Class: WeShipClient::TokenClient

Inherits:
Client
  • Object
show all
Defined in:
lib/we_ship_client/token_client.rb

Constant Summary

Constants inherited from Client

Client::DEFAULT_TIMEOUT

Instance Attribute Summary

Attributes inherited from Client

#http_client, #logger

Instance Method Summary collapse

Methods inherited from Client

#base_url, #initialize

Constructor Details

This class inherits a constructor from WeShipClient::Client

Instance Method Details

#generate_access_tokenString

Returns The access token.

Returns:

  • (String)

    The access token

Raises:



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/we_ship_client/token_client.rb', line 11

def generate_access_token
  response = http_client.post(
    "#{base_url}/token",
    data: {
      username: ENV['WE_SHIP_USERNAME'],
      password: ENV['WE_SHIP_PASSWORD']
    }
  )

  raise_token_generation_exception(response) unless response.status == 200

  JSON.parse(response.body)['access_token']
end