Class: DHLEcommerceAPI::Authentication
- Inherits:
-
ActiveResource::Base
- Object
- ActiveResource::Base
- DHLEcommerceAPI::Authentication
- Defined in:
- lib/dhl_ecommerce_api/resources/authentication.rb
Class Method Summary collapse
-
.get_token ⇒ Object
self.prefix set in configuration.rb.
Class Method Details
.get_token ⇒ Object
self.prefix set in configuration.rb
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/dhl_ecommerce_api/resources/authentication.rb', line 4 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 |