vacuum 0.3.1 → 0.4.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d07486645b8ea810b09ea915c530618f63044dd6
4
+ data.tar.gz: 8e09b77ac5525b6f4ded9af4eaa1162d7b6e3ad3
5
+ SHA512:
6
+ metadata.gz: 3c0961d922ddb4999cdbd597c24174b44b3619f9ed82cacf6cba40fe928c5c202c694404b9f43b2ca754d2b70b86e777d5058371ed8ca9ca3c8fecec77f0fb51
7
+ data.tar.gz: 913688bc90be1251d194b303d3737cbf30400392b9f65dc00f102dca5ddd52c6b8e128740f1cf54e90bdd975f3b2ef551c8906abc81b9b5061660e8f25548bb6
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2012 Hakan Ensari
3
+ Copyright (c) 2013 Hakan Ensari
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -8,21 +8,63 @@ Vacuum is a Ruby wrapper to the [Amazon Product Advertising API][4].
8
8
 
9
9
  ## Usage
10
10
 
11
+ Set up a request:
12
+
11
13
  ```ruby
12
14
  req = Vacuum.new
15
+ .configure(
16
+ aws_access_key_id: 'foo',
17
+ aws_secret_access_key: 'secret',
18
+ associate_tag: 'biz-val'
19
+ )
20
+ ```
21
+
22
+ The locale defaults to the US. If you wish to use another locale, specify its
23
+ ISO-3166 two-letter code when instantiating the request:
13
24
 
14
- req.configure key: 'foo',
15
- secret: 'secret',
16
- tag: 'biz-val'
25
+ ```ruby
26
+ Vacuum.new('GB')
27
+ ```
17
28
 
29
+ Make a request:
30
+
31
+ ```ruby
18
32
  params = { 'Operation' => 'ItemSearch',
19
33
  'SearchIndex' => 'Books',
20
34
  'Keywords' => 'Architecture' }
21
35
 
22
- req.get query: params # XPath is your friend.
36
+ res = req.get(query: params)
37
+ ```
38
+
39
+ Once you have a response, parse it with your favourite XML parser and parsing
40
+ method.
41
+
42
+ If you don't mind the performance hit, here is a simplistic solution based on
43
+ [`MultiXml`][5]:
44
+
45
+ ```ruby
46
+ require 'forwardable'
47
+ require 'multi_xml'
48
+
49
+ class Response
50
+ extend Forwardable
51
+
52
+ def_delegators :code, :body, :@response
53
+
54
+ def initialize(response)
55
+ @response = response
56
+ end
57
+
58
+ def to_h
59
+ MultiXml.parse(body)
60
+ end
61
+ end
62
+
63
+ Response.new(res).to_h
23
64
  ```
24
65
 
25
66
  [1]: https://secure.travis-ci.org/hakanensari/vacuum.png
26
67
  [2]: http://travis-ci.org/hakanensari/vacuum
27
68
  [3]: http://f.cl.ly/items/2k2X0e2u0G3k1c260D2u/vacuum.png
28
69
  [4]: https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html
70
+ [5]: https://github.com/sferik/multi_xml
@@ -6,7 +6,6 @@ module Vacuum
6
6
  include Jeff
7
7
 
8
8
  BadLocale = Class.new(ArgumentError)
9
- MissingTag = Class.new(ArgumentError)
10
9
 
11
10
  # A list of Amazon Product Advertising API hosts.
12
11
  HOSTS = {
@@ -17,11 +16,11 @@ module Vacuum
17
16
  'FR' => 'ecs.amazonaws.fr',
18
17
  'IT' => 'webservices.amazon.it',
19
18
  'JP' => 'ecs.amazonaws.jp',
20
- 'UK' => 'ecs.amazonaws.co.uk',
19
+ 'GB' => 'ecs.amazonaws.co.uk',
21
20
  'US' => 'ecs.amazonaws.com'
22
21
  }.freeze
23
22
 
24
- params 'AssociateTag' => -> { tag },
23
+ params 'AssociateTag' => -> { associate_tag },
25
24
  'Service' => 'AWSECommerceService',
26
25
  'Version' => '2011-08-01'
27
26
 
@@ -31,6 +30,11 @@ module Vacuum
31
30
  #
32
31
  # Raises a Bad Locale error if locale is not valid.
33
32
  def initialize(locale = nil)
33
+ if locale == 'UK'
34
+ warn '[DEPRECATION] Use GB instead of UK'
35
+ locale = 'GB'
36
+ end
37
+
34
38
  host = HOSTS[locale || 'US'] or raise BadLocale
