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.



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

def initialize(access_token)
  @access_token = access_token
end

Instance Attribute Details

#access_tokenObject

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



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

def access_token
  @access_token
end

Instance Method Details

#get_request(options = {}) ⇒ Object

Provides call of get_request_url



47
48
49
# File 'lib/fobos/graph_api/users.rb', line 47

def get_request(options = {})
  self.class.get(get_request_url(options))
end

#get_request_url(options = {}) ⇒ Object

Generate link for 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_url(fields: ‘id’) will return “graph.facebook.com/v2.1/me?fields=id&access_token=some_token



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

def get_request_url(options = {})
  options.add_access_token_to_options(@access_token)
  options_part = Options.map_options_to_params(options)

  GRAPH_URI.to_s + '/v2.1' '/me?' + options_part
end

#post_request(options = {}) ⇒ Object

Provides call of post_request_url



52
53
54
55
56
# File 'lib/fobos/graph_api/users.rb', line 52

def post_request(options = {})
  encoded_url = URI.encode(post_request_url(options))

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

#post_request_url(options = {}) ⇒ Object

Generate link for 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 return “graph.facebook.com/v2.1/me/feed?message=This is test message&access_token=some_token”



37
38
39
40
41
42
# File 'lib/fobos/graph_api/users.rb', line 37

def post_request_url(options = {})
  options.add_access_token_to_options(@access_token)
  options_part = Options.map_options_to_params(options)

  query = GRAPH_URI.to_s + '/v2.1' '/me/feed?' + options_part
end