Class: Fobos::GraphAPI::Users

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/fobos/graph_api/users.rb

Constant Summary collapse

FB_URI =

Store Facebook default URL

'https://www.facebook.com'
GRAPH_URI =

Store Facebook Graph API URL

'https://graph.facebook.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ Users

Need access token for making calls.



18
19
20
# File 'lib/fobos/graph_api/users.rb', line 18

def initialize(access_token)
  @access_token = access_token
end

Instance Attribute Details

#access_tokenObject

You can get access token with Fobos::GraphAPI::Oauth.



10
11
12
# File 'lib/fobos/graph_api/users.rb', line 10

def access_token
  @access_token
end

Instance Method Details

#get_request(options = {}) ⇒ Object

Provides getting user’s data with options. Options must be a hash. You can provide value as String or Array.

E.g. Fobos::GraphAPI::Users.new(access_token).get_request(fields: ‘id,first_name,last_name’) will return ID, FIRST NAME and LAST NAME of user.



26
27
28
29
30
31
32
33
# File 'lib/fobos/graph_api/users.rb', line 26

def get_request(options = {})
  options_part = ''
  options_part = options.map {|k,v| "#{k}=#{v.kind_of?(Array) ? v.join(',') : v}" }.join('&') unless options.empty?

  query = GRAPH_URI.to_s + '/v2.1' '/me?' + options_part + "&access_token=#{@access_token}"

  self.class.get(query)
end

#post_request(options = {}) ⇒ Object

Provides sending post request (publishing) for user. Options must be a hash. You can provide value as String or Array.

E.g. Fobos::GraphAPI::Users.new(access_token).post_request(message: ‘This is test message’) will post “This is test message” to user’s feed.



39
40
41
42
43
44
45
46
47
48
# File 'lib/fobos/graph_api/users.rb', line 39

def post_request(options = {})
  options_part = ''
  options_part = options.map {|k,v| "#{k}=#{v.kind_of?(Array) ? v.join(',') : v}" }.join('&') unless options.empty?

  query = GRAPH_URI.to_s + '/v2.1' '/me/feed?' + options_part + "&access_token=#{@access_token}"

  encoded_url = URI.encode(query)

  self.class.post(URI.parse(encoded_url))
end