Sha256: 5782e4c61bf7757ed05c65a3185ec24d2a3bd17b4473d105adfb258949530ac2

Contents?: true

Size: 725 Bytes

Versions: 19

Compression:

Stored size: 725 Bytes

Contents

module DHLEcommerceAPI
  class Authentication < ActiveResource::Base
    # self.prefix set in configuration.rb 
    def self.get_token
      token = DHLEcommerceAPI.cache.read("DHLEcommerceAPI::AuthenticationToken")
      if token.present?
        return token
      else
        path = "/rest/v1/OAuth/AccessToken?clientId=#{DHLEcommerceAPI.config.client_id}&password=#{DHLEcommerceAPI.config.password}&returnFormat=json"
        response = connection.get(path)
        response_body = JSON.parse(response.body)["accessTokenResponse"]
        DHLEcommerceAPI.cache.write("DHLEcommerceAPI::AuthenticationToken", response_body["token"], {expires_in: 12.hours})
        return response_body["token"]
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
dhl_ecommerce_api-0.1.19 lib/dhl_ecommerce_api/resources/authentication.rb
dhl_ecommerce_api-0.1.18 lib/dhl_ecommerce_api/resources/authentication.rb
dhl_ecommerce_api-0.1.17 lib/dhl_ecommerce_api/resources/authentication.rb
dhl_ecommerce_api-0.1.16 lib/dhl_ecommerce_api/resources/authentication.rb
dhl_ecommerce_api-0.1.15 lib/dhl_ecommerce_api/resources/authentication.rb
dhl_ecommerce_api-0.1.14 lib/dhl_ecommerce_api/resources/authentication.rb
dhl_ecommerce_api-0.1.13 lib/dhl_ecommerce_api/resources/authentication.rb
dhl_ecommerce_api-0.1.12 lib/dhl_ecommerce_api/resources/authentication.rb
dhl_ecommerce_api-0.1.11 lib/dhl_ecommerce_api/resources/authentication.rb
dhl_ecommerce_api-0.1.9 lib/dhl_ecommerce_api/resources/authentication.rb
dhl_ecommerce_api-0.1.8 lib/dhl_ecommerce_api/resources/authentication.rb
dhl_ecommerce_api-0.1.7 lib/dhl_ecommerce_api/resources/authentication.rb
dhl_ecommerce_api-0.1.6 lib/dhl_ecommerce_api/resources/authentication.rb
dhl_ecommerce_api-0.1.5 lib/dhl_ecommerce_api/resources/authentication.rb
dhl_ecommerce_api-0.1.4 lib/dhl_ecommerce_api/resources/authentication.rb
dhl_ecommerce_api-0.1.3 lib/dhl_ecommerce_api/resources/authentication.rb
dhl_ecommerce_api-0.1.2 lib/dhl_ecommerce_api/resources/authentication.rb
dhl_ecommerce_api-0.1.1 lib/dhl_ecommerce_api/resources/authentication.rb
dhl_ecommerce_api-0.1.0 lib/dhl_ecommerce_api/resources/authentication.rb