briandunn-a2ws 0.1.9 → 0.1.10

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/Rakefile CHANGED
@@ -6,12 +6,12 @@ begin
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "a2ws"
8
8
  gem.summary = %Q{Wrapper for Amazon Associates Web Service (A2WS).}
9
- gem.email = "brianpatrickdunn@gmail.com"
9
+ gem.email = "andy@shenie.info"
10
10
  gem.homepage = "http://github.com/handcrafted/a2ws"
11
11
  gem.authors = ["Andy Shen", "Josh Owens"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
12
13
  gem.add_dependency('httparty', '>= 0.4.3')
13
14
  gem.add_dependency('activesupport', '>= 2.2.2')
14
- gem.add_dependency('ruby-hmac')
15
15
  end
16
16
 
17
17
  rescue LoadError
data/a2ws.gemspec CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{a2ws}
5
- s.version = "0.1.9"
5
+ s.version = "0.1.10"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Andy Shen", "Josh Owens"]
9
- s.date = %q{2009-08-04}
10
- s.email = %q{brianpatrickdunn@gmail.com}
9
+ s.date = %q{2009-06-01}
10
+ s.email = %q{andy@shenie.info}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
13
13
  "README.rdoc"
@@ -27,43 +27,33 @@ Gem::Specification.new do |s|
27
27
  "lib/a2ws/item.rb",
28
28
  "lib/a2ws/item_search.rb",
29
29
  "lib/a2ws/methodize.rb",
30
- "lib/a2ws/signature.rb",
31
- "spec/a2ws_live_spec.rb",
32
30
  "spec/a2ws_spec.rb",
33
- "spec/fixtures/empty_response.yml",
34
- "spec/fixtures/single_item_response.yml",
35
- "spec/spec_helper.rb",
36
- "test/a2ws_test.rb"
31
+ "spec/spec_helper.rb"
37
32
  ]
38
33
  s.has_rdoc = true
