vacuum 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7024407a6c3d216a247ce435ef0ed65f56c1338
4
- data.tar.gz: 86557dbfd10b6df9b0cec4a17fd12bd8f8cf5705
3
+ metadata.gz: c4c2d00043baa236106ea42ca2e2938ba88b40ba
4
+ data.tar.gz: 8e30624c24d2631a4a3bc9dfee01bbe2fcb8b5ea
5
5
  SHA512:
6
- metadata.gz: 492be10dda8e7ea60b2f39db7531c503add9b37ceff989a5a11b45dbc77dabf972520988b04c7e6322797dc0c750a723f991ffd9cbad9e327a04473eb9492da8
7
- data.tar.gz: e04fe2ee991293dbaf942190f05f49fb3008f6613023e6ac701e15769765f86c7b21cdee449369c5294a32d32b2976f2f33763ff626d16eab57dfa8052edacea
6
+ metadata.gz: a6ea78733efb0ab6a5f32c3356d78a9954f16944148de341addf25e05c1fd50fa850a6343b44de75a867d0e0de085654db26af9b82c1807981d77185e0d33538
7
+ data.tar.gz: 4842c0dbde4ccdab7864441ef770c18655536d089bb7ff48f3b1e9ab7cb5fc0dba6ddb8ed3628cd19b218386fc804db7b9b969432067c0dae89629f46d8c30e8
data/README.md CHANGED
@@ -2,8 +2,7 @@
2
2
 
3
3
  [![Build Status][1]][2]
4
4
 
5
- Vacuum is a light-weight Ruby wrapper to the
6
- [Amazon Product Advertising API][4].
5
+ Vacuum is a fast, light-weight Ruby wrapper to the [Amazon Product Advertising API][4].
7
6
 
8
7
  ![vacuum][3]
9
8
 
