class DhlEcommerce::Client

Public Class Methods

new(client_id: '', password: '', production_env: false) click to toggle source
# File lib/dhl_ecommerce.rb, line 14
def initialize(client_id: '', password: '', production_env: false)
  self.class.base_uri (production_env ? PRODUCTION_BASE_URL : SANDBOX_BASE_URL)
  @client_id = client_id
  @password = password
  authenticate!
  self.class.default_options.merge!(headers: { 'content-type': 'application/json' })
end

Private Instance Methods

authenticate!() click to toggle source
# File lib/dhl_ecommerce.rb, line 24
def authenticate!
  resp = HTTParty.get("#{self.class.base_uri}/rest/v1/OAuth/AccessToken", query: { clientId: @client_id, password: @password })
  @access_token = resp.dig('accessTokenResponse', 'token')
end