Class: FacebookClient::Auth
- Inherits:
-
Object
- Object
- FacebookClient::Auth
- Defined in:
- lib/auth.rb
Instance Method Summary collapse
- #access_token_url(params = {}) ⇒ Object
- #connection ⇒ Object
-
#initialize(fb) ⇒ Auth
constructor
A new instance of Auth.
- #request_access(params = {}) ⇒ Object
- #url(params = {}) ⇒ Object
- #validate_access_token_response(data) ⇒ Object
Constructor Details
#initialize(fb) ⇒ Auth
Returns a new instance of Auth.
10 11 12 |
# File 'lib/auth.rb', line 10 def initialize(fb) @fb=fb end |
Instance Method Details
#access_token_url(params = {}) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/auth.rb', line 45 def access_token_url(params={}) params = params.stringify_keys params['client_id'] = @fb.app_id params['client_secret'] = @fb.secret params.require_keys('redirect_uri', 'client_id', 'client_secret', 'code') params.assert_valid_keys('redirect_uri', 'client_id', 'client_secret', 'code') connection.build_url('/oauth/access_token', params).to_s end |
#connection ⇒ Object
54 55 56 57 58 |
# File 'lib/auth.rb', line 54 def connection @connection ||= Faraday::Connection.new(:url => Base::GRAPH_URL) do |builder| builder.adapter :net_http end end |
#request_access(params = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/auth.rb', line 24 def request_access(params={}) # required params # - code # - redirect_uri response = connection.get(access_token_url(params)) data = Rack::Utils.parse_query(response.body) validate_access_token_response(data) @fb.graph(data['access_token'], data['expires']) end |
#url(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/auth.rb', line 14 def url(params={}) # params # - scope # - redirect_uri params = params.stringify_keys params['client_id'] = @fb.app_id params.require_keys('redirect_uri', 'client_id') connection.build_url('/oauth/authorize', params).to_s end |
#validate_access_token_response(data) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/auth.rb', line 34 def validate_access_token_response(data) if !data.is_a?(Hash) raise ResponseError, "response must be a hash" end data = data.stringify_keys missing_keys = ['access_token']-data.keys if missing_keys.size>0 raise ResponseError, "response missing key(s) #{missing_keys.join(', ')}" end end |