@@ -36,7 +35,7 @@ req.configure(
36
35
 
37
36
  Alternatively, set the key and secret as environment variables globally:
38
37
 
39
- ```bash
38
+ ```sh
40
39
  export AWS_ACCESS_KEY_ID=key
41
40
  export AWS_SECRET_ACCESS_KEY=secret
42
41
  ```
@@ -56,27 +55,33 @@ params = {
56
55
  'SearchIndex' => 'Books',
57
56
  'Keywords' => 'Architecture'
58
57
  }
59
- res = req.item_search(params)
58
+ res = req.item_search(query: params)
60
59
  ```
61
60
  The above executes an item search operation. The names of available methods
62
61
  derive from the operations listed in the API docs and include
63
62
  `browse_node_lookup`, `cart_add`, `cart_clear`, `cart_create`, `cart_get`,
64
63
  `cart_modify`, `item_lookup`, `item_search`, and `similarity_lookup`.
65
64
 
66
- Vacuum builds on [Excon][5]. See latter's API for ways to tweak your requests.
65
+ Vacuum uses [Excon][5] as HTTP client. Check the Excon API for ways to tweak
66
+ your request:
67
+
68
+ ```ruby
69
+ res = req.item_search(query: params, persistent: true)
70
+ ```
67
71
 
68
72
  ### Response
69
73
 
70
- The quick way to consume a response is to parse it into a Ruby hash:
74
+ The quickest way to consume a response is to parse it into a Ruby hash:
71
75
 
72
76
  ```ruby
73
77
  res.to_h
74
78
  ```
75
79
 
76
80
  Vacuum uses [MultiXml][6], which will work with a number of popular XML
77
- libraries.
81
+ libraries. If working in MRI, you may want to use [Ox][7].
78
82
 
79
- You can also pass the response body into a custom parser:
83
+ You can also pass the response body into your own parser for some custom XML
84
+ heavy-lifting:
80
85
 
81
86
  ```ruby
82
87
  MyParser.new(res.body)
@@ -88,3 +93,4 @@ MyParser.new(res.body)
88
93
  [4]: https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html
89
94
  [5]: https://github.com/geemus/excon
90
95
  [6]: https://github.com/sferik/multi_xml
96
+ [7]: https://github.com/ohler55/ox
@@ -9,15 +9,16 @@ module Vacuum
9
9
  BadLocale = Class.new(ArgumentError)
10
10
 
11
11
  HOSTS = {
12
+ 'BR' => 'webservices.amazon.com.br',
12
13
  'CA' => 'webservices.amazon.ca',
13
14
  'CN' => 'webservices.amazon.cn',
14
15
  'DE' => 'webservices.amazon.de',
15
16
  'ES' => 'webservices.amazon.es',
16
17
  'FR' => 'webservices.amazon.fr',
18
+ 'GB' => 'webservices.amazon.co.uk',
17
19
  'IN' => 'webservices.amazon.in',
18
20
  'IT' => 'webservices.amazon.it',
19
21
  'JP' => 'webservices.amazon.co.jp',
20
- 'GB' => 'webservices.amazon.co.uk',
21
22
  'US' => 'webservices.amazon.com'
22
23
  }.freeze
23
24
 
@@ -65,22 +66,39 @@ module Vacuum
65
66
  self
66
67
  end
67
68
 
69
+ # Execute an API operation. See `OPERATIONS` constant for available
70
+ # operation names.
71
+ #
72
+ # params - The Hash request parameters.
73
+ # opts - Options passed to Excon (default: {}).
74
+ #
75
+ # Alternatively, pass Excon options as first argument and include request
76
+ # parameters as query key.
77
+ #
78
+ # Examples
79
+ #
80
+ # req.item_search(
81
+ # 'SearchIndex' => 'All',
82
+ # 'Keywords' => 'Architecture'
83
+ # )
84
+ #
85
+ # req.item_search(
86
+ # query: {
87
+ # 'SearchIndex' => 'All',
88
+ # 'Keywords' => 'Architecture'
89
+ # },
90
+ # persistent: true
91
+ # )
92
+ #
93
+ # Returns a Vacuum Response.
68
94
  OPERATIONS.each do |operation|
69
95
  method_name = operation.gsub(/(.)([A-Z])/,'\1_\2').downcase
70
96
  define_method(method_name) do |params, opts = {}|
71
- res = get(opts.merge(query: params.merge('Operation' => operation)))
72
- Response.new(res)
73
- end
74
- end
97
+ params.has_key?(:query) ? opts = params : opts.update(query: params)
98
+ opts[:query].update('Operation' => operation)
75
99
 
76
- # Build a URL.
77
- #
78
- # params - A Hash of Amazon Product Advertising request parameters.
79
- #
80
- # Returns the built URL String.
81
- def url(params)
82
- opts = { method: :get, query: params }
83
- [aws_endpoint, build_options(opts).fetch(:query)].join('?')
100
+ Response.new(get(opts))
101
+ end
84
102
  end
85
103
  end
86
104
  end
@@ -1,3 +1,3 @@
1
1
  module Vacuum
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -5,26 +5,34 @@ require_relative '../lib/vacuum'
5
5
  class TestVacuum < Minitest::Test
6
6
  include Vacuum
7
7
 
8
+ def setup
9
+ @req = Request.new
10
+ end
11
+
12
+ def teardown
13
+ Excon.stubs.clear
14
+ end
15
+
8
16
  def test_requires_valid_locale
9
17
  assert_raises(Request::BadLocale) { Request.new('foo') }
10
18
  end
11
19
 
12
20
  def test_defaults_to_us_endpoint
13
- assert_equal 'http://webservices.amazon.com/onca/xml', Request.new.aws_endpoint
21
+ assert_equal 'http://webservices.amazon.com/onca/xml', @req.aws_endpoint
14
22
  end
15
23
 
16
- def test_returns_url
17
- req = Request.new
18
- req.configure(aws_access_key_id: 'key', aws_secret_access_key: 'secret', associate_tag: 'tag')
19
- assert_match(/webservices.amazon.com.*Foo=Bar/, req.url('Foo' => 'Bar'))
24
+ def test_fetches_parsable_response
25
+ Excon.stub({}, { body: '<foo>bar</foo>' })
26
+ @req.configure(aws_access_key_id: 'key', aws_secret_access_key: 'secret', associate_tag: 'tag')
27
+ res = @req.item_lookup({}, mock: true)
28
+ refute_empty res.to_h
20
29
  end
21
30
 
22
- def test_fetches_parsable_response
31
+ def test_alternative_query_syntax
23
32
  Excon.stub({}, { body: '<foo>bar</foo>' })
24
33
  req = Request.new
25
34
  req.configure(aws_access_key_id: 'key', aws_secret_access_key: 'secret', associate_tag: 'tag')
26
- res = req.item_lookup({}, mock: true)
35
+ res = req.item_lookup(query: {}, mock: true)
27
36
  refute_empty res.to_h
28
- Excon.stubs.clear
29
37
  end
30
38
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vacuum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hakan Ensari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-25 00:00:00.000000000 Z
11
+ date: 2014-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jeff
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: multi_xml
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.5.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.5.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '5.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: A wrapper to the Amazon Product Advertising API
@@ -73,12 +73,12 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - LICENSE
77
+ - README.md
78
+ - lib/vacuum.rb
76
79
  - lib/vacuum/request.rb
77
80
  - lib/vacuum/response.rb
78
81
  - lib/vacuum/version.rb
79
- - lib/vacuum.rb
80
- - LICENSE
81
- - README.md
82
82
  - test/test_vacuum.rb
83
83
  homepage: https://github.com/hakanensari/vacuum
84
84
  licenses:
@@ -90,17 +90,17 @@ require_paths:
90
90
  - lib
91
91
  required_ruby_version: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - '>='
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: '1.9'
96
96
  required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  requirements:
98
- - - '>='
98
+ - - ">="
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 2.0.3
103
+ rubygems_version: 2.2.2
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: Amazon Product Advertising in Ruby