Class: Challah::Facebook::Interfaces::FbGraph

Inherits:
Base
  • Object
show all
Defined in:
lib/challah/facebook/interfaces/fb_graph.rb

Instance Attribute Summary

Attributes inherited from Base

#app_id, #app_secret, #permissions

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Challah::Facebook::Interfaces::Base

Class Method Details

.get_access_token_for_oauth_code(code, callback_uri) ⇒ Object



9
10
11
12
13
# File 'lib/challah/facebook/interfaces/fb_graph.rb', line 9

def self.get_access_token_for_oauth_code(code, callback_uri)
  client = new(Facebook.options).auth(callback_uri).client
  client.authorization_code = code
  client.access_token!(:client_auth_body).to_s
end

.get_authorization_url(callback_uri, permissions = nil) ⇒ Object



53
54
55
56
57
# File 'lib/challah/facebook/interfaces/fb_graph.rb', line 53

def self.get_authorization_url(callback_uri, permissions = nil)
  scope = Facebook.permissions if permissions.nil?
  client = new(Facebook.options).auth(callback_uri).client
  client.authorization_uri(scope: scope)
end

.get_extended_token(access_token) ⇒ Object



15
16
17
18
19
# File 'lib/challah/facebook/interfaces/fb_graph.rb', line 15

def self.get_extended_token(access_token)
  fb_auth = new(Facebook.options).auth
  fb_auth.exchange_token!(access_token)
  fb_auth.access_token.to_s
end

.get_facebook_uid_from_access_token(access_token) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/challah/facebook/interfaces/fb_graph.rb', line 21

def self.get_facebook_uid_from_access_token(access_token)
  fb_user = get_user_object_from_access_token(access_token)

  if fb_user
    return fb_user.identifier.to_s
  end

  nil
rescue
  nil
end

.get_user_info_from_access_token(access_token) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/challah/facebook/interfaces/fb_graph.rb', line 33

def self.(access_token)
  result = {}

  fb_user = get_user_object_from_access_token(access_token)

  Facebook.user_fields.each do |field|
    if fb_user.respond_to?(field)
      result[field] = fb_user.send(field)
    else
      result[field] = nil
    end
  end

  result
end

.get_user_object_from_access_token(access_token) ⇒ Object



49
50
51
# File 'lib/challah/facebook/interfaces/fb_graph.rb', line 49

def self.get_user_object_from_access_token(access_token)
  ::FbGraph::User.me(access_token).fetch
end

.modeObject



5
6
7
# File 'lib/challah/facebook/interfaces/fb_graph.rb', line 5

def self.mode
  "fb_graph"
end

Instance Method Details

#auth(callback_uri = nil) ⇒ Object



59
60
61
# File 'lib/challah/facebook/interfaces/fb_graph.rb', line 59

def auth(callback_uri = nil)
  ::FbGraph::Auth.new(app_id, app_secret, redirect_uri: callback_uri)
end