vacuum 0.5.0 → 1.0.0

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: d688557c2a30832e793deb6f932f78e38f3fe2eb
4
- data.tar.gz: 762f70ee270015de03c5ba177724bcea03fcac9f
3
+ metadata.gz: f7024407a6c3d216a247ce435ef0ed65f56c1338
4
+ data.tar.gz: 86557dbfd10b6df9b0cec4a17fd12bd8f8cf5705
5
5
  SHA512:
6
- metadata.gz: 4f4d7fc84ef456bbdc31b6ce81169eb9799ce79c1112ec0a1e9e35cbf6a619dceadda25e4386458b0ecdddec8bd1179216d98dc6451a8de5a511c717bdbfc5ea
7
- data.tar.gz: c353c71626477896d12385b58c47049cdcdce226bd114c961904a3e3520fc2fcefac383527a3f5b9cc3b52ef5ff0f6abd26042a642c3ea629f688e849be9b0c0
6
+ metadata.gz: 492be10dda8e7ea60b2f39db7531c503add9b37ceff989a5a11b45dbc77dabf972520988b04c7e6322797dc0c750a723f991ffd9cbad9e327a04473eb9492da8
7
+ data.tar.gz: e04fe2ee991293dbaf942190f05f49fb3008f6613023e6ac701e15769765f86c7b21cdee449369c5294a32d32b2976f2f33763ff626d16eab57dfa8052edacea
data/README.md CHANGED
@@ -2,20 +2,23 @@
2
2
 
3
3
  [![Build Status][1]][2]
4
4
 
5
- Vacuum is a Ruby wrapper to the [Amazon Product Advertising API][4].
5
+ Vacuum is a light-weight Ruby wrapper to the
6
+ [Amazon Product Advertising API][4].
6
7
 
7
8
  ![vacuum][3]
8
9
 
9
10
  ## Usage
10
11
 
12
+ ### Setup
13
+
11
14
  Set up a request:
12
15
 
13
16
  ```ruby
14
17
  req = Vacuum.new
15
18
  ```
16
19
 
17
- The locale defaults to the US. If you wish to use another locale, instantiate
18
- with its ISO-3166 two-letter country code:
20
+ The locale defaults to the US. To use another locale, instantiate with its
21
+ two-letter country code:
19
22
 
20
23
  ```ruby
21
24
  req = Vacuum.new('GB')
@@ -31,7 +34,22 @@ req.configure(
31
34
  )
32
35
  ```
33
36
 
34
- Make a request:
37
+ Alternatively, set the key and secret as environment variables globally:
38
+
39
+ ```bash
40
+ export AWS_ACCESS_KEY_ID=key
41
+ export AWS_SECRET_ACCESS_KEY=secret
42
+ ```
43
+
44
+ You will still need to set a distinct associate tag for each locale:
45
+
46
+ ```ruby
47
+ req.associate_tag = 'tag'
48
+ ```
49
+
50
+ ### Request
51
+
52
+ Set up your parameters and make a request:
35
53
 
36
54
  ```ruby
37
55
  params = {
@@ -40,18 +58,29 @@ params = {
40
58
  }
41
59
  res = req.item_search(params)
42
60
  ```
61
+ The above executes an item search operation. The names of available methods
62
+ derive from the operations listed in the API docs and include
63
+ `browse_node_lookup`, `cart_add`, `cart_clear`, `cart_create`, `cart_get`,
64
+ `cart_modify`, `item_lookup`, `item_search`, and `similarity_lookup`.
65
+
66
+ Vacuum builds on [Excon][5]. See latter's API for ways to tweak your requests.
67
+
68
+ ### Response
43
69
 
44
- Parse the response into a Ruby hash:
70
+ The quick way to consume a response is to parse it into a Ruby hash:
45
71
 
46
72
  ```ruby
47
73
  res.to_h
48
74
  ```
49
75
 
50
- Allowed requests include `browse_node_lookup`, `cart_add`, `cart_clear`,
51
- `cart_create`, `cart_get`, `cart_modify`, `item_lookup`, `item_search`,
52
- `similarity_lookup`.
76
+ Vacuum uses [MultiXml][6], which will work with a number of popular XML
77
+ libraries.
53
78
 
54
- Vacuum is built with [excon][5] and [multi_xml][6].
79
+ You can also pass the response body into a custom parser:
80
+
81
+ ```ruby
82
+ MyParser.new(res.body)
83
+ ```
55
84
 
56
85
  [1]: https://secure.travis-ci.org/hakanensari/vacuum.png
57
86
  [2]: http://travis-ci.org/hakanensari/vacuum
@@ -46,9 +46,9 @@ module Vacuum
46
46
  # false)
47
47
  #
48
48
  # Raises a Bad Locale error if locale is not valid.
49
- def initialize(locale = nil, secure = false)
50
- host = HOSTS[locale || 'US'] or raise BadLocale
51
- self.aws_endpoint = "#{secure ? 'https' : 'http' }://#{host}/onca/xml"
49
+ def initialize(locale = 'US', secure = false)
50
+ host = HOSTS.fetch(locale) { raise BadLocale }
51
+ @aws_endpoint = "#{secure ? 'https' : 'http' }://#{host}/onca/xml"
52
52
  end
53
53
 
54
54
  # Configure the Amazon Product Advertising API request.
@@ -67,8 +67,9 @@ module Vacuum
67
67
 
68
68
  OPERATIONS.each do |operation|
69
69
  method_name = operation.gsub(/(.)([A-Z])/,'\1_\2').downcase
70
- define_method(method_name) do |params, excon_options = {}|
71
- Response.new(get(excon_options.merge(query: params.merge('Operation' => operation))))
70
+ define_method(method_name) do |params, opts = {}|
71
+ res = get(opts.merge(query: params.merge('Operation' => operation)))
72
+ Response.new(res)
72
73
  end
73
74
  end
74
75
 
@@ -78,8 +79,8 @@ module Vacuum
78
79
  #
79
80
  # Returns the built URL String.
80
81
  def url(params)
81
- options = { method: :get, query: params }
82
- [aws_endpoint, build_options(options).fetch(:query)].join('?')
82
+ opts = { method: :get, query: params }
83
+ [aws_endpoint, build_options(opts).fetch(:query)].join('?')
83
84
  end
84
85
  end
85
86
  end
@@ -1,3 +1,3 @@
1
1
  module Vacuum
2
- VERSION = '0.5.0'
2
+ VERSION = '1.0.0'
3
3
  end
data/test/test_vacuum.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  require 'minitest/autorun'
2
+ require 'minitest/pride'
2
3
  require_relative '../lib/vacuum'
3
4
 
4
5
  class TestVacuum < Minitest::Test
5
6
  include Vacuum
6
7
 
7
- def test_request_valid_locale
8
+ def test_requires_valid_locale
8
9
  assert_raises(Request::BadLocale) { Request.new('foo') }
9
10
  end
10
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vacuum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 1.0.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-11 00:00:00.000000000 Z
11
+ date: 2013-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jeff
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 0.7.0
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
- version: 0.7.0
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: multi_xml
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.5.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement