amazon-ecs 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/README +16 -9
- data/lib/amazon/ecs.rb +48 -10
- data/test/amazon/ecs_test.rb +23 -4
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
0.5.1 2006-02-08
|
2
|
+
----------------
|
3
|
+
* Fixed Amazon Japan and France URL error
|
4
|
+
* Removed opts.delete(:search_index) from item_lookup, SearchIndex param is allowed
|
5
|
+
when looking for a book with IdType other than the ASIN.
|
6
|
+
* Check for defined? RAILS_DEFAULT_LOGGER to avoid exception for non-rails ruby app
|
7
|
+
* Added check for LOGGER constant if RAILS_DEFAULT_LOGGER is not defined
|
8
|
+
* Added Ecs.configure(&proc) method for easier configuration of default options
|
9
|
+
* Added Element#search_and_convert method
|
10
|
+
|
1
11
|
0.5.0 2006-09-12
|
2
12
|
----------------
|
3
13
|
Initial Release
|
data/README
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Generic Amazon E-commerce REST API using Hpricot with configurable
|
4
4
|
default options and method call options. Uses Response and
|
5
|
-
Element classes for easy access
|
5
|
+
Element wrapper classes for easy access to REST XML output. It supports ECS 4.0.
|
6
6
|
|
7
7
|
It is generic, so you can easily extend <tt>Amazon::Ecs</tt> to support
|
8
8
|
other not implemented REST operations; and it is also generic because it just wraps around
|
@@ -12,7 +12,7 @@ If in the future, there is a change in REST XML output structure,
|
|
12
12
|
no changes will be required on <tt>amazon-ecs</tt> library,
|
13
13
|
instead you just need to change the element path.
|
14
14
|
|
15
|
-
Version: 0.5.
|
15
|
+
Version: 0.5.1
|
16
16
|
|
17
17
|
Links:
|
18
18
|
* http://amazon-ecs.rubyforge.org
|
@@ -24,18 +24,20 @@ Links:
|
|
24
24
|
|
25
25
|
== EXAMPLE
|
26
26
|
|
27
|
-
|
27
|
+
require 'amazon/ecs'
|
28
|
+
|
29
|
+
# set the default options; options will be camelized and converted to REST request parameters.
|
28
30
|
Amazon::Ecs.options = {:aWS_access_key_id => [your developer token]}
|
29
31
|
|
30
32
|
# options provided on method call will merge with the default options
|
31
33
|
res = Amazon::Ecs.item_search('ruby', {:response_group => 'Medium', :sort => 'salesrank'})
|
32
34
|
|
33
35
|
# some common response object methods
|
34
|
-
res.is_valid_request? # return true request is valid
|
36
|
+
res.is_valid_request? # return true if request is valid
|
35
37
|
res.has_error? # return true if there is an error
|
36
38
|
res.error # return error message if there is any
|
37
39
|
res.total_pages # return total pages
|
38
|
-
res.total_results # return total
|
40
|
+
res.total_results # return total results
|
39
41
|
res.item_page # return current page no if :item_page option is provided
|
40
42
|
|
41
43
|
# traverse through each item (Amazon::Element)
|
@@ -63,14 +65,19 @@ Links:
|
|
63
65
|
# Getting hash value out of Hpricot element
|
64
66
|
Amazon::Element.get_hash(review) # [:source => ..., :content ==> ...]
|
65
67
|
|
66
|
-
# Or
|
67
|
-
Amazon::Element.
|
68
|
-
Amazon::Element.
|
68
|
+
# Or to get unescaped HTML values
|
69
|
+
Amazon::Element.get_unescaped(review, 'source')
|
70
|
+
Amazon::Element.get_unescaped(review, 'content')
|
71
|
+
|
72
|
+
# Or this way
|
73
|
+
el = Amazon::Element.new(review)
|
74
|
+
el.get_unescaped('source')
|
75
|
+
el.get_unescaped('content')
|
69
76
|
end
|
70
77
|
end
|
71
78
|
|
72
79
|
Refer to Amazon ECS documentation for more information on Amazon REST request parameters and XML output:
|
73
|
-
http://docs.amazonwebservices.com/AWSEcommerceService/
|
80
|
+
http://docs.amazonwebservices.com/AWSEcommerceService/2006-09-13/
|
74
81
|
|
75
82
|
To get a sample of Amazon REST response XML output, use AWSZone.com scratch pad:
|
76
83
|
http://www.awszone.com/scratchpads/aws/ecs.us/index.aws
|
data/lib/amazon/ecs.rb
CHANGED
@@ -1,3 +1,26 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2006 Herryanto Siatono, Pluit Solutions
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
1
24
|
require 'net/http'
|
2
25
|
require 'hpricot'
|
3
26
|
require 'cgi'
|
@@ -11,11 +34,12 @@ module Amazon
|
|
11
34
|
:uk => 'http://webservices.amazon.co.uk/onca/xml?Service=AWSECommerceService',
|
12
35
|
:ca => 'http://webservices.amazon.ca/onca/xml?Service=AWSECommerceService',
|
13
36
|
:de => 'http://webservices.amazon.de/onca/xml?Service=AWSECommerceService',
|
14
|
-
:jp => 'http://webservices.amazon.
|
15
|
-
:fr => 'http://webservices.amazon.
|
37
|
+
:jp => 'http://webservices.amazon.co.jp/onca/xml?Service=AWSECommerceService',
|
38
|
+
:fr => 'http://webservices.amazon.fr/onca/xml?Service=AWSECommerceService'
|
16
39
|
}
|
17
40
|
|
18
|
-
@@
|
41
|
+
@@options = {}
|
42
|
+
@@debug = false
|
19
43
|
|
20
44
|
# Default search options
|
21
45
|
def self.options
|
@@ -35,7 +59,12 @@ module Amazon
|
|
35
59
|
# Set debug flag to true or false.
|
36
60
|
def self.debug=(dbg)
|
37
61
|
@@debug = dbg
|
38
|
-
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.configure(&proc)
|
65
|
+
raise ArgumentError, "Block is required." unless block_given?
|
66
|
+
yield @@options
|
67
|
+
end
|
39
68
|
|
40
69
|
# Search amazon items with search terms. Default search index option is 'Books'.
|
41
70
|
# For other search type other than keywords, please specify :type => [search type param name].
|
@@ -60,12 +89,9 @@ module Amazon
|
|
60
89
|
opts[:operation] = 'ItemLookup'
|
61
90
|
opts[:item_id] = item_id
|
62
91
|
|
63
|
-
# not allowed in item_lookup
|
64
|
-
opts.delete(:search_index)
|
65
|
-
|
66
92
|
self.send_request(opts)
|
67
|
-
end
|
68
|
-
|
93
|
+
end
|
94
|
+
|
69
95
|
# Generic send request to ECS REST service. You have to specify the :operation parameter.
|
70
96
|
def self.send_request(opts)
|
71
97
|
request_url = prepare_url(opts)
|
@@ -146,8 +172,10 @@ module Amazon
|
|
146
172
|
protected
|
147
173
|
def self.log(s)
|
148
174
|
return unless self.debug
|
149
|
-
if RAILS_DEFAULT_LOGGER
|
175
|
+
if defined? RAILS_DEFAULT_LOGGER
|
150
176
|
RAILS_DEFAULT_LOGGER.error(s)
|
177
|
+
elsif defined? LOGGER
|
178
|
+
LOGGER.error(s)
|
151
179
|
else
|
152
180
|
puts s
|
153
181
|
end
|
@@ -192,6 +220,16 @@ module Amazon
|
|
192
220
|
return nil if elements.size == 0
|
193
221
|
elements
|
194
222
|
end
|
223
|
+
|
224
|
+
# Find Hpricot::Elements matching the given path, and convert to Amazon::Element.
|
225
|
+
# Returns an array Amazon::Elements if more than Hpricot::Elements size is greater than 1.
|
226
|
+
def search_and_convert(path)
|
227
|
+
elements = self./(path)
|
228
|
+
return unless elements
|
229
|
+
elements = elements.map{|element| Element.new(element)}
|
230
|
+
return elements.first if elements.size == 1
|
231
|
+
elements
|
232
|
+
end
|
195
233
|
|
196
234
|
# Get the text value of the given path, leave empty to retrieve current element value.
|
197
235
|
def get(path='')
|
data/test/amazon/ecs_test.rb
CHANGED
@@ -2,7 +2,15 @@ require File.dirname(__FILE__) + '/../test_helper'
|
|
2
2
|
|
3
3
|
class Amazon::EcsTest < Test::Unit::TestCase
|
4
4
|
|
5
|
-
|
5
|
+
AWS_ACCESS_KEY_ID = ''
|
6
|
+
raise "Please specify set your AWS_ACCESS_KEY_ID" if AWS_ACCESS_KEY_ID.empty?
|
7
|
+
|
8
|
+
Amazon::Ecs.configure do |options|
|
9
|
+
options[:response_group] = 'Large'
|
10
|
+
options[:aWS_access_key_id] = AWS_ACCESS_KEY_ID
|
11
|
+
end
|
12
|
+
|
13
|
+
## Test item_search
|
6
14
|
|
7
15
|
def test_item_search
|
8
16
|
resp = Amazon::Ecs.item_search('ruby')
|
@@ -56,8 +64,7 @@ class Amazon::EcsTest < Test::Unit::TestCase
|
|
56
64
|
small_image = item.get_hash("smallimage")
|
57
65
|
|
58
66
|
assert_equal 3, small_image.keys.size
|
59
|
-
assert_match "
|
60
|
-
small_image[:url]
|
67
|
+
assert_match "0974514055.01", small_image[:url]
|
61
68
|
assert_equal "75", small_image[:height]
|
62
69
|
assert_equal "59", small_image[:width]
|
63
70
|
|
@@ -70,6 +77,7 @@ class Amazon::EcsTest < Test::Unit::TestCase
|
|
70
77
|
end
|
71
78
|
end
|
72
79
|
|
80
|
+
## Test item_lookup
|
73
81
|
def test_item_lookup
|
74
82
|
resp = Amazon::Ecs.item_lookup('0974514055')
|
75
83
|
assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition",
|
@@ -88,4 +96,15 @@ class Amazon::EcsTest < Test::Unit::TestCase
|
|
88
96
|
assert resp.is_valid_request?
|
89
97
|
assert_match(/ABC is not a valid value for ItemId/, resp.error)
|
90
98
|
end
|
91
|
-
|
99
|
+
|
100
|
+
def test_search_and_convert
|
101
|
+
resp = Amazon::Ecs.item_lookup('0974514055')
|
102
|
+
title = resp.first_item.get("itemattributes/title")
|
103
|
+
authors = resp.first_item.search_and_convert("author")
|
104
|
+
|
105
|
+
assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition", title
|
106
|
+
assert authors.is_a?(Array)
|
107
|
+
assert 3, authors.size
|
108
|
+
assert_equal "Dave Thomas", authors.first.get
|
109
|
+
end
|
110
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: amazon-ecs
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.5.
|
7
|
-
date:
|
6
|
+
version: 0.5.1
|
7
|
+
date: 2007-02-09 00:00:00 +08:00
|
8
8
|
summary: Generic Amazon E-commerce Service (ECS) REST API. Supports ECS 4.0.
|
9
9
|
require_paths:
|
10
10
|
- lib
|