a2ws 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +12 -0
- data/Rakefile +52 -0
- data/VERSION.yml +3 -0
- data/a2ws.gemspec +62 -0
- data/lib/a2ws.rb +12 -0
- data/lib/a2ws/base.rb +34 -0
- data/lib/a2ws/image.rb +16 -0
- data/lib/a2ws/image_search.rb +21 -0
- data/lib/a2ws/item.rb +23 -0
- data/lib/a2ws/item_search.rb +21 -0
- data/lib/a2ws/methodize.rb +17 -0
- data/spec/a2ws_spec.rb +28 -0
- data/spec/spec_helper.rb +10 -0
- metadata +92 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Andy Shen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "a2ws"
|
8
|
+
gem.summary = %Q{Wrapper for Amazon Associates Web Service (A2WS).}
|
9
|
+
gem.email = "andy@shenie.info"
|
10
|
+
gem.homepage = "http://github.com/shenie/a2ws"
|
11
|
+
gem.authors = ["Andy Shen", "Josh Owens"]
|
12
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
|
+
gem.add_dependency('httparty', '>= 0.4.3')
|
14
|
+
gem.add_dependency('activesupport', '>= 2.2.2')
|
15
|
+
end
|
16
|
+
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'spec/rake/spectask'
|
24
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
25
|
+
spec.libs << 'lib' << 'spec'
|
26
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
end
|
28
|
+
|
29
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
30
|
+
spec.libs << 'lib' << 'spec'
|
31
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
+
spec.rcov = true
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
if File.exist?('VERSION.yml')
|
41
|
+
config = YAML.load(File.read('VERSION.yml'))
|
42
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
43
|
+
else
|
44
|
+
version = ""
|
45
|
+
end
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "a2ws #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
52
|
+
|
data/VERSION.yml
ADDED
data/a2ws.gemspec
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{a2ws}
|
8
|
+
s.version = "0.1.9"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Andy Shen", "Josh Owens"]
|
12
|
+
s.date = %q{2009-10-30}
|
13
|
+
s.email = %q{andy@shenie.info}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE",
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION.yml",
|
25
|
+
"a2ws.gemspec",
|
26
|
+
"lib/a2ws.rb",
|
27
|
+
"lib/a2ws/base.rb",
|
28
|
+
"lib/a2ws/image.rb",
|
29
|
+
"lib/a2ws/image_search.rb",
|
30
|
+
"lib/a2ws/item.rb",
|
31
|
+
"lib/a2ws/item_search.rb",
|
32
|
+
"lib/a2ws/methodize.rb",
|
33
|
+
"spec/a2ws_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/shenie/a2ws}
|
37
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.5}
|
40
|
+
s.summary = %q{Wrapper for Amazon Associates Web Service (A2WS).}
|
41
|
+
s.test_files = [
|
42
|
+
"spec/a2ws_spec.rb",
|
43
|
+
"spec/spec_helper.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0.4.3"])
|
52
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 2.2.2"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<httparty>, [">= 0.4.3"])
|
55
|
+
s.add_dependency(%q<activesupport>, [">= 2.2.2"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<httparty>, [">= 0.4.3"])
|
59
|
+
s.add_dependency(%q<activesupport>, [">= 2.2.2"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
data/lib/a2ws.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'httparty'
|
3
|
+
require 'activesupport'
|
4
|
+
require 'pp'
|
5
|
+
|
6
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
7
|
+
require 'a2ws/base'
|
8
|
+
require 'a2ws/methodize'
|
9
|
+
require 'a2ws/item'
|
10
|
+
require 'a2ws/image'
|
11
|
+
require 'a2ws/item_search'
|
12
|
+
require 'a2ws/image_search'
|
data/lib/a2ws/base.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module A2WS
|
2
|
+
class Base
|
3
|
+
include HTTParty
|
4
|
+
base_uri 'http://ecs.amazonaws.com'
|
5
|
+
default_params :Service => 'AWSECommerceService', :Operation => 'ItemSearch'
|
6
|
+
|
7
|
+
def self.configure
|
8
|
+
yield self
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.api_key=(key)
|
12
|
+
default_params :AWSAccessKeyId => key
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.downcase_keys(hash)
|
18
|
+
new_hash = {}
|
19
|
+
hash.keys.each do |key|
|
20
|
+
value = hash.delete(key)
|
21
|
+
new_hash[downcase_key(key)] = value
|
22
|
+
new_hash[downcase_key(key)] = downcase_keys(value) if value.is_a?(Hash)
|
23
|
+
new_hash[downcase_key(key)] = value.each{|p| downcase_keys(p) if p.is_a?(Hash)} if value.is_a?(Array)
|
24
|
+
end
|
25
|
+
new_hash
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.downcase_key(key)
|
29
|
+
key.titlecase.downcase.gsub(' ', '_')
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/lib/a2ws/image.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module A2WS
|
2
|
+
|
3
|
+
|
4
|
+
class ImageSearch < Base
|
5
|
+
|
6
|
+
def self.find(item)
|
7
|
+
items = get('/onca/xml', :query => {:ItemId => item, :Operation => "ItemLookup", :ResponseGroup => "Images"})
|
8
|
+
puts items.inspect
|
9
|
+
if items['ItemLookupResponse']["Items"]["Request"]['IsValid'] == 'True'
|
10
|
+
items["ItemLookupResponse"]["Items"]["Item"].delete("ImageSets")
|
11
|
+
items["ItemLookupResponse"]["Items"]["Item"].delete("ASIN")
|
12
|
+
downcase_keys(items["ItemLookupResponse"]["Items"]["Item"]).collect { |size, data| Image.new(size, data) }
|
13
|
+
else
|
14
|
+
raise items['Request']['Errors']['Error']['Message']
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
end
|
data/lib/a2ws/item.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module A2WS
|
2
|
+
|
3
|
+
|
4
|
+
class Item
|
5
|
+
include Methodize
|
6
|
+
|
7
|
+
def item_attributes
|
8
|
+
ItemAttributes.new @data_hash["item_attributes"]
|
9
|
+
end
|
10
|
+
|
11
|
+
def images
|
12
|
+
ImageSearch.find(@data_hash["asin"])
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
class ItemAttributes
|
18
|
+
include Methodize
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module A2WS
|
2
|
+
|
3
|
+
class ItemSearch < Base
|
4
|
+
|
5
|
+
def self.find(keywords, search_index = :All, options = {})
|
6
|
+
options.merge!({:Keywords => keywords, :SearchIndex => search_index})
|
7
|
+
result = get('/onca/xml', :query => options)
|
8
|
+
|
9
|
+
items = result["ItemSearchResponse"]["Items"]
|
10
|
+
if items['Request']['IsValid'] == 'True'
|
11
|
+
items['Item'].collect do |i|
|
12
|
+
Item.new downcase_keys(i)
|
13
|
+
end
|
14
|
+
else
|
15
|
+
raise items['Request']['Errors']['Error']['Message']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Methodize
|
2
|
+
|
3
|
+
attr_accessor :data_hash
|
4
|
+
|
5
|
+
def initialize(attributes)
|
6
|
+
@data_hash = attributes
|
7
|
+
end
|
8
|
+
|
9
|
+
def method_missing(meth,*args)
|
10
|
+
if @data_hash.keys.include?(meth.to_s)
|
11
|
+
@data_hash[meth.to_s]
|
12
|
+
else
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/spec/a2ws_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
include A2WS
|
5
|
+
|
6
|
+
config = YAML::load(open(ENV['HOME'] + '/.a2ws'))
|
7
|
+
access_key = config["access_key"]
|
8
|
+
|
9
|
+
A2WS::Base.configure do |config|
|
10
|
+
config.api_key = access_key
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "A2WS Operations" do
|
14
|
+
|
15
|
+
describe "ItemSearch" do
|
16
|
+
|
17
|
+
it "should require SearchIndex" do
|
18
|
+
search = ItemSearch.new
|
19
|
+
lambda { search.find }.should raise_error
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should find some items" do
|
23
|
+
search = ItemSearch.new(:Books)
|
24
|
+
search.find(nil, :Title => 'Harry Potter').size.should_not == 0
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: a2ws
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.9
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andy Shen
|
8
|
+
- Josh Owens
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-10-30 00:00:00 +11:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: httparty
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.4.3
|
25
|
+
version:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: activesupport
|
28
|
+
type: :runtime
|
29
|
+
version_requirement:
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 2.2.2
|
35
|
+
version:
|
36
|
+
description:
|
37
|
+
email: andy@shenie.info
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- LICENSE
|
44
|
+
- README.rdoc
|
45
|
+
files:
|
46
|
+
- .document
|
47
|
+
- .gitignore
|
48
|
+
- LICENSE
|
49
|
+
- README.rdoc
|
50
|
+
- Rakefile
|
51
|
+
- VERSION.yml
|
52
|
+
- a2ws.gemspec
|
53
|
+
- lib/a2ws.rb
|
54
|
+
- lib/a2ws/base.rb
|
55
|
+
- lib/a2ws/image.rb
|
56
|
+
- lib/a2ws/image_search.rb
|
57
|
+
- lib/a2ws/item.rb
|
58
|
+
- lib/a2ws/item_search.rb
|
59
|
+
- lib/a2ws/methodize.rb
|
60
|
+
- spec/a2ws_spec.rb
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
has_rdoc: true
|
63
|
+
homepage: http://github.com/shenie/a2ws
|
64
|
+
licenses: []
|
65
|
+
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options:
|
68
|
+
- --charset=UTF-8
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: "0"
|
76
|
+
version:
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: "0"
|
82
|
+
version:
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.3.5
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Wrapper for Amazon Associates Web Service (A2WS).
|
90
|
+
test_files:
|
91
|
+
- spec/a2ws_spec.rb
|
92
|
+
- spec/spec_helper.rb
|