alandipert-ruby-aaws 0.7.1
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.
- data/COPYING +340 -0
- data/INSTALL +260 -0
- data/NEWS +710 -0
- data/README +653 -0
- data/README.rdoc +145 -0
- data/Rakefile +35 -0
- data/VERSION +1 -0
- data/example/batch_operation +27 -0
- data/example/browse_node_lookup1 +46 -0
- data/example/customer_content_lookup1 +27 -0
- data/example/customer_content_search1 +21 -0
- data/example/example1 +87 -0
- data/example/help1 +25 -0
- data/example/item_lookup1 +56 -0
- data/example/item_lookup2 +56 -0
- data/example/item_search1 +30 -0
- data/example/item_search2 +37 -0
- data/example/item_search3 +23 -0
- data/example/list_lookup1 +29 -0
- data/example/list_search1 +30 -0
- data/example/multiple_operation1 +68 -0
- data/example/seller_listing_lookup1 +30 -0
- data/example/seller_listing_search1 +28 -0
- data/example/seller_lookup1 +45 -0
- data/example/shopping_cart1 +42 -0
- data/example/similarity_lookup1 +48 -0
- data/example/tag_lookup1 +34 -0
- data/example/transaction_lookup1 +26 -0
- data/example/vehicle_search +22 -0
- data/lib/amazon/aws/cache.rb +141 -0
- data/lib/amazon/aws/search.rb +342 -0
- data/lib/amazon/aws/shoppingcart.rb +504 -0
- data/lib/amazon/aws.rb +1217 -0
- data/lib/amazon/locale.rb +102 -0
- data/lib/amazon.rb +145 -0
- data/ruby-aaws.gemspec +117 -0
- data/setup.rb +1306 -0
- data/test/setup.rb +34 -0
- data/test/tc_amazon.rb +20 -0
- data/test/tc_aws.rb +151 -0
- data/test/tc_browse_node_lookup.rb +62 -0
- data/test/tc_customer_content_lookup.rb +64 -0
- data/test/tc_help.rb +60 -0
- data/test/tc_item_lookup.rb +60 -0
- data/test/tc_item_search.rb +106 -0
- data/test/tc_list_lookup.rb +55 -0
- data/test/tc_list_search.rb +55 -0
- data/test/tc_multiple_operation.rb +265 -0
- data/test/tc_operation_request.rb +58 -0
- data/test/tc_seller_listing_lookup.rb +58 -0
- data/test/tc_seller_listing_search.rb +70 -0
- data/test/tc_seller_lookup.rb +54 -0
- data/test/tc_serialisation.rb +103 -0
- data/test/tc_shopping_cart.rb +214 -0
- data/test/tc_similarity_lookup.rb +59 -0
- data/test/tc_tag_lookup.rb +35 -0
- data/test/tc_transaction_lookup.rb +35 -0
- data/test/tc_vehicle_operations.rb +106 -0
- data/test/ts_aws.rb +24 -0
- metadata +135 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# $Id: locale.rb,v 1.3 2008/06/07 17:28:51 ianmacd Exp $
|
|
2
|
+
#
|
|
3
|
+
|
|
4
|
+
catch :done do
|
|
5
|
+
|
|
6
|
+
begin
|
|
7
|
+
require 'net/geoip'
|
|
8
|
+
rescue LoadError
|
|
9
|
+
throw :done
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
module Amazon
|
|
13
|
+
|
|
14
|
+
# Use of this module requires the use of the GeoIP library from
|
|
15
|
+
# MaxMind[http://www.maxmind.com/]. It also requires the
|
|
16
|
+
# net-geoip[http://rubyforge.org/scm/?group_id=947] Ruby module to
|
|
17
|
+
# interface with it.
|
|
18
|
+
#
|
|
19
|
+
# Load this library as follows:
|
|
20
|
+
#
|
|
21
|
+
# require 'amazon/locale'
|
|
22
|
+
#
|
|
23
|
+
module Locale
|
|
24
|
+
|
|
25
|
+
# These country lists are obviously not complete.
|
|
26
|
+
|
|
27
|
+
# ISO 3166[http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/iso_3166-1_decoding_table.html]
|
|
28
|
+
# codes of countries likely to want to shop in the *CA* locale.
|
|
29
|
+
#
|
|
30
|
+
CA = %w[ ca ]
|
|
31
|
+
|
|
32
|
+
# ISO 3166 codes of countries likely to want to shop in the *DE* locale.
|
|
33
|
+
#
|
|
34
|
+
DE = %w[ at ch de ]
|
|
35
|
+
|
|
36
|
+
# ISO 3166 codes of countries likely to want to shop in the *FR* locale.
|
|
37
|
+
#
|
|
38
|
+
FR = %w[ fr ]
|
|
39
|
+
|
|
40
|
+
# ISO 3166 codes of countries likely to want to shop in the *JP* locale.
|
|
41
|
+
#
|
|
42
|
+
JP = %w[ jp ]
|
|
43
|
+
|
|
44
|
+
# ISO 3166 codes of countries likely to want to shop in the *UK* locale.
|
|
45
|
+
#
|
|
46
|
+
UK = %w[ ad al ba be cy cz dk ee es fi fo gg gi gr gl hu ie im is it je
|
|
47
|
+
li lt lu lv mk mt nl no pl pt ro se si sk sm uk ]
|
|
48
|
+
|
|
49
|
+
# ISO 3166 codes of countries likely to want to shop in the *US* locale.
|
|
50
|
+
# Any countries not explicitly listed above default to the *US* locale.
|
|
51
|
+
#
|
|
52
|
+
US = %w[ mx us ]
|
|
53
|
+
|
|
54
|
+
# Exception class for geolocation errors.
|
|
55
|
+
#
|
|
56
|
+
class GeoError < StandardError; end
|
|
57
|
+
|
|
58
|
+
def Locale.localise(code)
|
|
59
|
+
code.downcase!
|
|
60
|
+
|
|
61
|
+
return 'ca' if CA.include? code
|
|
62
|
+
return 'de' if DE.include? code
|
|
63
|
+
return 'fr' if FR.include? code
|
|
64
|
+
return 'jp' if JP.include? code
|
|
65
|
+
return 'uk' if UK.include? code
|
|
66
|
+
|
|
67
|
+
'us'
|
|
68
|
+
end
|
|
69
|
+
private_class_method :localise
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# This will attempt to return a reasonable locale (*ca*, *de*, *fr*,
|
|
73
|
+
# *jp*, *uk* or *us*) to use for _host_.
|
|
74
|
+
#
|
|
75
|
+
# Example:
|
|
76
|
+
#
|
|
77
|
+
# get_locale_by_name( 'xs1.xs4all.nl' ) => "uk"
|
|
78
|
+
#
|
|
79
|
+
def Locale.get_locale_by_name(host)
|
|
80
|
+
cc = Net::GeoIP.new.country_code_by_name( host )
|
|
81
|
+
raise GeoError, "invalid host: #{host}" unless cc
|
|
82
|
+
localise( cc )
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# This will attempt to return a reasonable locale (*ca*, *de*, *fr*,
|
|
86
|
+
# *jp*, *uk* or *us*) to use for the IP address _address_.
|
|
87
|
+
#
|
|
88
|
+
# Example:
|
|
89
|
+
#
|
|
90
|
+
# get_locale_by_addr( '217.110.207.55' ) => "de"
|
|
91
|
+
#
|
|
92
|
+
def Locale.get_locale_by_addr(address)
|
|
93
|
+
cc = Net::GeoIP.new.country_code_by_addr( address )
|
|
94
|
+
raise GeoError, "invalid address: #{address}" unless cc
|
|
95
|
+
localise( cc )
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
end
|
data/lib/amazon.rb
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# $Id: amazon.rb,v 1.25 2008/10/03 09:35:37 ianmacd Exp $
|
|
2
|
+
#
|
|
3
|
+
|
|
4
|
+
module Amazon
|
|
5
|
+
|
|
6
|
+
#$DEBUG = true
|
|
7
|
+
|
|
8
|
+
# A top-level exception container class.
|
|
9
|
+
#
|
|
10
|
+
class AmazonError < StandardError; end
|
|
11
|
+
|
|
12
|
+
NAME = 'Ruby/Amazon'
|
|
13
|
+
@@config = {}
|
|
14
|
+
|
|
15
|
+
# Prints debugging messages and works like printf, except that it prints
|
|
16
|
+
# only when Ruby is run with the -d switch.
|
|
17
|
+
#
|
|
18
|
+
def Amazon.dprintf(format='', *args)
|
|
19
|
+
$stderr.printf( format + "\n", *args ) if $DEBUG
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# Encode a string, such that it is suitable for HTTP transmission.
|
|
24
|
+
#
|
|
25
|
+
def Amazon.url_encode(string)
|
|
26
|
+
|
|
27
|
+
# Shamelessly plagiarised from Wakou Aoyama's cgi.rb.
|
|
28
|
+
#
|
|
29
|
+
string.gsub( /([^ a-zA-Z0-9_.-]+)/n ) do
|
|
30
|
+
'%' + $1.unpack( 'H2' * $1.size ).join( '%' ).upcase
|
|
31
|
+
end.tr( ' ', '+' )
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def Amazon.rawurlencode(string)
|
|
35
|
+
CGI.escape(string).gsub("+", "%20")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# Convert a string from CamelCase to ruby_case.
|
|
40
|
+
#
|
|
41
|
+
def Amazon.uncamelise(str)
|
|
42
|
+
# Avoid modifying by reference.
|
|
43
|
+
#
|
|
44
|
+
str = str.dup
|
|
45
|
+
|
|
46
|
+
# Don't mess with string if all caps.
|
|
47
|
+
#
|
|
48
|
+
str.gsub!( /(.+?)(([A-Z][a-z]|[A-Z]+$))/, "\\1_\\2" ) if str =~ /[a-z]/
|
|
49
|
+
|
|
50
|
+
# Convert to lower case.
|
|
51
|
+
#
|
|
52
|
+
str.downcase
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# A Class for dealing with configuration files, such as
|
|
57
|
+
# <tt>/etc/amazonrc</tt> and <tt>~/.amazonrc</tt>.
|
|
58
|
+
#
|
|
59
|
+
class Config < Hash
|
|
60
|
+
|
|
61
|
+
require 'stringio'
|
|
62
|
+
|
|
63
|
+
# Exception class for configuration file errors.
|
|
64
|
+
#
|
|
65
|
+
class ConfigError < AmazonError; end
|
|
66
|
+
|
|
67
|
+
# A configuration may be passed in as a string. Otherwise, the files
|
|
68
|
+
# <tt>/etc/amazonrc</tt> and <tt>~/.amazonrc</tt> are read if they exist
|
|
69
|
+
# and are readable.
|
|
70
|
+
#
|
|
71
|
+
def initialize(config_str=nil)
|
|
72
|
+
|
|
73
|
+
if config_str
|
|
74
|
+
|
|
75
|
+
# We have been passed a config file as a string.
|
|
76
|
+
#
|
|
77
|
+
config_files = [ config_str ]
|
|
78
|
+
config_class = StringIO
|
|
79
|
+
|
|
80
|
+
else
|
|
81
|
+
|
|
82
|
+
# Perform the usual search for the system and user config files.
|
|
83
|
+
#
|
|
84
|
+
config_files = [ File.join( '', 'etc', 'amazonrc' ) ]
|
|
85
|
+
|
|
86
|
+
# Figure out where home is. The locations after HOME are for Windows.
|
|
87
|
+
# [ruby-core:12347]
|
|
88
|
+
#
|
|
89
|
+
home = ENV['AMAZONRCDIR'] ||
|
|
90
|
+
ENV['HOME'] || ENV['HOMEDRIVE'] + ENV['HOMEPATH'] ||
|
|
91
|
+
ENV['USERPROFILE']
|
|
92
|
+
user_rcfile = ENV['AMAZONRCFILE'] || '.amazonrc'
|
|
93
|
+
|
|
94
|
+
if home
|
|
95
|
+
config_files << File.expand_path( File.join( home, user_rcfile ) )
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
config_class = File
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
config_files.each do |cf|
|
|
102
|
+
|
|
103
|
+
if config_class == StringIO
|
|
104
|
+
readable = true
|
|
105
|
+
else
|
|
106
|
+
# We must determine whether the file is readable.
|
|
107
|
+
#
|
|
108
|
+
readable = File.exists?( cf ) && File.readable?( cf )
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
if readable
|
|
112
|
+
|
|
113
|
+
Amazon.dprintf( 'Opening %s ...', cf ) if config_class == File
|
|
114
|
+
|
|
115
|
+
config_class.open( cf ) { |f| lines = f.readlines }.each do |line|
|
|
116
|
+
line.chomp!
|
|
117
|
+
|
|
118
|
+
# Skip comments and blank lines.
|
|
119
|
+
#
|
|
120
|
+
next if line =~ /^(#|$)/
|
|
121
|
+
|
|
122
|
+
Amazon.dprintf( 'Read: %s', line )
|
|
123
|
+
|
|
124
|
+
# Store these, because we'll probably find a use for these later.
|
|
125
|
+
#
|
|
126
|
+
begin
|
|
127
|
+
match = line.match( /^\s*(\S+)\s*=\s*(['"]?)([^'"]+)(['"]?)/ )
|
|
128
|
+
key, begin_quote, val, end_quote = match[1, 4]
|
|
129
|
+
raise ConfigError if begin_quote != end_quote
|
|
130
|
+
|
|
131
|
+
rescue NoMethodError, ConfigError
|
|
132
|
+
raise ConfigError, "bad config line: #{line}"
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
self[key] = val
|
|
136
|
+
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
end
|
data/ruby-aaws.gemspec
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |s|
|
|
4
|
+
s.name = %q{ruby-aaws}
|
|
5
|
+
s.version = "0.7.1"
|
|
6
|
+
|
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
8
|
+
s.authors = ["Ian Macdonald", "Jamie Dyer"]
|
|
9
|
+
s.date = %q{2009-08-17}
|
|
10
|
+
s.description = %q{Ruby interface to Amazon Associates Web Services}
|
|
11
|
+
s.email = %q{ian@caliban.org}
|
|
12
|
+
s.extra_rdoc_files = [
|
|
13
|
+
"README",
|
|
14
|
+
"README.rdoc"
|
|
15
|
+
]
|
|
16
|
+
s.files = [
|
|
17
|
+
"COPYING",
|
|
18
|
+
"INSTALL",
|
|
19
|
+
"NEWS",
|
|
20
|
+
"README",
|
|
21
|
+
"README.rdoc",
|
|
22
|
+
"Rakefile",
|
|
23
|
+
"VERSION",
|
|
24
|
+
"example/batch_operation",
|
|
25
|
+
"example/browse_node_lookup1",
|
|
26
|
+
"example/customer_content_lookup1",
|
|
27
|
+
"example/customer_content_search1",
|
|
28
|
+
"example/example1",
|
|
29
|
+
"example/help1",
|
|
30
|
+
"example/item_lookup1",
|
|
31
|
+
"example/item_lookup2",
|
|
32
|
+
"example/item_search1",
|
|
33
|
+
"example/item_search2",
|
|
34
|
+
"example/item_search3",
|
|
35
|
+
"example/list_lookup1",
|
|
36
|
+
"example/list_search1",
|
|
37
|
+
"example/multiple_operation1",
|
|
38
|
+
"example/seller_listing_lookup1",
|
|
39
|
+
"example/seller_listing_search1",
|
|
40
|
+
"example/seller_lookup1",
|
|
41
|
+
"example/shopping_cart1",
|
|
42
|
+
"example/similarity_lookup1",
|
|
43
|
+
"example/tag_lookup1",
|
|
44
|
+
"example/transaction_lookup1",
|
|
45
|
+
"example/vehicle_search",
|
|
46
|
+
"lib/amazon.rb",
|
|
47
|
+
"lib/amazon/aws.rb",
|
|
48
|
+
"lib/amazon/aws/cache.rb",
|
|
49
|
+
"lib/amazon/aws/search.rb",
|
|
50
|
+
"lib/amazon/aws/shoppingcart.rb",
|
|
51
|
+
"lib/amazon/locale.rb",
|
|
52
|
+
"ruby-aaws.gemspec",
|
|
53
|
+
"setup.rb",
|
|
54
|
+
"test/setup.rb",
|
|
55
|
+
"test/tc_amazon.rb",
|
|
56
|
+
"test/tc_aws.rb",
|
|
57
|
+
"test/tc_browse_node_lookup.rb",
|
|
58
|
+
"test/tc_customer_content_lookup.rb",
|
|
59
|
+
"test/tc_help.rb",
|
|
60
|
+
"test/tc_item_lookup.rb",
|
|
61
|
+
"test/tc_item_search.rb",
|
|
62
|
+
"test/tc_list_lookup.rb",
|
|
63
|
+
"test/tc_list_search.rb",
|
|
64
|
+
"test/tc_multiple_operation.rb",
|
|
65
|
+
"test/tc_operation_request.rb",
|
|
66
|
+
"test/tc_seller_listing_lookup.rb",
|
|
67
|
+
"test/tc_seller_listing_search.rb",
|
|
68
|
+
"test/tc_seller_lookup.rb",
|
|
69
|
+
"test/tc_serialisation.rb",
|
|
70
|
+
"test/tc_shopping_cart.rb",
|
|
71
|
+
"test/tc_similarity_lookup.rb",
|
|
72
|
+
"test/tc_tag_lookup.rb",
|
|
73
|
+
"test/tc_transaction_lookup.rb",
|
|
74
|
+
"test/tc_vehicle_operations.rb",
|
|
75
|
+
"test/ts_aws.rb"
|
|
76
|
+
]
|
|
77
|
+
s.has_rdoc = true
|
|
78
|
+
s.homepage = %q{http://www.caliban.org/ruby/ruby-aws/}
|
|
79
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
80
|
+
s.require_paths = ["lib"]
|
|
81
|
+
s.rubygems_version = %q{1.3.1}
|
|
82
|
+
s.summary = %q{Ruby interface to Amazon Associates Web Services}
|
|
83
|
+
s.test_files = [
|
|
84
|
+
"test/setup.rb",
|
|
85
|
+
"test/tc_amazon.rb",
|
|
86
|
+
"test/tc_aws.rb",
|
|
87
|
+
"test/tc_browse_node_lookup.rb",
|
|
88
|
+
"test/tc_customer_content_lookup.rb",
|
|
89
|
+
"test/tc_help.rb",
|
|
90
|
+
"test/tc_item_lookup.rb",
|
|
91
|
+
"test/tc_item_search.rb",
|
|
92
|
+
"test/tc_list_lookup.rb",
|
|
93
|
+
"test/tc_list_search.rb",
|
|
94
|
+
"test/tc_multiple_operation.rb",
|
|
95
|
+
"test/tc_operation_request.rb",
|
|
96
|
+
"test/tc_seller_listing_lookup.rb",
|
|
97
|
+
"test/tc_seller_listing_search.rb",
|
|
98
|
+
"test/tc_seller_lookup.rb",
|
|
99
|
+
"test/tc_serialisation.rb",
|
|
100
|
+
"test/tc_shopping_cart.rb",
|
|
101
|
+
"test/tc_similarity_lookup.rb",
|
|
102
|
+
"test/tc_tag_lookup.rb",
|
|
103
|
+
"test/tc_transaction_lookup.rb",
|
|
104
|
+
"test/tc_vehicle_operations.rb",
|
|
105
|
+
"test/ts_aws.rb"
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
if s.respond_to? :specification_version then
|
|
109
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
110
|
+
s.specification_version = 2
|
|
111
|
+
|
|
112
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
113
|
+
else
|
|
114
|
+
end
|
|
115
|
+
else
|
|
116
|
+
end
|
|
117
|
+
end
|