completelynovel-amazon-product-advertising-api 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,10 @@
1
+ Basic usage
2
+ ###########
3
+
1
4
  require 'rubygems'
2
5
  require 'amazon_product_advertising_api'
3
6
  # Setup your API key - in an initializer or something like that
4
- AmazonProductAdvertisingApi::Base.api_key = "<insert api key here>"
7
+ AmazonProductAdvertisingApi::Base.access_key_id = "<insert api key here>"
5
8
 
6
9
  # Setup Associates IDs for whichever regions you're selling to
7
10
  AmazonProductAdvertisingApi::Base.associate_ids.uk = "<insert UK Associate ID here>"
@@ -50,6 +53,10 @@ lookup.run
50
53
  # </Items>
51
54
  # </ItemLookupResponse>
52
55
 
56
+ # is_valid is part of the api and says whether the request was valid
57
+ lookup.is_valid
58
+ => true
59
+
53
60
  lookup.response.items.size
54
61
  => 1
55
62
 
@@ -77,5 +84,43 @@ lookup.hpricot_data
77
84
  => <the xml data, having been fed into Hpricot>
78
85
 
79
86
  # And also the request uri
80
- irb(main):022:0> lookup.request_uri
87
+ lookup.request_uri
81
88
  => #<URI::HTTP:0x1c7021c URL:http://ecs.amazonaws.co.uk/onca/xml?Service=AWSECommerceService&Operation=ItemLookup&ItemId=0201485419&AWSAccessKeyId=%3Cinsert%20api%20key%20here%3E>
89
+
90
+
91
+ Error handling - invalid request credentials, url form, etc
92
+ ###########################################################
93
+ AmazonProductAdvertisingApi::Base.access_key_id = "<an invalid id>"
94
+ lookup = AmazonProductAdvertisingApi::Operations::Item::ItemLookup.new("0201485419")
95
+ lookup.run
96
+ => false
97
+
98
+ lookup.is_valid
99
+ => false
100
+
101
+ lookup.errors
102
+ => <an array of error objects>
103
+
104
+ lookup.errors.first.code
105
+ => AWS.InvalidParameterValue
106
+
107
+ lookup.errors.first.message
108
+ => <an invalid id> is not a valid value for AWSAccessKeyId. Please change this value and retry your request.
109
+
110
+
111
+ Error handling - invalid request credentials, url form, etc
112
+ ###########################################################
113
+ AmazonProductAdvertisingApi::Base.access_key_id = "<valid api key>"
114
+ lookup = AmazonProductAdvertisingApi::Operations::Item::ItemLookup.new("<invalid asin>")
115
+ lookup.run
116
+ => false
117
+
118
+ # is_valid returns true as the request was well formed, it just doesn't have any valid data to return
119
+ lookup.is_valid
120
+ => true
121
+
122
+ lookup.errors.first.code
123
+ => AWS.InvalidParameterValue
124
+
125
+ lookup.errors.first.message
126
+ => <an invalid asin> is not a valid value for ItemId. Please change this value and retry your request.
data/README.rdoc CHANGED
@@ -77,7 +77,6 @@ intended rules.
77
77
  = TODO
78
78
  - Implement the rest of the Operations (Cart*, Customer*, Help, List*, Seller*,
79
79
  Tag*, Transaction* and Vehicle*).
80
- - Clean handling of routine errors such as rate limiting, etc.
81
80
  - Implement HMAC before the authentication requirement kicks in in August 2009.
82
81
  - Implement batch and multiple operation requests, abstracted away from the
83
82
  user within the dsl.
@@ -2,14 +2,14 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{amazon-product-advertising-api}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jon Gilbraith"]
9
9
  s.date = %q{2009-06-11}
10
10
  s.description = %q{A nice rubyish interface to the Amazon Product Advertising API, formerly known as the Associates Web Service and before that the Amazon E-Commerce Service.}
11
11
  s.email = %q{jon@completelynovel.com}
12
- s.files = ["EXAMPLE.rdoc", "MIT-LICENSE", "README.rdoc", "amazon-product-advertising-api.gemspec", "lib/amazon_product_advertising_api", "lib/amazon_product_advertising_api/base.rb", "lib/amazon_product_advertising_api/operations", "lib/amazon_product_advertising_api/operations/base.rb", "lib/amazon_product_advertising_api/operations/browse_node.rb", "lib/amazon_product_advertising_api/operations/item.rb", "lib/amazon_product_advertising_api/support.rb", "lib/amazon_product_advertising_api.rb"]
12
+ s.files = ["EXAMPLE.txt", "MIT-LICENSE", "README.rdoc", "amazon-product-advertising-api.gemspec", "lib/amazon_product_advertising_api", "lib/amazon_product_advertising_api/base.rb", "lib/amazon_product_advertising_api/operations", "lib/amazon_product_advertising_api/operations/base.rb", "lib/amazon_product_advertising_api/operations/browse_node.rb", "lib/amazon_product_advertising_api/operations/item.rb", "lib/amazon_product_advertising_api/support.rb", "lib/amazon_product_advertising_api.rb"]
13
13
  s.has_rdoc = false
