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
-
#api_get(uri) ⇒ Object
Set these up to be pluggable/overridable (e.g. so you can override them in app engine).
- #api_post(uri, options) ⇒ 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.
40 41 42 43 44 45 46 |
# File 'lib/facebook_graphr.rb', line 40 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.
27 28 29 |
# File 'lib/facebook_graphr.rb', line 27 def access_token @access_token end |
#api_key ⇒ Object
Returns the value of attribute api_key.
27 28 29 |
# File 'lib/facebook_graphr.rb', line 27 def api_key @api_key end |
#app_id ⇒ Object
Returns the value of attribute app_id.
27 28 29 |
# File 'lib/facebook_graphr.rb', line 27 def app_id @app_id end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
27 28 29 |
# File 'lib/facebook_graphr.rb', line 27 def secret_key @secret_key end |
#user_id ⇒ Object
Returns the value of attribute user_id.
27 28 29 |
# File 'lib/facebook_graphr.rb', line 27 def user_id @user_id end |
Class Method Details
.new_from_cookie(cookie) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/facebook_graphr.rb', line 29 def self.() ::Rails.logger.info(.inspect) # Sometimes cookie comes in with extra quotes in front and back = .chomp('"').reverse.chomp('"').reverse = .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
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/facebook_graphr.rb', line 48 def api(path, params = {}, method = :get) params = params.reverse_merge(:access_token => self.access_token) code, body = if method == :get param_string = params.map {|k, v| "#{k}=#{v}"}.join("&") api_get(URI.escape(BASE_URL + path + "?" + param_string)) else api_post(URI.escape(BASE_URL + path), ) end if code == 200 JSON.parse(body) end end |
#api_get(uri) ⇒ Object
Set these up to be pluggable/overridable (e.g. so you can override them in app engine)
62 63 64 65 |
# File 'lib/facebook_graphr.rb', line 62 def api_get(uri) res = HTTParty.get(uri) [res.code, res.body] end |
#api_post(uri, options) ⇒ Object
67 68 69 70 |
# File 'lib/facebook_graphr.rb', line 67 def api_post(uri, ) res = HTTParty.post(uri, ) [res.code, res.body] end |