Class: FacebookGraphr::Session
- Inherits:
-
Object
- Object
- FacebookGraphr::Session
- Defined in:
- lib/facebook_graphr.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Class Method Summary collapse
Instance Method Summary collapse
- #api(path, params = {}, method = :get) ⇒ Object
-
#initialize(facebook_uid, access_token) ⇒ Session
constructor
A new instance of Session.
Constructor Details
#initialize(facebook_uid, access_token) ⇒ Session
Returns a new instance of Session.
37 38 39 40 41 42 43 |
# File 'lib/facebook_graphr.rb', line 37 def initialize(facebook_uid, access_token) self.user_id = facebook_uid self.access_token = access_token self.api_key = FacebookGraphr.config[:api_key] self.app_id = FacebookGraphr.config[:app_id] self.secret_key = FacebookGraphr.config[:secret_key] end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
26 27 28 |
# File 'lib/facebook_graphr.rb', line 26 def access_token @access_token end |
#api_key ⇒ Object
Returns the value of attribute api_key.
26 27 28 |
# File 'lib/facebook_graphr.rb', line 26 def api_key @api_key end |
#app_id ⇒ Object
Returns the value of attribute app_id.
26 27 28 |
# File 'lib/facebook_graphr.rb', line 26 def app_id @app_id end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
26 27 28 |
# File 'lib/facebook_graphr.rb', line 26 def secret_key @secret_key end |
#user_id ⇒ Object
Returns the value of attribute user_id.
26 27 28 |
# File 'lib/facebook_graphr.rb', line 26 def user_id @user_id end |
Class Method Details
.new_from_cookie(cookie) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/facebook_graphr.rb', line 28 def self.() ::Rails.logger.info(.inspect) = .split("&").inject({}) do |hash, pair| k, v = pair.split('=') hash.merge(k.to_sym => v) end self.new([:uid], [:access_token]) end |
Instance Method Details
#api(path, params = {}, method = :get) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/facebook_graphr.rb', line 45 def api(path, params = {}, method = :get) params = params.reverse_merge(:access_token => self.access_token) res = if method == :get param_string = params.map {|k, v| "#{k}=#{v}"}.join("&") HTTParty.get(URI.escape(BASE_URL + path + "?" + param_string)) else HTTParty.post(URI.escape(BASE_URL + path), ) end if res.code == 200 JSON.parse(res.body) end end |