amazon-drs 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.jrubyrc +1 -0
- data/.travis.yml +10 -1
- data/Gemfile +1 -1
- data/amazon-drs.gemspec +8 -8
- data/bin/console +4 -4
- data/lib/amazon-drs/base.rb +14 -3
- data/lib/amazon-drs/client.rb +5 -10
- data/lib/amazon-drs/error.rb +13 -0
- data/lib/amazon-drs/version.rb +1 -1
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f23a9a21b66bde11b05b063c7dc4a6912a07382
|
4
|
+
data.tar.gz: 9e223b19d1d422db163640bcf4ab6517d1b98a4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9df1544a33d6f403083778f753f9d4f8804a9506925b5bd7c1e7116c968fa7eb960b5e2c9690ca79bd644ef0a4e47ded41fdef255008a7d7b28fe88002fc5050
|
7
|
+
data.tar.gz: c3874e6436e91063abb4d90ba6648994f035a21914d005b77786efdc2ff9182b9611f2603d83b9a4c94a22ec162f9ee9961af30470543d03917ddcd319317423
|
data/.gitignore
CHANGED
data/.jrubyrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
compat.version=2.0
|
data/.travis.yml
CHANGED
@@ -1,5 +1,14 @@
|
|
1
|
+
---
|
1
2
|
sudo: false
|
2
3
|
language: ruby
|
3
4
|
rvm:
|
5
|
+
- 2.2.6
|
4
6
|
- 2.3.3
|
5
|
-
|
7
|
+
- 2.4.0
|
8
|
+
- jruby-1.7.26
|
9
|
+
- jruby-9.1.7.0
|
10
|
+
script: bundle exec rake
|
11
|
+
matrix:
|
12
|
+
allow_failures:
|
13
|
+
- rvm: jruby-1.7.26
|
14
|
+
- rvm: jruby-9.1.7.0
|
data/Gemfile
CHANGED
data/amazon-drs.gemspec
CHANGED
@@ -11,16 +11,16 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = %q{amazon-drs is for Amazon Dash Replenishment Service}
|
13
13
|
spec.description = %Q{amazon-drs is for Amazon Dash Replenishment Service.\nYou can use this after authorized by Login with Amazon.}
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
14
|
+
spec.homepage = 'https://github.com/aycabta/amazon-drs'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f| f.match(%r{^(test|spec|features)/}) end
|
18
|
-
spec.bindir =
|
18
|
+
spec.bindir = 'exe'
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
22
|
+
spec.add_development_dependency 'bundler'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'test-unit'
|
25
|
+
spec.add_development_dependency 'webmock'
|
26
26
|
end
|
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'amazon-drs'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require
|
10
|
+
# require 'pry'
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
data/lib/amazon-drs/base.rb
CHANGED
@@ -7,12 +7,12 @@ module AmazonDrs
|
|
7
7
|
def initialize(response)
|
8
8
|
@response = response
|
9
9
|
@status_code = response.code.to_i
|
10
|
-
parse_header(response
|
10
|
+
parse_header(response)
|
11
11
|
parse_body(response.body)
|
12
12
|
end
|
13
13
|
|
14
|
-
def parse_header(
|
15
|
-
|
14
|
+
def parse_header(response)
|
15
|
+
response.each do |key, value|
|
16
16
|
case key.downcase
|
17
17
|
when 'x-amzn-errortype'
|
18
18
|
# Value examples:
|
@@ -36,5 +36,16 @@ module AmazonDrs
|
|
36
36
|
# abstract
|
37
37
|
end
|
38
38
|
private :parse_body
|
39
|
+
|
40
|
+
def inspect
|
41
|
+
if @status_code == 200
|
42
|
+
self.class.name
|
43
|
+
else
|
44
|
+
resp = "ERROR #{@status_code} : "
|
45
|
+
resp += @message if instance_variable_defined?(:@message) && @message
|
46
|
+
resp += @error_description if instance_variable_defined?(:@error_description) && @error_description
|
47
|
+
resp
|
48
|
+
end
|
49
|
+
end
|
39
50
|
end
|
40
51
|
end
|
data/lib/amazon-drs/client.rb
CHANGED
@@ -11,10 +11,6 @@ require 'amazon-drs/error'
|
|
11
11
|
require 'amazon-drs/slot_status'
|
12
12
|
require 'amazon-drs/access_token'
|
13
13
|
|
14
|
-
class Net::HTTPResponse
|
15
|
-
attr_accessor :json
|
16
|
-
end
|
17
|
-
|
18
14
|
module AmazonDrs
|
19
15
|
class Client
|
20
16
|
attr_accessor :device_model, :serial, :authorization_code, :redirect_uri, :access_token, :refresh_token, :client_id, :client_secret
|
@@ -37,7 +33,7 @@ module AmazonDrs
|
|
37
33
|
end
|
38
34
|
|
39
35
|
def user_agent
|
40
|
-
@user_agent ||= "
|
36
|
+
@user_agent ||= "AmazonDrsRubyGem/#{AmazonDrs::VERSION}/#{RUBY_DESCRIPTION}"
|
41
37
|
end
|
42
38
|
|
43
39
|
def deregistrate_device
|
@@ -163,7 +159,8 @@ module AmazonDrs
|
|
163
159
|
end
|
164
160
|
end
|
165
161
|
resp = request(method, url, headers: headers, params: params)
|
166
|
-
|
162
|
+
json = JSON.parse(resp.body)
|
163
|
+
if resp.code == '400' && json['message'] == 'Invalid token' && @refresh_token
|
167
164
|
resp = refresh_access_token
|
168
165
|
process_token_response(resp)
|
169
166
|
request(method, url, headers: headers, params: params)
|
@@ -231,16 +228,14 @@ module AmazonDrs
|
|
231
228
|
request['Content-Type'] = 'application/x-www-form-urlencoded'
|
232
229
|
request['User-Agent'] = user_agent
|
233
230
|
headers.each do |key, value|
|
234
|
-
request[key] = value
|
231
|
+
request[key.to_s] = value
|
235
232
|
end
|
236
233
|
if not @access_token.nil?
|
237
234
|
request["Authorization"] = "Bearer #{@access_token}"
|
238
235
|
end
|
239
236
|
http = Net::HTTP.new(uri.host, uri.port)
|
240
237
|
http.use_ssl = true
|
241
|
-
|
242
|
-
response.json = JSON.parse(response.body)
|
243
|
-
response
|
238
|
+
http.request(request)
|
244
239
|
end
|
245
240
|
private :request
|
246
241
|
end
|
data/lib/amazon-drs/error.rb
CHANGED
@@ -10,6 +10,19 @@ module AmazonDrs
|
|
10
10
|
@error = json['error'] if json['error']
|
11
11
|
@error_description = json['error_description'] if json['error_description']
|
12
12
|
end
|
13
|
+
|
14
|
+
def inspect
|
15
|
+
resp = 'ERROR'
|
16
|
+
resp += " #{@error}" if instance_variable_defined?(:@error) && @error
|
17
|
+
resp += ': '
|
18
|
+
resp += @message if instance_variable_defined?(:@message) && @message
|
19
|
+
resp += @error_description if instance_variable_defined?(:@error_description) && @error_description
|
20
|
+
resp
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
inspect
|
25
|
+
end
|
13
26
|
end
|
14
27
|
end
|
15
28
|
|
data/lib/amazon-drs/version.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amazon-drs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code Ass
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: test-unit
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -76,6 +76,7 @@ extensions: []
|
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
78
|
- ".gitignore"
|
79
|
+
- ".jrubyrc"
|
79
80
|
- ".travis.yml"
|
80
81
|
- Gemfile
|
81
82
|
- LICENSE.txt
|
@@ -116,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
117
|
version: '0'
|
117
118
|
requirements: []
|
118
119
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.
|
120
|
+
rubygems_version: 2.4.5.2
|
120
121
|
signing_key:
|
121
122
|
specification_version: 4
|
122
123
|
summary: amazon-drs is for Amazon Dash Replenishment Service
|