Class: SBF::Client::Facebook::UserEndpoint

Inherits:
UserEndpoint show all
Defined in:
lib/stbaldricks/endpoints/facebook/user.rb

Instance Attribute Summary

Attributes inherited from EntityEndpoint

#orig_target_class

Instance Method Summary collapse

Methods inherited from UserEndpoint

#change_password, #disconnect_facebook, #list_entities_user_has_permission

Methods inherited from EntityEndpoint

#aggregate, #create, #delete, #find, #find_first, #get, #initialize, #save, #update

Constructor Details

This class inherits a constructor from SBF::Client::EntityEndpoint

Instance Method Details

#login!(authorization_code, redirect_uri) ⇒ string

Logs in a user, using a Facebook Oauth authorization code & redirect uri. Configures the client library to use user credentials for subsequent requests. Returns the SBF access token for the user that should be held onto to configure the client library in future requests that are outside of this scope.

Parameters:

  • authorization_code (string)
  • redirect_uri (string)

Returns:

  • (string)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/stbaldricks/endpoints/facebook/user.rb', line 15

def login!(authorization_code, redirect_uri)
  response = SBF::Client::Api::Request.post_request(
    "/#{SBF::Client::Api::VERSION}/security/facebook/login",
    authorization_code: authorization_code,
    redirect_uri: redirect_uri
  )
  parsed_response = JSON.parse(response.body).symbolize!

  if ok?(response)
    SBF::Client::Configuration.user_token = parsed_response[:token]
    data = parsed_response.merge(user: target_class.new(parsed_response[:user]))
    SBF::Client::LOG.info { "SBF::Client - Facebook User Login with Identifier: #{parsed_response[:user][:identifier]}" }
  else
    SBF::Client::Configuration.user_token = nil
    error = SBF::Client::ErrorEntity.new(parsed_response)
  end

  SBF::Client::Api::Response.new(http_code: response.code, data: data, error: error)
end