Class: Trustpilot::Auth::Authenticator
- Inherits:
-
Object
- Object
- Trustpilot::Auth::Authenticator
- Defined in:
- lib/trustpilot/auth/authenticator.rb
Instance Method Summary collapse
-
#auth_header ⇒ Object
Returns the value of the authentication header to use when requesting an access token.
-
#initialize ⇒ Authenticator
constructor
A new instance of Authenticator.
-
#request_token ⇒ Object
Gets a new access token from the API.
Constructor Details
#initialize ⇒ Authenticator
Returns a new instance of Authenticator.
8 9 10 11 12 |
# File 'lib/trustpilot/auth/authenticator.rb', line 8 def initialize return if Trustpilot.api_email && Trustpilot.api_password raise Trustpilot::Error, 'Trustpilot.api_email / Trustpilot.api_password are not set.' end |
Instance Method Details
#auth_header ⇒ Object
Returns the value of the authentication header to use when requesting an access token
35 36 37 38 39 40 41 |
# File 'lib/trustpilot/auth/authenticator.rb', line 35 def auth_header unless Trustpilot.api_key && Trustpilot.api_secret raise Trustpilot::Error, 'Trustpilot.api_key / Trustpilot.api_secret are not set.' end "Basic #{ Base64.strict_encode64( "#{ Trustpilot.api_key }:#{ Trustpilot.api_secret }" ) }" end |
#request_token ⇒ Object
Gets a new access token from the API
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/trustpilot/auth/authenticator.rb', line 15 def request_token request = Request.new( 'oauth/oauth-business-users-for-applications/accesstoken', headers: { 'Authorization' => auth_header, 'Content-Type' => 'application/x-www-form-urlencoded' }, params: { grant_type: 'password', username: Trustpilot.api_email, password: Trustpilot.api_password }, verb: 'post' ) Api.request request end |