Class: Jet::Client
- Inherits:
-
Object
- Object
- Jet::Client
- Defined in:
- lib/jet/client.rb
Defined Under Namespace
Constant Summary collapse
- API_URL =
'https://merchant-api.jet.com/api'
Instance Method Summary collapse
-
#initialize(config = {}) ⇒ Client
constructor
A new instance of Client.
- #orders ⇒ Object
- #returns ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 |
# File 'lib/jet/client.rb', line 7 def initialize(config = {}) @api_user = config[:api_user] @secret = config[:secret] @merchant_id = config[:merchant_id] end |
Instance Method Details
#token ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jet/client.rb', line 13 def token if not (@id_token and @token_type and @expires_on > Time.now) body = { user: @api_user, pass: @secret } response = RestClient.post("#{API_URL}/token", body.to_json) parsed_response = JSON.parse(response.body) @id_token = parsed_response['id_token'] @token_type = parsed_response['token_type'] @expires_on = Time.parse(parsed_response['expires_on']) end { Authorization: "#{@token_type} #{@id_token}" } end |