39
34
  s.homepage = %q{http://github.com/handcrafted/a2ws}
40
35
  s.rdoc_options = ["--charset=UTF-8"]
41
36
  s.require_paths = ["lib"]
42
- s.rubygems_version = %q{1.3.1}
37
+ s.rubygems_version = %q{1.3.2}
43
38
  s.summary = %q{Wrapper for Amazon Associates Web Service (A2WS).}
44
39
  s.test_files = [
45
- "spec/a2ws_live_spec.rb",
46
- "spec/a2ws_spec.rb",
47
- "spec/spec_helper.rb",
48
- "test/a2ws_test.rb"
40
+ "spec/a2ws_spec.rb",
41
+ "spec/spec_helper.rb"
49
42
  ]
50
43
 
51
44
  if s.respond_to? :specification_version then
52
45
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
- s.specification_version = 2
46
+ s.specification_version = 3
54
47
 
55
48
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
49
  s.add_runtime_dependency(%q<httparty>, [">= 0.4.3"])
57
50
  s.add_runtime_dependency(%q<activesupport>, [">= 2.2.2"])
58
- s.add_runtime_dependency(%q<ruby-hmac>, [">= 0"])
59
51
  else
60
52
  s.add_dependency(%q<httparty>, [">= 0.4.3"])
61
53
  s.add_dependency(%q<activesupport>, [">= 2.2.2"])
62
- s.add_dependency(%q<ruby-hmac>, [">= 0"])
63
54
  end
64
55
  else
65
56
  s.add_dependency(%q<httparty>, [">= 0.4.3"])
66
57
  s.add_dependency(%q<activesupport>, [">= 2.2.2"])
67
- s.add_dependency(%q<ruby-hmac>, [">= 0"])
68
58
  end
69
59
  end
data/lib/a2ws.rb CHANGED
@@ -4,10 +4,9 @@ require 'activesupport'
4
4
  require 'pp'
5
5
 
6
6
  $:.unshift File.join(File.dirname(__FILE__),'..','lib')
7
- require 'a2ws/signature'
8
7
  require 'a2ws/base'
9
8
  require 'a2ws/methodize'
10
9
  require 'a2ws/item'
11
10
  require 'a2ws/image'
12
11
  require 'a2ws/item_search'
13
- require 'a2ws/image_search'
12
+ require 'a2ws/image_search'
data/lib/a2ws/base.rb CHANGED
@@ -1,10 +1,8 @@
1
1
  module A2WS
2
2
  class Base
3
3
  include HTTParty
4
- extend Signature
5
4
  base_uri 'http://ecs.amazonaws.com'
6
5
  default_params :Service => 'AWSECommerceService', :Operation => 'ItemSearch'
7
- @@secret_key = ''
8
6
 
9
7
  def self.configure
10
8
  yield self
@@ -13,21 +11,9 @@ module A2WS
13
11
  def self.api_key=(key)
14
12
  default_params :AWSAccessKeyId => key
15
13
  end
16
-
17
- def self.secret_key=(key)
18
- @@secret_key = key
19
- end
20
-
21
- def self.secret_key
22
- @@secret_key
23
- end
24
-
25
- def self.request_uri
26
- '/onca/xml'
27
- end
28
-
14
+
29
15
  private
30
-
16
+
31
17
  def self.downcase_keys(hash)
32
18
  new_hash = {}
33
19
  hash.keys.each do |key|
@@ -4,7 +4,7 @@ module A2WS
4
4
  class ImageSearch < Base
5
5
 
6
6
  def self.find(item)
7
- items = get(request_url, :query => {:ItemId => item, :Operation => "ItemLookup", :ResponseGroup => "Images"})
7
+ items = get('/onca/xml', :query => {:ItemId => item, :Operation => "ItemLookup", :ResponseGroup => "Images"})
8
8
  puts items.inspect
9
9
  if items['ItemLookupResponse']["Items"]["Request"]['IsValid'] == 'True'
10
10
  items["ItemLookupResponse"]["Items"]["Item"].delete("ImageSets")
@@ -18,4 +18,4 @@ module A2WS
18
18
  end
19
19
 
20
20
 
21
- end
21
+ end
@@ -4,14 +4,11 @@ module A2WS
4
4
 
5
5
  def self.find(keywords, search_index = :All, options = {})
6
6
  options.merge!({:Keywords => keywords, :SearchIndex => search_index})
7
- query = sign_request(options)
8
- puts query.inspect
9
- result = get( request_uri, :query => query )
10
- puts result.inspect
7
+ result = get('/onca/xml', :query => options)
11
8
 
12
9
  items = result["ItemSearchResponse"]["Items"]
13
10
  if items['Request']['IsValid'] == 'True'
14
- [ items['Item'] ].flatten.compact.collect do |i|
11
+ [ items['Item'] ].flatten.collect do |i|
15
12
  Item.new downcase_keys(i)
16
13
  end
17
14
  else
data/spec/a2ws_spec.rb CHANGED
@@ -7,15 +7,10 @@ describe "A2WS Operations" do
7
7
  describe ItemSearch do
8
8
 
9
9
  it "should survive a search that returns a single result" do
10
- ItemSearch.should_receive(:get).and_return(fixture :single_item_response)
10
+ ItemSearch.should_receive(:get).and_return(YAML.load(File.open(File.expand_path(File.dirname(__FILE__) + '/fixtures/single_item_response.yml'))))
11
11
  ItemSearch.find('not used')
12
12
  end
13
13
 
14
- it "should return an empty array when there aint no results" do
15
- ItemSearch.should_receive(:get).and_return(fixture :empty_response)
16
- ItemSearch.find( "not used" ).should == []
17
- end
18
-
19
14
  end
20
15
 
21
16
  end
data/spec/spec_helper.rb CHANGED
@@ -7,7 +7,5 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
7
  require 'a2ws'
8
8
 
9
9
  Spec::Runner.configure do |config|
10
- def fixture file_name
11
- YAML.load(File.open(File.expand_path(File.dirname(__FILE__) + "/fixtures/#{file_name}.yml")))
12
- end
10
+
13
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: briandunn-a2ws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Shen
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-08-04 00:00:00 -07:00
13
+ date: 2009-06-01 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -33,18 +33,8 @@ dependencies:
33
33
  - !ruby/object:Gem::Version
34
34
  version: 2.2.2
35
35
  version:
36
- - !ruby/object:Gem::Dependency
37
- name: ruby-hmac
38
- type: :runtime
39
- version_requirement:
40
- version_requirements: !ruby/object:Gem::Requirement
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- version: "0"
45
- version:
46
36
  description:
47
- email: brianpatrickdunn@gmail.com
37
+ email: andy@shenie.info
48
38
  executables: []
49
39
 
50
40
  extensions: []
@@ -67,13 +57,8 @@ files:
67
57
  - lib/a2ws/item.rb
68
58
  - lib/a2ws/item_search.rb
69
59
  - lib/a2ws/methodize.rb
70
- - lib/a2ws/signature.rb
71
- - spec/a2ws_live_spec.rb
72
60
  - spec/a2ws_spec.rb
73
- - spec/fixtures/empty_response.yml
74
- - spec/fixtures/single_item_response.yml
75
61
  - spec/spec_helper.rb
76
- - test/a2ws_test.rb
77
62
  has_rdoc: true
78
63
  homepage: http://github.com/handcrafted/a2ws
79
64
  licenses:
@@ -99,10 +84,8 @@ requirements: []
99
84
  rubyforge_project:
100
85
  rubygems_version: 1.3.5
101
86
  signing_key:
102
- specification_version: 2
87
+ specification_version: 3
103
88
  summary: Wrapper for Amazon Associates Web Service (A2WS).
104
89
  test_files:
105
- - spec/a2ws_live_spec.rb
106
90
  - spec/a2ws_spec.rb
107
91
  - spec/spec_helper.rb
108
- - test/a2ws_test.rb
@@ -1,46 +0,0 @@
1
- require "hmac"
2
- require "hmac-sha2"
3
- require 'cgi'
4
-
5
- # reference:
6
- # http://docs.amazonwebservices.com/AWSECommerceService/2009-07-01/DG/index.html?BasicAuthProcess.html
7
- # http://docs.amazonwebservices.com/AWSECommerceService/2009-07-01/DG/index.html?Query_QueryAuth.html
8
- module A2WS
9
- module Signature
10
- def sign_request(params)
11
- params.reverse_merge!(:Timestamp => timestamp, :Version => "2009-07-01")
12
- params.merge!(:Signature => build_signature(params, "GET"))
13
- params
14
- end
15
-
16
- private
17
-
18
- def timestamp
19
- Time.now.gmtime.strftime("%Y-%m-%dT%H:%M:%SZ")
20
- end
21
-
22
- def build_string_to_sign(params, http_verb)
23
- returning [] do |string_to_sign|
24
- string_to_sign << http_verb << self.base_uri.gsub(/^https?\:\/\//, "") << self.request_uri
25
- canonicalized_params = params.sort_by {|k,v| k.to_s }.map do |( k,v )|
26
- "#{aws_escape(k.to_s)}=#{aws_escape(v.to_s)}"
27
- end.join("&")
28
- string_to_sign << canonicalized_params
29
- end.join("\n")
30
- end
31
-
32
- def build_signature(params, http_verb)
33
- params.merge!(self.default_params)
34
-
35
- hmac = HMAC::SHA256.new(secret_key)
36
- hmac.update(build_string_to_sign(params, http_verb))
37
-
38
- Base64.encode64(hmac.digest).chomp
39
- end
40
-
41
- def aws_escape(string)
42
- CGI.escape(string).gsub("+", "%20").gsub("%7E", "~")
43
- end
44
- end
45
- end
46
-
@@ -1,28 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- include A2WS
4
- begin
5
- conf = YAML::load(open(ENV['HOME'] + '/.a2ws'))
6
- A2WS::Base.configure do |config|
7
- config.api_key = conf["access_key"]
8
- config.secret_key = conf["secret_key"]
9
- end
10
- describe "A2WS Operations" do
11
-
12
- describe ItemSearch do
13
-
14
- it "should find some items" do
15
- ItemSearch.find('Harry Potter', :Books).size.should_not == 0
16
- end
17
-
18
- end
19
-
20
- describe "signing" do
21
- ItemSearch.find('Harry Potter', :Books).size.should_not == 0
22
- end
23
-
24
- end
25
- rescue
26
- puts "couldn't run live specs. if you want to actually hit up the api, put your key in a yaml file in your home folder.#{$!}"
27
- end
28
-
@@ -1,73 +0,0 @@
1
- ---
2
- ItemSearchResponse:
3
- OperationRequest:
4
- Arguments:
5
- Argument:
6
- - Name: Operation
7
- Value: ItemSearch
8
- - Name: Service
9
- Value: AWSECommerceService
10
- - Name: AWSAccessKeyId
11
- Value: AKIAJJES5KN2IIXQSSOA
12
- - Name: SearchIndex
13
- Value: Books
14
- - Name: Keywords
15
- Value: assdflasdjfasldkfjasdl
16
- RequestId: !str
17
- str: 46ebabe5-abe2-44ff-a010-7b76cb0538c9
18
- "@attributes": {}
19
-
20
- RequestProcessingTime: !str
21
- str: "0.0196700000000000"
22
- "@attributes": {}
23
-
24
- Items:
25
- TotalPages: !str
26
- str: "0"
27
- "@attributes": {}
28
-
29
- Request:
30
- ItemSearchRequest:
31
- DeliveryMethod: !str
32
- str: Ship
33
- "@attributes": {}
34
-
35
- Keywords: !str
36
- str: assdflasdjfasldkfjasdl
37
- "@attributes": {}
38
-
39
- MerchantId: !str
40
- str: Amazon
41
- "@attributes": {}
42
-
43
- Condition: !str
44
- str: New
45
- "@attributes": {}
46
-
47
- ResponseGroup: !str
48
- str: Small
49
- "@attributes": {}
50
-
51
- SearchIndex: !str
52
- str: Books
53
- "@attributes": {}
54
-
55
- Errors:
56
- Error:
57
- Message: !str
58
- str: We did not find any matches for your request.
59
- "@attributes": {}
60
-
61
- Code: !str
62
- str: AWS.ECommerceService.NoExactMatches
63
- "@attributes": {}
64
-
65
- IsValid: !str
66
- str: "True"
67
- "@attributes": {}
68
-
69
- TotalResults: !str
70
- str: "0"
71
- "@attributes": {}
72
-
73
- xmlns: http://webservices.amazon.com/AWSECommerceService/2005-10-05
@@ -1,72 +0,0 @@
1
- ---
2
- ItemSearchResponse:
3
- OperationRequest:
4
- Arguments:
5
- Argument:
6
- - Name: Operation
7
- Value: ItemSearch
8
- - Name: Service
9
- Value: AWSECommerceService
10
- - Name: AWSAccessKeyId
11
- Value: SECRET
12
- - Name: SearchIndex
13
- Value: Books
14
- - Name: Keywords
15
- Value: Something cool from canada
16
- RequestId: !str
17
- str: 53b485a7-6bb7-4b3f-9c6d-fa9f2f1293dc
18
- "@attributes": {}
19
- RequestProcessingTime: !str
20
- str: "0.0551560000000000"
21
- "@attributes": {}
22
- Items:
23
- TotalPages: !str
24
- str: "1"
25
- "@attributes": {}
26
- Item:
27
- ItemAttributes:
28
- Author: !str
29
- str: Christopher A. Sawyer
30
- "@attributes": {}
31
- Title: !str
32
- str: "Something cool from Canada: powersport equipment design requires flowing, edgy forms, an understanding of the role of the rider, and a multi-disciplinary ... article from: Automotive Design & Production"
33
- "@attributes": {}
34
- ProductGroup: !str
35
- str: Book
36
- "@attributes": {}
37
- Manufacturer: !str
38
- str: Thomson Gale
39
- "@attributes": {}
40
- ASIN: !str
41
- str: B000Y757NE
42
- "@attributes": {}
43
- DetailPageURL: !str
44
- str: http://www.amazon.com/Something-cool-Canada-understanding-multi-disciplinary/dp/B000Y757NE%3FSubscriptionId%3DAKIAJJES5KN2IIXQSSOA%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB000Y757NE
45
- "@attributes": {}
46
- Request:
47
- ItemSearchRequest:
48
- DeliveryMethod: !str
49
- str: Ship
50
- "@attributes": {}
51
- Keywords: !str
52
- str: Something cool from canada
53
- "@attributes": {}
54
- MerchantId: !str
55
- str: Amazon
56
- "@attributes": {}
57
- Condition: !str
58
- str: New
59
- "@attributes": {}
60
- ResponseGroup: !str
61
- str: Small
62
- "@attributes": {}
63
- SearchIndex: !str
64
- str: Books
65
- "@attributes": {}
66
- IsValid: !str
67
- str: "True"
68
- "@attributes": {}
69
- TotalResults: !str
70
- str: "1"
71
- "@attributes": {}
72
- xmlns: http://webservices.amazon.com/AWSECommerceService/2005-10-05
data/test/a2ws_test.rb DELETED
@@ -1,69 +0,0 @@
1
- require 'rubygems'
2
- gem 'thoughtbot-shoulda'
3
- require 'shoulda'
4
- require File.expand_path(File.dirname(__FILE__) + '/../lib/a2ws')
5
- include A2WS
6
- # black-box testing for generating signatures
7
- # reference:
8
- # http://docs.amazonwebservices.com/AWSECommerceService/2009-07-01/DG/index.html?rest-signature.html
9
- class A2WSTest < Test::Unit::TestCase
10
- context "Amazon Authentication" do
11
- should "occur when finding items" do
12
- AAWS.stubs(:timestamp).returns("2009-01-01T12:00:00Z")
13
- AAWS.stubs(:build_signature).returns("SIGNATURE")
14
- expected_params = has_entries(
15
- :query => has_entries(
16
- :Timestamp => "2009-01-01T12:00:00Z",
17
- :Signature => "SIGNATURE",
18
- :Version => "2009-07-01"
19
- )
20
- )
21
- AAWS.expects(:get).with("/onca/xml", expected_params).returns(AAWSCannedResponse.asin_response)
22
- AAWS.find("0316769177")
23
- end
24
-
25
- should "occur when searching items" do
26
- AAWS.stubs(:timestamp).returns("2009-01-01T12:00:00Z")
27
- AAWS.stubs(:build_signature).returns("SIGNATURE")
28
- expected_params = has_entries(
29
- :query => has_entries(
30
- :Timestamp => "2009-01-01T12:00:00Z",
31
- :Signature => "SIGNATURE",
32
- :Version => "2009-07-01"
33
- )
34
- )
35
- AAWS.expects(:get).with("/onca/xml", expected_params).returns(AAWSCannedResponse.search_response)
36
- AAWS.search(:Title => "Ruby on Rails")
37
- end
38
-
39
- should "properly generate signatures" do
40
- AAWS.stubs(:timestamp).returns("2009-01-01T12:00:00Z")
41
- AAWS.stubs(:secret_key).returns("1234567890")
42
- AAWS.stubs(:default_params).returns({ :Service => "AWSECommerceService",
43
- :AWSAccessKeyId => "00000000000000000000",
44
- :ResponseGroup => "ItemAttributes,Offers,Images,Reviews"})
45
-
46
- assert_equal "Nace+U3Az4OhN7tISqgs1vdLBHBEijWcBeCqL5xN9xg=",
47
- AAWS.sign_request({ :Operation => "ItemLookup",
48
- :ItemId => "0679722769",
49
- :Version => "2009-01-06"})[:Signature]
50
- end
51
-
52
- should "properly generate signatures with overrides" do
53
- AAWS.stubs(:base_uri).returns("http://ecs.amazonaws.co.uk")
54
- AAWS.stubs(:timestamp).returns("2009-01-01T12:00:00Z")
55
- AAWS.stubs(:secret_key).returns("1234567890")
56
- AAWS.stubs(:default_params).returns({ :Service => "AWSECommerceService",
57
- :AWSAccessKeyId => "00000000000000000000",
58
- :ResponseGroup => "ItemAttributes,Offers,Images,Reviews,Variations"})
59
-
60
- assert_equal "TuM6E5L9u/uNqOX09ET03BXVmHLVFfJIna5cxXuHxiU=",
61
- AAWS.sign_request({ :Operation => "ItemSearch",
62
- :SearchIndex => "DVD",
63
- :Sort => "salesrank",
64
- :AssociateTag => "mytag-20",
65
- :Actor => "Johnny Depp",
66
- :Version => "2009-01-01"})[:Signature]
67
- end
68
- end
69
- end