Class: Fobos::GraphAPI::Users
- Inherits:
-
Object
- Object
- Fobos::GraphAPI::Users
- 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
-
#access_token ⇒ Object
You can get access token with Fobos::GraphAPI::Oauth.
Instance Method Summary collapse
-
#get_request(options = {}) ⇒ Object
Provides getting user’s data with options.
-
#initialize(access_token) ⇒ Users
constructor
Need access token for making calls.
-
#post_request(options = {}) ⇒ Object
Provides sending post request (publishing) for user.
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_token ⇒ Object
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( = {}) = '' = .map {|k,v| "#{k}=#{v.kind_of?(Array) ? v.join(',') : v}" }.join('&') unless .empty? query = GRAPH_URI.to_s + '/v2.1' '/me?' + + "&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( = {}) = '' = .map {|k,v| "#{k}=#{v.kind_of?(Array) ? v.join(',') : v}" }.join('&') unless .empty? query = GRAPH_URI.to_s + '/v2.1' '/me/feed?' + + "&access_token=#{@access_token}" encoded_url = URI.encode(query) self.class.post(URI.parse(encoded_url)) end |