Class: Adash::Client
- Inherits:
-
Object
- Object
- Adash::Client
- Defined in:
- lib/adash/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#authorization_code ⇒ Object
Returns the value of attribute authorization_code.
-
#device_model ⇒ Object
Returns the value of attribute device_model.
-
#on_new_token ⇒ Object
Returns the value of attribute on_new_token.
-
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
-
#serial ⇒ Object
Returns the value of attribute serial.
- #user_agent ⇒ Object
Instance Method Summary collapse
- #deregistrate_device ⇒ Object
- #device_status(most_recently_active_date) ⇒ Object
- #get_token ⇒ Object
-
#initialize(device_model) {|_self| ... } ⇒ Client
constructor
A new instance of Client.
- #replenish(slot_id) ⇒ Object
- #slot_status(slot_id, expected_replenishment_date, remaining_quantity_in_unit, original_quantity_in_unit, total_quantity_on_hand, last_use_date) ⇒ Object
- #subscription_info ⇒ Object
Constructor Details
#initialize(device_model) {|_self| ... } ⇒ Client
Returns a new instance of Client.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/adash/client.rb', line 19 def initialize(device_model) @drs_host = 'dash-replenishment-service-na.amazon.com' @amazon_host = 'api.amazon.com' @device_model = device_model @serial = nil = nil @redirect_uri = nil @access_token = nil @refresh_token = nil @on_new_token = nil yield(self) if block_given? end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
15 16 17 |
# File 'lib/adash/client.rb', line 15 def access_token @access_token end |
#authorization_code ⇒ Object
Returns the value of attribute authorization_code.
15 16 17 |
# File 'lib/adash/client.rb', line 15 def end |
#device_model ⇒ Object
Returns the value of attribute device_model.
15 16 17 |
# File 'lib/adash/client.rb', line 15 def device_model @device_model end |
#on_new_token ⇒ Object
Returns the value of attribute on_new_token.
16 17 18 |
# File 'lib/adash/client.rb', line 16 def on_new_token @on_new_token end |
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
15 16 17 |
# File 'lib/adash/client.rb', line 15 def redirect_uri @redirect_uri end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
15 16 17 |
# File 'lib/adash/client.rb', line 15 def refresh_token @refresh_token end |
#serial ⇒ Object
Returns the value of attribute serial.
15 16 17 |
# File 'lib/adash/client.rb', line 15 def serial @serial end |
#user_agent ⇒ Object
32 33 34 |
# File 'lib/adash/client.rb', line 32 def user_agent @user_agent ||= "AdashRubyGem/#{Adash::VERSION}/#{RUBY_DESCRIPTION}" end |
Instance Method Details
#deregistrate_device ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/adash/client.rb', line 36 def deregistrate_device headers = { 'x-amzn-accept-type': '[email protected]', 'x-amzn-type-version': '[email protected]' } path = "/deviceModels/#{@device_model}/devices/#{@serial}/registration" request_drs(:delete, path, headers: headers) end |
#device_status(most_recently_active_date) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/adash/client.rb', line 45 def device_status(most_recently_active_date) headers = { 'x-amzn-accept-type': '[email protected]', 'x-amzn-type-version': '[email protected]' } path = '/deviceStatus' request_drs(:post, path, headers: headers, params: { 'mostRecentlyActiveDate' => convert_to_iso8601(most_recently_active_date) }) end |
#get_token ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/adash/client.rb', line 94 def get_token if @access_token @access_token else resp = request_token process_token_response(resp) end end |
#replenish(slot_id) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/adash/client.rb', line 79 def replenish(slot_id) headers = { 'x-amzn-accept-type': '[email protected]', 'x-amzn-type-version': '[email protected]' } path = "/replenish/#{slot_id}" response = request_drs(:post, path, headers: headers) # TODO: imprement response processing # https://developer.amazon.com/public/solutions/devices/dash-replenishment-service/docs/dash-replenish-endpoint # response examples: # {"message":"Unable to place order - slot : <01234567-89ab-cdef-0123-456789abcdef> is unsubscribed."} # {"detailCode":"STANDARD_ORDER_PLACED","eventInstanceId":"amzn1.dash.v2.o.xxxxxx......"} # {"detailCode":"ORDER_INPROGRESS","eventInstanceId":"amzn1.dash.v2.o.xxxxxx......"} end |
#slot_status(slot_id, expected_replenishment_date, remaining_quantity_in_unit, original_quantity_in_unit, total_quantity_on_hand, last_use_date) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/adash/client.rb', line 63 def slot_status(slot_id, expected_replenishment_date, remaining_quantity_in_unit, original_quantity_in_unit, total_quantity_on_hand, last_use_date) headers = { 'x-amzn-accept-type': '[email protected]', 'x-amzn-type-version': '[email protected]' } path = "/slotStatus/#{slot_id}" params = { 'expectedReplenishmentDate' => convert_to_iso8601(expected_replenishment_date), 'remainingQuantityInUnit' => remaining_quantity_in_unit, 'originalQuantityInUnit' => original_quantity_in_unit, 'totalQuantityOnHand' => total_quantity_on_hand, 'lastUseDate' => convert_to_iso8601(last_use_date) } request_drs(:post, path, headers: headers, params: params) end |
#subscription_info ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/adash/client.rb', line 54 def subscription_info headers = { 'x-amzn-accept-type': '[email protected]', 'x-amzn-type-version': '[email protected]' } path = '/subscriptionInfo' request_drs(:get, path, headers: headers) end |