Sha256: 017c499b871e77ab24187d8fb032bab18be998d6eb845f1f3079effa59a374c2

Contents?: true

Size: 1.65 KB

Versions: 76

Compression:

Stored size: 1.65 KB

Contents

module FbGraph
  class AdUser < User
    attr_accessor :role, :permissions

    def initialize(identifier, attributes = {})
      super(identifier, attributes)

      %w(role permissions).each do |field|
        self.send("#{field}=", attributes[field.to_sym])
      end
    end

    # Level 1001, administrator access
    # Level 1002, general-user (ad manager) access
    # Level 1003, reports-only access
    ROLES = {
      :admin        => 1001,
      :general      => 1002,
      :reports_only => 1003
    }
    ROLES.each do |key, value|
      define_method "#{key}_access?" do
        self.role == value
      end
    end

    # 1: ACCOUNT_ADMIN: modify the set of users associated with the given account.
    # 2: ADMANAGER_READ: view campaigns and ads
    # 3: ADMANAGER_WRITE: manage campaigns and ads
    # 4: BILLING_READ: view account billing information
    # 5: BILLING_WRITE: modify the account billing information
    # 7: REPORTS: run reports
    PERMISSIONS = {
      :account_admin => 1,
      :ad_manager_read => 2,
      :ad_manager_write => 3,
      :billing_read => 4,
      :billing_write => 5,
      # what's "6"??
      :reports => 7
    }
    PERMISSIONS.each do |key, value|
      define_method "#{key}_access?" do
        self.permissions.include? value
      end
    end

    # FbGraph::User#fetch does not retrieve the permissions and roles since they are outside the normal
    # attributes for an FbGraph::User, so we just copy them over from this object before returning
    # the fetched one.
    def fetch(options = {})
      super(options).tap do |fetched|
        fetched.role = role
        fetched.permissions = permissions
      end
    end
  end
end

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
fb_graph-2.7.17 lib/fb_graph/ad_user.rb
fb_graph-2.7.16 lib/fb_graph/ad_user.rb
fb_graph-2.7.15 lib/fb_graph/ad_user.rb
fb_graph-2.7.14 lib/fb_graph/ad_user.rb
fb_graph-2.7.13 lib/fb_graph/ad_user.rb
fb_graph-2.7.12 lib/fb_graph/ad_user.rb
fb_graph-2.7.11 lib/fb_graph/ad_user.rb
fb_graph-2.7.10 lib/fb_graph/ad_user.rb
fb_graph-2.7.9 lib/fb_graph/ad_user.rb
fb_graph-2.7.8 lib/fb_graph/ad_user.rb
fb_graph-2.7.7 lib/fb_graph/ad_user.rb
fb_graph-2.7.6 lib/fb_graph/ad_user.rb
fb_graph-2.7.5 lib/fb_graph/ad_user.rb
fb_graph-2.7.4 lib/fb_graph/ad_user.rb
fb_graph-2.7.3 lib/fb_graph/ad_user.rb
fb_graph-2.7.2 lib/fb_graph/ad_user.rb
fb_graph-2.7.1 lib/fb_graph/ad_user.rb
fb_graph-2.7.0 lib/fb_graph/ad_user.rb
fb_graph-2.6.7 lib/fb_graph/ad_user.rb
fb_graph-2.6.6 lib/fb_graph/ad_user.rb