Class: FacebookGraphr::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/facebook_graphr.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_tokenObject

Returns the value of attribute access_token.



26
27
28
# File 'lib/facebook_graphr.rb', line 26

def access_token
  @access_token
end

#api_keyObject

Returns the value of attribute api_key.



26
27
28
# File 'lib/facebook_graphr.rb', line 26

def api_key
  @api_key
end

#app_idObject

Returns the value of attribute app_id.



26
27
28
# File 'lib/facebook_graphr.rb', line 26

def app_id
  @app_id
end

#secret_keyObject

Returns the value of attribute secret_key.



26
27
28
# File 'lib/facebook_graphr.rb', line 26

def secret_key
  @secret_key
end

#user_idObject

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



28
29
30
31
32
33
34
35
# File 'lib/facebook_graphr.rb', line 28

def self.new_from_cookie(cookie)
  ::Rails.logger.info(cookie.inspect)
  cookie_hash = cookie.split("&").inject({}) do |hash, pair|
    k, v = pair.split('=')
    hash.merge(k.to_sym => v)
  end
  self.new(cookie_hash[:uid], cookie_hash[: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), options)
  end
  if res.code == 200
    JSON.parse(res.body)
  end
end