14
14
  s.homepage = %q{http://github.com/completelynovel/amazon-product-advertising-api}
15
15
  s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
@@ -18,19 +18,4 @@ Gem::Specification.new do |s|
18
18
  s.rubygems_version = %q{1.3.0}
19
19
  s.summary = %q{A nice rubyish interface to the Amazon Product Advertising API.}
20
20
 
21
- if s.respond_to? :specification_version then
22
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
- s.specification_version = 2
24
-
25
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
- s.add_runtime_dependency(%q<mime-types>, [">= 1.15"])
27
- s.add_runtime_dependency(%q<diff-lcs>, [">= 1.1.2"])
28
- else
29
- s.add_dependency(%q<mime-types>, [">= 1.15"])
30
- s.add_dependency(%q<diff-lcs>, [">= 1.1.2"])
31
- end
32
- else
33
- s.add_dependency(%q<mime-types>, [">= 1.15"])
34
- s.add_dependency(%q<diff-lcs>, [">= 1.1.2"])
35
- end
36
21
  end
@@ -2,7 +2,7 @@ module AmazonProductAdvertisingApi
2
2
 
3
3
  class Base
4
4
 
5
- cattr_accessor :api_key
5
+ cattr_accessor :access_key_id
6
6
 
7
7
  cattr_accessor :associate_ids
8
8
  @@associate_ids = Struct.new(:ca, :de, :fr, :jp, :uk, :us).new
@@ -4,8 +4,6 @@ module AmazonProductAdvertisingApi
4
4
 
5
5
  class Request
6
6
 
7
- attr_accessor :aws_access_key_id
8
-
9
7
  attr_accessor :region
10
8
 
11
9
  attr_accessor :operation
@@ -17,6 +15,10 @@ module AmazonProductAdvertisingApi
17
15
  attr_accessor :hpricot_data
18
16
 
19
17
  attr_accessor :response
18
+
19
+ attr_accessor :is_valid
20
+
21
+ attr_accessor :errors
20
22
 
21
23
  SERVICE_URLS = {
22
24
  :us => 'http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService',
@@ -29,11 +31,12 @@ module AmazonProductAdvertisingApi
29
31
 
30
32
  def initialize
31
33
  self.response = AmazonProductAdvertisingApi::Operations::Base::Element.new
34
+ self.errors = []
32
35
  end
33
36
 
34
37
  def query_amazon(params)
35
38
  request_params = {}
36
- request_params["AWSAccessKeyId"] = AmazonProductAdvertisingApi::Base.api_key
39
+ request_params["AWSAccessKeyId"] = AmazonProductAdvertisingApi::Base.access_key_id
37
40
  request_params["Operation"] = self.operation
38
41
  request_params["AssociateTag"] = AmazonProductAdvertisingApi::Base.associate_ids.send(self.region) unless AmazonProductAdvertisingApi::Base.associate_ids.send(self.region).nil?
39
42
  request_params.merge!(params)
@@ -49,7 +52,19 @@ module AmazonProductAdvertisingApi
49
52
  self.hpricot_data = Hpricot.XML(self.raw_data)
50
53
 
51
54
  # Now parse the xml and build out the reponse elements
55
+ self.is_valid = self.hpricot_data.at(:IsValid).inner_html == "True"
56
+
52
57
  self.parse
58
+
59
+ # is_valid only refers to the request, so we could still have errors - check and parse if present
60
+ if !self.hpricot_data.at(:Errors).nil?
61
+ self.hpricot_data.at(:Errors).search(:Error).each do |error|
62
+ self.errors << Struct.new(:code, :message).new(error.at(:Code).inner_html, error.at(:Message).inner_html)
63
+ end
64
+ end
65
+
66
+ # Return false if it's not a valid request, otherwise return the response
67
+ self.is_valid ? self.response : false
53
68
  end
54
69
 
55
70
  def parse
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: completelynovel-amazon-product-advertising-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Gilbraith
@@ -11,27 +11,8 @@ cert_chain: []
11
11
 
12
12
  date: 2009-06-11 00:00:00 -07:00
13
13
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: mime-types
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "1.15"
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: diff-lcs
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 1.1.2
34
- version:
14
+ dependencies: []
15
+
35
16
  description: A nice rubyish interface to the Amazon Product Advertising API, formerly known as the Associates Web Service and before that the Amazon E-Commerce Service.
36
17
  email: jon@completelynovel.com
37
18
  executables: []
@@ -41,7 +22,7 @@ extensions: []
41
22
  extra_rdoc_files: []
42
23
 
43
24
  files:
44
- - EXAMPLE.rdoc
25
+ - EXAMPLE.txt
45
26
  - MIT-LICENSE
46
27
  - README.rdoc
47
28
  - amazon-product-advertising-api.gemspec