35
39
  self.endpoint = "http://#{host}/onca/xml"
36
40
  end
@@ -38,24 +42,22 @@ module Vacuum
38
42
  # Configure the Amazon Product Advertising API request.
39
43
  #
40
44
  # credentials - The Hash credentials of the API endpoint.
41
- # :key - The String Amazon Web Services (AWS) key.
42
- # :secret - The String AWS secret.
43
- # :tag - The String Associate Tag.
45
+ # :aws_access_key_id - The String Amazon Web Services
46
+ # (AWS) key.
47
+ # :aws_secret_access_key - The String AWS secret.
48
+ # :associate_tag - The String Associate Tag.
44
49
  #
45
- # Returns nothing.
50
+ # Returns self.
46
51
  def configure(credentials)
47
52
  credentials.each { |key, val| self.send("#{key}=", val) }
53
+ self
48
54
  end
49
55
 
50
- # Get the String Associate Tag.
51
- #
52
- # Raises a Missing Tag error if Associate Tag is missing.
53
- def tag
54
- @tag or raise MissingTag
55
- end
56
-
57
- # Sets the String Associate Tag.
58
- attr_writer :tag
56
+ # Get/Sets the String Associate Tag.
57
+ attr_accessor :associate_tag
58
+ # Keep around old attribute for a while for backward compatibility.
59
+ alias :tag :associate_tag
60
+ alias :tag= :associate_tag=
59
61
 
60
62
  # Build a URL.
61
63
  #
@@ -64,8 +66,8 @@ module Vacuum
64
66
  # Returns the built URL String.
65
67
  def url(params)
66
68
  opts = {
67
- :method => :get,
68
- :query => params
69
+ method: :get,
70
+ query: params
69
71
  }
70
72
 
71
73
  [endpoint, build_options(opts).fetch(:query)].join('?')
@@ -1,3 +1,3 @@
1
1
  module Vacuum
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,48 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vacuum
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.3.1
4
+ version: 0.4.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Hakan Ensari
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-25 00:00:00.000000000 Z
11
+ date: 2013-09-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- version_requirements: !ruby/object:Gem::Requirement
14
+ name: jeff
15
+ requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.0
20
- none: false
21
- name: jeff
19
+ version: 0.7.0
22
20
  type: :runtime
23
21
  prerelease: false
24
- requirement: !ruby/object:Gem::Requirement
22
+ version_requirements: !ruby/object:Gem::Requirement
25
23
  requirements:
26
24
  - - ~>
27
25
  - !ruby/object:Gem::Version
28
- version: 0.6.0
29
- none: false
26
+ version: 0.7.0
30
27
  - !ruby/object:Gem::Dependency
31
- version_requirements: !ruby/object:Gem::Requirement
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
32
30
  requirements:
33
- - - ! '>='
31
+ - - '>='
34
32
  - !ruby/object:Gem::Version
35
33
  version: '0'
36
- none: false
37
- name: rake
38
34
  type: :development
39
35
  prerelease: false
40
- requirement: !ruby/object:Gem::Requirement
36
+ version_requirements: !ruby/object:Gem::Requirement
41
37
  requirements:
42
- - - ! '>='
38
+ - - '>='
43
39
  - !ruby/object:Gem::Version
44
40
  version: '0'
45
- none: false
46
41
  description: A wrapper to the Amazon Product Advertising API
47
42
  email:
48
43
  - hakan.ensari@papercavalier.com
@@ -56,27 +51,27 @@ files:
56
51
  - LICENSE
57
52
  - README.md
58
53
  homepage: https://github.com/hakanensari/vacuum
59
- licenses: []
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
60
57
  post_install_message:
61
58
  rdoc_options: []
62
59
  require_paths:
63
60
  - lib
64
61
  required_ruby_version: !ruby/object:Gem::Requirement
65
62
  requirements:
66
- - - ! '>='
63
+ - - '>='
67
64
  - !ruby/object:Gem::Version
68
65
  version: '1.9'
69
- none: false
70
66
  required_rubygems_version: !ruby/object:Gem::Requirement
71
67
  requirements:
72
- - - ! '>='
68
+ - - '>='
73
69
  - !ruby/object:Gem::Version
74
70
  version: '0'
75
- none: false
76
71
  requirements: []
77
72
  rubyforge_project:
78
- rubygems_version: 1.8.23
73
+ rubygems_version: 2.0.3
79
74
  signing_key:
80
- specification_version: 3
75
+ specification_version: 4
81
76
  summary: Amazon Product Advertising in Ruby
82
77
  test_files: []