Class: Lyft::Client::Api::Oauth

Inherits:
Base
  • Object
show all
Defined in:
lib/lyft/client/api/oauth.rb

Overview

Client for making authentication related requests to the lyft api

Constant Summary collapse

ENDPOINTS =

Authentication Endpoints

{
  access_token: '/oauth/token'
}

Constants inherited from Base

Base::API_VERSION, Base::DEFAULT_VALIDATES

Instance Method Summary collapse

Methods inherited from Base

path_for, #path_for, #set_debug_output

Constructor Details

#initialize(config) ⇒ Oauth

Returns a new instance of Oauth.



19
20
21
22
# File 'lib/lyft/client/api/oauth.rb', line 19

def initialize(config)
  super
  set_default_headers
end

Instance Method Details

#retrieve_access_token(authorization_code: nil) ⇒ HTTParty::Response

Retrieves access token from the server.

Examples:

Get public access token.

resp = client.authentication.retrieve_access_token
resp.success?

Get access token from authorization_code.

resp = client.authentication.retrieve_access_token authorization_code: 'auth_code'
resp.success?

Parameters:

  • authorization_code (String) (defaults to: nil)

Returns:

  • (HTTParty::Response)


38
39
40
41
42
43
44
45
46
47
48
# File 'lib/lyft/client/api/oauth.rb', line 38

def retrieve_access_token(authorization_code: nil)
  path = path_for(:access_token)

  grant_type = get_grant_type(authorization_code.present?)
  body = request_body(
    grant_type: grant_type,
    authorization_code: authorization_code
  )

  self.class.post(path, body: body.to_json)
end