class Mogli::User

Constants

ALL_EXTENDED_PERMISSIONS

the entire list of extended permissions the user is able to grant the application. the list should be kept in sync with developers.facebook.com/docs/authentication/permissions

Attributes

extended_permissions[R]

Public Class Methods

recognize?(hash) click to toggle source
# File lib/mogli/user.rb, line 10
def self.recognize?(hash)
  !hash.has_key?("category")
end

Public Instance Methods

has_permission?(permission) click to toggle source

check if the facebook user has a specific permission. the permission arg is a symbol matching the facebook extended permission names exactly: developers.facebook.com/docs/authentication/permissions

# File lib/mogli/user.rb, line 99
def has_permission?(permission)
  if !ALL_EXTENDED_PERMISSIONS.include? permission
    raise UnrecognizedExtendedPermissionException,
          "The requested permission is not recognized as a facebook extended permission: '#{permission}'"
  end

  if !defined?(@extended_permissions)
    fetch_permissions
  end

  extended_permissions[permission]
end
revoke_permission() click to toggle source

revoke all permissions for this user

# File lib/mogli/user.rb, line 113
def revoke_permission
  client.delete("#{id}/permissions")
end

Private Instance Methods

fetch_permissions() click to toggle source

queries all extended permissions for this user for the current application caches a hash of permission names => boolean indicating if the user has granted the specified permission to this app

# File lib/mogli/user.rb, line 122
def fetch_permissions
  fql = "SELECT #{ALL_EXTENDED_PERMISSIONS.map(&:to_s).join(',')} " +
        "FROM permissions " +
        "WHERE uid = #{self.id}"
  @extended_permissions = {}
  perms_query_result = client.fql_query(fql).first
  ALL_EXTENDED_PERMISSIONS.each do |perm|
    @extended_permissions[perm] = (perms_query_result[perm.to_s] == 1)
  end
end