Class: AmazonDrs::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/amazon-drs/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(device_model) {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/amazon-drs/client.rb', line 21

def initialize(device_model)
  @drs_host = 'dash-replenishment-service-na.amazon.com'
  @amazon_host = 'api.amazon.com'
  @device_model = device_model
  @serial = nil
  @authorization_code = nil
  @redirect_uri = nil
  @access_token = nil
  @refresh_token = nil
  @on_new_token = nil
  @client_id = nil
  @client_secret = nil
  yield(self) if block_given?
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



17
18
19
# File 'lib/amazon-drs/client.rb', line 17

def access_token
  @access_token
end

#authorization_codeObject

Returns the value of attribute authorization_code.



17
18
19
# File 'lib/amazon-drs/client.rb', line 17

def authorization_code
  @authorization_code
end

#client_idObject

Returns the value of attribute client_id.



17
18
19
# File 'lib/amazon-drs/client.rb', line 17

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



17
18
19
# File 'lib/amazon-drs/client.rb', line 17

def client_secret
  @client_secret
end

#device_modelObject

Returns the value of attribute device_model.



17
18
19
# File 'lib/amazon-drs/client.rb', line 17

def device_model
  @device_model
end

#on_new_tokenObject

Returns the value of attribute on_new_token.



18
19
20
# File 'lib/amazon-drs/client.rb', line 18

def on_new_token
  @on_new_token
end

#redirect_uriObject

Returns the value of attribute redirect_uri.



17
18
19
# File 'lib/amazon-drs/client.rb', line 17

def redirect_uri
  @redirect_uri
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



17
18
19
# File 'lib/amazon-drs/client.rb', line 17

def refresh_token
  @refresh_token
end

#serialObject

Returns the value of attribute serial.



17
18
19
# File 'lib/amazon-drs/client.rb', line 17

def serial
  @serial
end

#user_agentObject



36
37
38
# File 'lib/amazon-drs/client.rb', line 36

def user_agent
  @user_agent ||= "AmazonDrsRubyGem/#{AmazonDrs::VERSION}/#{RUBY_DESCRIPTION}"
end

Instance Method Details

#deregistrate_deviceObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/amazon-drs/client.rb', line 40

def deregistrate_device
  headers = {
    'x-amzn-accept-type': '[email protected]',
    'x-amzn-type-version': '[email protected]'
  }
  path = "/deviceModels/#{@device_model}/devices/#{@serial}/registration"
  response = request_drs(:delete, path, headers: headers)
  if response.code == '200'
    ::AmazonDrs::DeregistrateDevice.new(response)
  else
    ::AmazonDrs::Error.new(response)
  end
end

#device_status(most_recently_active_date) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/amazon-drs/client.rb', line 54

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) })
  if response.code == '200'
    ::AmazonDrs::DeviceStatus.new(response)
  else
    ::AmazonDrs::Error.new(response)
  end
end

#get_tokenObject



132
133
134
135
136
137
138
139
140
# File 'lib/amazon-drs/client.rb', line 132

def get_token
  if @access_token
    @access_token
  else
    resp = request_token
    process_token_response(resp)
    resp
  end
end

#replenish(slot_id) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/amazon-drs/client.rb', line 103

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)
  if response.code == '200'
    ::AmazonDrs::Replenish.new(response)
  else
    ::AmazonDrs::Error.new(response)
  end
end

#slot_status(slot_id, expected_replenishment_date, remaining_quantity_in_unit, original_quantity_in_unit, total_quantity_on_hand, last_use_date) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/amazon-drs/client.rb', line 82

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)
  }
  response = request_drs(:post, path, headers: headers, params: params)
  if response.code == '200'
    ::AmazonDrs::SlotStatus.new(response)
  else
    ::AmazonDrs::Error.new(response)
  end
end

#subscription_infoObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/amazon-drs/client.rb', line 68

def subscription_info
  headers = {
    'x-amzn-accept-type': '[email protected]',
    'x-amzn-type-version': '[email protected]'
  }
  path = '/subscriptionInfo'
  response = request_drs(:get, path, headers: headers)
  if response.code == '200'
    ::AmazonDrs::SubscriptionInfo.new(response)
  else
    ::AmazonDrs::Error.new(response)
  end
end

#test_orders(slot_id) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/amazon-drs/client.rb', line 118

def test_orders(slot_id)
  headers = {
    'x-amzn-accept-type': '[email protected]',
    'x-amzn-type-version': '[email protected]'
  }
  path = "/testOrders/#{slot_id}"
  response = request_drs(:delete, path, headers: headers)
  if response.code == '200'
    ::AmazonDrs::TestOrders.new(response)
  else
    ::AmazonDrs::Error.new(response)
  end
end