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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f902912f543efa10b1c721d6fdd269434cdf4cc
4
- data.tar.gz: 7a28d74b215e5b3cd29d60d2b71e8ce24e075171
3
+ metadata.gz: 3f23a9a21b66bde11b05b063c7dc4a6912a07382
4
+ data.tar.gz: 9e223b19d1d422db163640bcf4ab6517d1b98a4b
5
5
  SHA512:
6
- metadata.gz: eadcbf854b6bf1234b211b51debd7067d4514fbb052d53d1c06696f6fe41b782de973e188559152b54a2cd93c30cc674c833d7102fdc9e7ace604cf8e4cada8d
7
- data.tar.gz: 2de9412108eec58f8924821842d9911064905da0ec7550f321c9109ed7fb1d8e7f87abc95163b9c56a80570f93e8d61b8e2fd2c26f00bc2cdedcc56c54011b55
6
+ metadata.gz: 9df1544a33d6f403083778f753f9d4f8804a9506925b5bd7c1e7116c968fa7eb960b5e2c9690ca79bd644ef0a4e47ded41fdef255008a7d7b28fe88002fc5050
7
+ data.tar.gz: c3874e6436e91063abb4d90ba6648994f035a21914d005b77786efdc2ff9182b9611f2603d83b9a4c94a22ec162f9ee9961af30470543d03917ddcd319317423
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
+ /.ruby-version
3
4
  /Gemfile.lock
4
5
  /_yardoc/
5
6
  /coverage/
@@ -0,0 +1 @@
1
+ compat.version=2.0
@@ -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
- before_install: gem install bundler -v 1.13.6
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
@@ -4,5 +4,5 @@ group :development do
4
4
  gem 'webmock'
5
5
  end
6
6
 
7
- # Specify your gem's dependencies in adash.gemspec
7
+ # Specify your gem's dependencies in amazon-drs.gemspec
8
8
  gemspec
@@ -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 = "https://github.com/aycabta/amazon-drs"
15
- spec.license = "MIT"
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 = "exe"
18
+ spec.bindir = 'exe'
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.13"
23
- spec.add_development_dependency "rake", "~> 12.0"
24
- spec.add_development_dependency "test-unit"
25
- spec.add_development_dependency "webmock"
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
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "adash"
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 "pry"
10
+ # require 'pry'
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -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.header)
10
+ parse_header(response)
11
11
  parse_body(response.body)
12
12
  end
13
13
 
14
- def parse_header(headers)
15
- headers.each do |key, value|
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
@@ -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 ||= "AdashRubyGem/#{AmazonDrs::VERSION}/#{RUBY_DESCRIPTION}"
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
- if resp.code == '400' && resp.json['message'] == 'Invalid token' && @refresh_token
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
- response = http.request(request)
242
- response.json = JSON.parse(response.body)
243
- response
238
+ http.request(request)
244
239
  end
245
240
  private :request
246
241
  end
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module AmazonDrs
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
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.3
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 00:00:00.000000000 Z
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: '1.13'
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: '1.13'
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: '12.0'
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: '12.0'
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.6.8
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