sucker 0.9.2 → 1.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/README.markdown +4 -20
  2. data/lib/sucker/request.rb +16 -9
  3. data/lib/sucker/response.rb +5 -4
  4. data/lib/sucker/version.rb +1 -1
  5. data/lib/sucker.rb +2 -4
  6. data/spec/fixtures/cassette_library/integration/errors.yml +27 -0
  7. data/spec/fixtures/cassette_library/integration/france.yml +27 -0
  8. data/spec/fixtures/cassette_library/integration/images.yml +27 -0
  9. data/spec/fixtures/cassette_library/integration/item_lookup/multiple.yml +27 -0
  10. data/spec/fixtures/cassette_library/integration/item_lookup/single.yml +27 -0
  11. data/spec/fixtures/cassette_library/integration/item_search.yml +27 -0
  12. data/spec/fixtures/cassette_library/integration/japan.yml +27 -0
  13. data/spec/fixtures/cassette_library/integration/related_items/child.yml +27 -0
  14. data/spec/fixtures/cassette_library/integration/related_items/parent.yml +27 -0
  15. data/spec/fixtures/cassette_library/integration/seller_listings_search.yml +27 -0
  16. data/spec/fixtures/cassette_library/integration/twenty_items.yml +27 -0
  17. data/spec/fixtures/cassette_library/unit/sucker/request.yml +32 -0
  18. data/spec/fixtures/cassette_library/unit/sucker/response.yml +27 -0
  19. data/spec/integration/errors_spec.rb +7 -8
  20. data/spec/integration/france_spec.rb +15 -33
  21. data/spec/integration/images_spec.rb +12 -12
  22. data/spec/integration/item_lookup_spec.rb +25 -22
  23. data/spec/integration/item_search_spec.rb +12 -8
  24. data/spec/integration/japan_spec.rb +12 -15
  25. data/spec/integration/related_items_spec.rb +21 -16
  26. data/spec/integration/seller_listing_search_spec.rb +10 -11
  27. data/spec/integration/twenty_items_in_one_request_spec.rb +20 -19
  28. data/spec/spec_helper.rb +1 -0
  29. data/spec/support/amazon.yml +2 -0
  30. data/spec/support/amazon_credentials.rb +1 -0
  31. data/spec/support/asins.rb +1 -0
  32. data/spec/support/vcr.rb +14 -0
  33. data/spec/unit/sucker/request_spec.rb +45 -33
  34. data/spec/unit/sucker/response_spec.rb +27 -24
  35. data/spec/unit/sucker_spec.rb +1 -0
  36. metadata +114 -38
  37. data/lib/sucker/stub.rb +0 -45
  38. data/spec/support/sucker.rb +0 -3
  39. data/spec/unit/sucker/stub_spec.rb +0 -68
@@ -0,0 +1,32 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://ecs.amazonaws.com:80/onca/xml?AWSAccessKeyId=key&Service=AWSECommerceService&Signature=VsapxUuUI/FxSgttnb7jz3/B+gLjUFkZbBXCp+FC5xA=&Timestamp=2010-10-14T15:45:01Z&Version=2010-09-01
6
+ body:
7
+ headers: {}
8
+
9
+ response: !ruby/struct:VCR::Response
10
+ status: !ruby/struct:VCR::ResponseStatus
11
+ code: 200
12
+ message: OK
13
+ headers:
14
+ date:
15
+ - Thu, 14 Oct 2010 15:45:01 GMT
16
+ server:
17
+ - Server
18
+ x-amz-id-1:
19
+ - 030W9VC78EDMZHG1R4ZG
20
+ x-amz-id-2:
21
+ - jMSdHZz+sSd7nv+0plj5FxB7OQIKPd/O0dlQfey+Jp0=
22
+ nncoection:
23
+ - close
24
+ - close
25
+ content-type:
26
+ - text/html; charset=ISO-8859-1
27
+ vary:
28
+ - Accept-Encoding,User-Agent
29
+ transfer-encoding:
30
+ - chunked
31
+ body: <?xml version="1.0" encoding="UTF-8"?><Errors xmlns="http://webservices.amazon.com/AWSECommerceService/2005-10-05"><Error><Code>AWS.InvalidOperationParameter</Code><Message>The Operation parameter is invalid. Please modify the Operation parameter and retry. Valid values for the Operation parameter include TagLookup, ListLookup, CartGet, SellerListingLookup, CustomerContentLookup, ItemLookup, SimilarityLookup, SellerLookup, ItemSearch, VehiclePartLookup, BrowseNodeLookup, CartModify, ListSearch, CartClear, VehiclePartSearch, CustomerContentSearch, CartCreate, TransactionLookup, VehicleSearch, SellerListingSearch, CartAdd, Help.</Message></Error></Errors>
32
+ http_version: "1.1"
@@ -0,0 +1,27 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://ecs.amazonaws.com:80/onca/xml?AWSAccessKeyId=AKIAI66X5P3HPKX56PNQ&IdType=ASIN&ItemId=0816614024,0143105825&Operation=ItemLookup&ResponseGroup=ItemAttributes,OfferFull&Service=AWSECommerceService&Signature=ziA+5DocfoZJJ17F7cK2acMy8tZdw10ipD7/UbIkjiU=&Timestamp=2010-10-14T15:45:01Z&Version=2010-09-01
6
+ body:
7
+ headers: {}
8
+
9
+ response: !ruby/struct:VCR::Response
10
+ status: !ruby/struct:VCR::ResponseStatus
11
+ code: 200
12
+ message: OK
13
+ headers:
14
+ date:
15
+ - Thu, 14 Oct 2010 15:45:01 GMT
16
+ server:
17
+ - Server
18
+ content-type:
19
+ - text/xml;charset=UTF-8
20
+ vary:
21
+ - Accept-Encoding,User-Agent
22
+ nncoection:
23
+ - close
24
+ transfer-encoding:
25
+ - chunked
26
+ body: "<?xml version=\"1.0\" ?><ItemLookupResponse xmlns=\"http://webservices.amazon.com/AWSECommerceService/2010-09-01\"><OperationRequest><RequestId>d4c160b1-e4a7-4519-9273-430f7c17136f</RequestId><Arguments><Argument Name=\"Operation\" Value=\"ItemLookup\"></Argument><Argument Name=\"Service\" Value=\"AWSECommerceService\"></Argument><Argument Name=\"Signature\" Value=\"ziA+5DocfoZJJ17F7cK2acMy8tZdw10ipD7/UbIkjiU=\"></Argument><Argument Name=\"Version\" Value=\"2010-09-01\"></Argument><Argument Name=\"ItemId\" Value=\"0816614024,0143105825\"></Argument><Argument Name=\"IdType\" Value=\"ASIN\"></Argument><Argument Name=\"AWSAccessKeyId\" Value=\"AKIAI66X5P3HPKX56PNQ\"></Argument><Argument Name=\"Timestamp\" Value=\"2010-10-14T15:45:01Z\"></Argument><Argument Name=\"ResponseGroup\" Value=\"ItemAttributes,OfferFull\"></Argument></Arguments><RequestProcessingTime>0.0769160000000000</RequestProcessingTime></OperationRequest><Items><Request><IsValid>True</IsValid><ItemLookupRequest><Condition>New</Condition><DeliveryMethod>Ship</DeliveryMethod><IdType>ASIN</IdType><MerchantId>Amazon</MerchantId><OfferPage>1</OfferPage><ItemId>0816614024</ItemId><ItemId>0143105825</ItemId><ResponseGroup>ItemAttributes</ResponseGroup><ResponseGroup>OfferFull</ResponseGroup><ReviewPage>1</ReviewPage><ReviewSort>-SubmissionDate</ReviewSort><VariationPage>All</VariationPage></ItemLookupRequest></Request><Item><ASIN>0816614024</ASIN><DetailPageURL>http://www.amazon.com/Thousand-Plateaus-Capitalism-Schizophrenia/dp/0816614024%3FSubscriptionId%3DAKIAI66X5P3HPKX56PNQ%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0816614024</DetailPageURL><ItemLinks><ItemLink><Description>Technical Details</Description><URL>http://www.amazon.com/Thousand-Plateaus-Capitalism-Schizophrenia/dp/tech-data/0816614024%3FSubscriptionId%3DAKIAI66X5P3HPKX56PNQ%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0816614024</URL></ItemLink><ItemLink><Description>Add To Baby Registry</Description><URL>http://www.amazon.com/gp/registry/baby/add-item.html%3Fasin.0%3D0816614024%26SubscriptionId%3DAKIAI66X5P3HPKX56PNQ%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0816614024</URL></ItemLink><ItemLink><Description>Add To Wedding Registry</Description><URL>http://www.amazon.com/gp/registry/wedding/add-item.html%3Fasin.0%3D0816614024%26SubscriptionId%3DAKIAI66X5P3HPKX56PNQ%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0816614024</URL></ItemLink><ItemLink><Description>Add To Wishlist</Description><URL>http://www.amazon.com/gp/registry/wishlist/add-item.html%3Fasin.0%3D0816614024%26SubscriptionId%3DAKIAI66X5P3HPKX56PNQ%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0816614024</URL></ItemLink><ItemLink><Description>Tell A Friend</Description><URL>http://www.amazon.com/gp/pdp/taf/0816614024%3FSubscriptionId%3DAKIAI66X5P3HPKX56PNQ%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0816614024</URL></ItemLink><ItemLink><Description>All Customer Reviews</Description><URL>http://www.amazon.com/review/product/0816614024%3FSubscriptionId%3DAKIAI66X5P3HPKX56PNQ%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0816614024</URL></ItemLink><ItemLink><Description>All Offers</Description><URL>http://www.amazon.com/gp/offer-listing/0816614024%3FSubscriptionId%3DAKIAI66X5P3HPKX56PNQ%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0816614024</URL></ItemLink></ItemLinks><ItemAttributes><Author>Gilles Deleuze</Author><Author>Felix Guattari</Author><Author>Brian Massumi</Author><Binding>Paperback</Binding><DeweyDecimalNumber>194</DeweyDecimalNumber><EAN>9780816614028</EAN><ISBN>0816614024</ISBN><IsEligibleForTradeIn>1</IsEligibleForTradeIn><Label>University of Minnesota Press</Label><Languages><Language><Name>English</Name><Type>Unknown</Type></Language><Language><Name>English</Name><Type>Original Language</Type></Language><Language><Name>English</Name><Type>Published</Type></Language></Languages><ListPrice><Amount>2500</Amount><CurrencyCode>USD</CurrencyCode><FormattedPrice>$25.00</FormattedPrice></ListPrice><Manufacturer>University of Minnesota Press</Manufacturer><NumberOfItems>1</NumberOfItems><NumberOfPages>610</NumberOfPages><PackageDimensions><Height Units=\"hundredths-inches\">135</Height><Length Units=\"hundredths-inches\">899</Length><Weight Units=\"hundredths-pounds\">183</Weight><Width Units=\"hundredths-inches\">608</Width></PackageDimensions><ProductGroup>Book</ProductGroup><ProductTypeName>ABIS_BOOK</ProductTypeName><PublicationDate>1987-12</PublicationDate><Publisher>University of Minnesota Press</Publisher><Studio>University of Minnesota Press</Studio><Title>A Thousand Plateaus: Capitalism and Schizophrenia</Title><TradeInValue><Amount>722</Amount><CurrencyCode>USD</CurrencyCode><FormattedPrice>$7.22</FormattedPrice></TradeInValue></ItemAttributes><OfferSummary><LowestNewPrice><Amount>1800</Amount><CurrencyCode>USD</CurrencyCode><FormattedPrice>$18.00</FormattedPrice></LowestNewPrice><LowestUsedPrice><Amount>1625</Amount><CurrencyCode>USD</CurrencyCode><FormattedPrice>$16.25</FormattedPrice></LowestUsedPrice><LowestCollectiblePrice><Amount>5000</Amount><CurrencyCode>USD</CurrencyCode><FormattedPrice>$50.00</FormattedPrice></LowestCollectiblePrice><TotalNew>27</TotalNew><TotalUsed>21</TotalUsed><TotalCollectible>1</TotalCollectible><TotalRefurbished>0</TotalRefurbished></OfferSummary><Offers><TotalOffers>1</TotalOffers><TotalOfferPages>1</TotalOfferPages><Offer><Merchant><MerchantId>ATVPDKIKX0DER</MerchantId><Name>Amazon.com</Name><GlancePage>http://www.amazon.com/gp/help/seller/home.html?seller=ATVPDKIKX0DER</GlancePage><AverageFeedbackRating>0.0</AverageFeedbackRating><TotalFeedback>0</TotalFeedback></Merchant><OfferAttributes><Condition>New</Condition><SubCondition>new</SubCondition></OfferAttributes><OfferListing><OfferListingId>N5LpjKFwvGMBqooPVSe3Y7ylW3EXWdCjzGpB5mJL%2F6hy4XY%2FvS6GJlzA1l2I6ZN39%2BrwiaNX2MVdG1Dqf1E1rQ%3D%3D</OfferListingId><Price><Amount>1800</Amount><CurrencyCode>USD</CurrencyCode><FormattedPrice>$18.00</FormattedPrice></Price><AmountSaved><Amount>700</Amount><CurrencyCode>USD</CurrencyCode><FormattedPrice>$7.00</FormattedPrice></AmountSaved><PercentageSaved>28</PercentageSaved><Availability>Usually ships in 24 hours</Availability><AvailabilityAttributes><AvailabilityType>now</AvailabilityType><MinimumHours>0</MinimumHours><MaximumHours>0</MaximumHours></AvailabilityAttributes><Quantity>-1</Quantity><IsEligibleForSuperSaverShipping>1</IsEligibleForSuperSaverShipping><IsFulfilledByAmazon>1</IsFulfilledByAmazon></OfferListing></Offer></Offers></Item><Item><ASIN>0143105825</ASIN><DetailPageURL>http://www.amazon.com/Anti-Oedipus-Capitalism-Schizophrenia-Penguin-Classics/dp/0143105825%3FSubscriptionId%3DAKIAI66X5P3HPKX56PNQ%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0143105825</DetailPageURL><ItemLinks><ItemLink><Description>Technical Details</Description><URL>http://www.amazon.com/Anti-Oedipus-Capitalism-Schizophrenia-Penguin-Classics/dp/tech-data/0143105825%3FSubscriptionId%3DAKIAI66X5P3HPKX56PNQ%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0143105825</URL></ItemLink><ItemLink><Description>Add To Baby Registry</Description><URL>http://www.amazon.com/gp/registry/baby/add-item.html%3Fasin.0%3D0143105825%26SubscriptionId%3DAKIAI66X5P3HPKX56PNQ%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0143105825</URL></ItemLink><ItemLink><Description>Add To Wedding Registry</Description><URL>http://www.amazon.com/gp/registry/wedding/add-item.html%3Fasin.0%3D0143105825%26SubscriptionId%3DAKIAI66X5P3HPKX56PNQ%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0143105825</URL></ItemLink><ItemLink><Description>Add To Wishlist</Description><URL>http://www.amazon.com/gp/registry/wishlist/add-item.html%3Fasin.0%3D0143105825%26SubscriptionId%3DAKIAI66X5P3HPKX56PNQ%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0143105825</URL></ItemLink><ItemLink><Description>Tell A Friend</Description><URL>http://www.amazon.com/gp/pdp/taf/0143105825%3FSubscriptionId%3DAKIAI66X5P3HPKX56PNQ%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0143105825</URL></ItemLink><ItemLink><Description>All Customer Reviews</Description><URL>http://www.amazon.com/review/product/0143105825%3FSubscriptionId%3DAKIAI66X5P3HPKX56PNQ%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0143105825</URL></ItemLink><ItemLink><Description>All Offers</Description><URL>http://www.amazon.com/gp/offer-listing/0143105825%3FSubscriptionId%3DAKIAI66X5P3HPKX56PNQ%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0143105825</URL></ItemLink></ItemLinks><ItemAttributes><Author>Gilles Deleuze</Author><Author>Felix Guattari</Author><Binding>Paperback</Binding><Creator Role=\"Translator\">Robert Hurley</Creator><Creator Role=\"Translator\">Mark Seem</Creator><Creator Role=\"Introduction\">Mark Seem</Creator><Creator Role=\"Translator\">Helen Lane</Creator><Creator Role=\"Preface\">Michel Foucault</Creator><DeweyDecimalNumber>616</DeweyDecimalNumber><EAN>9780143105824</EAN><Feature>ISBN13: 9780143105824</Feature><Feature>Condition: New</Feature><Feature>Notes: BUY WITH CONFIDENCE, Over one million books sold! 98% Positive feedback. Compare our books, prices and service to the competition. 100% Satisfaction Guaranteed</Feature><ISBN>0143105825</ISBN><IsEligibleForTradeIn>1</IsEligibleForTradeIn><Label>Penguin Classics</Label><Languages><Language><Name>English</Name><Type>Unknown</Type></Language><Language><Name>English</Name><Type>Original Language</Type></Language><Language><Name>English</Name><Type>Published</Type></Language></Languages><ListPrice><Amount>2200</Amount><CurrencyCode>USD</CurrencyCode><FormattedPrice>$22.00</FormattedPrice></ListPrice><Manufacturer>Penguin Classics</Manufacturer><NumberOfItems>1</NumberOfItems><NumberOfPages>432</NumberOfPages><PackageDimensions><Height Units=\"hundredths-inches\">118</Height><Length Units=\"hundredths-inches\">819</Length><Weight Units=\"hundredths-pounds\">79</Weight><Width Units=\"hundredths-inches\">543</Width></PackageDimensions><ProductGroup>Book</ProductGroup><ProductTypeName>ABIS_BOOK</ProductTypeName><PublicationDate>2009-05-26</PublicationDate><Publisher>Penguin Classics</Publisher><Studio>Penguin Classics</Studio><Title>Anti-Oedipus: Capitalism and Schizophrenia (Penguin Classics)</Title><TradeInValue><Amount>425</Amount><CurrencyCode>USD</CurrencyCode><FormattedPrice>$4.25</FormattedPrice></TradeInValue></ItemAttributes><OfferSummary><LowestNewPrice><Amount>1191</Amount><CurrencyCode>USD</CurrencyCode><FormattedPrice>$11.91</FormattedPrice></LowestNewPrice><LowestUsedPrice><Amount>1192</Amount><CurrencyCode>USD</CurrencyCode><FormattedPrice>$11.92</FormattedPrice></LowestUsedPrice><LowestCollectiblePrice><Amount>15000</Amount><CurrencyCode>USD</CurrencyCode><FormattedPrice>$150.00</FormattedPrice></LowestCollectiblePrice><TotalNew>30</TotalNew><TotalUsed>12</TotalUsed><TotalCollectible>1</TotalCollectible><TotalRefurbished>0</TotalRefurbished></OfferSummary><Offers><TotalOffers>1</TotalOffers><TotalOfferPages>1</TotalOfferPages><Offer><Merchant><MerchantId>ATVPDKIKX0DER</MerchantId><Name>Amazon.com</Name><GlancePage>http://www.amazon.com/gp/help/seller/home.html?seller=ATVPDKIKX0DER</GlancePage><AverageFeedbackRating>0.0</AverageFeedbackRating><TotalFeedback>0</TotalFeedback></Merchant><OfferAttributes><Condition>New</Condition><SubCondition>new</SubCondition></OfferAttributes><OfferListing><OfferListingId>YLDlhU0fIlENaSAeEkFqPpWhGK%2F%2FhvSGMbxsaevQpNLcAuNX0gtUd1QhrMaY3mO05v047B2VYQQCCP%2BCvrni2g%3D%3D</OfferListingId><Price><Amount>1496</Amount><CurrencyCode>USD</CurrencyCode><FormattedPrice>$14.96</FormattedPrice></Price><AmountSaved><Amount>704</Amount><CurrencyCode>USD</CurrencyCode><FormattedPrice>$7.04</FormattedPrice></AmountSaved><PercentageSaved>32</PercentageSaved><Availability>Usually ships in 24 hours</Availability><AvailabilityAttributes><AvailabilityType>now</AvailabilityType><MinimumHours>0</MinimumHours><MaximumHours>0</MaximumHours></AvailabilityAttributes><Quantity>-1</Quantity><IsEligibleForSuperSaverShipping>1</IsEligibleForSuperSaverShipping><IsFulfilledByAmazon>1</IsFulfilledByAmazon></OfferListing></Offer></Offers></Item></Items></ItemLookupResponse>"
27
+ http_version: "1.1"
@@ -1,15 +1,16 @@
1
+ # encoding: utf-8
1
2
  require "spec_helper"
2
3
 
3
4
  module Sucker
4
5
  describe "Errors" do
5
- before do
6
+ use_vcr_cassette "integration/errors", :record => :new_episodes
7
+
8
+ let(:response) do
6
9
  worker = Sucker.new(
7
10
  :locale => "us",
8
11
  :key => amazon["key"],
9
12
  :secret => amazon["secret"])
10
13
 
11
- # worker.curl { |curl| curl.verbose = true }
12
-
13
14
  worker << {
14
15
  "Operation" => "ItemLookup",
15
16
  "IdType" => "ASIN",
@@ -17,21 +18,19 @@ module Sucker
17
18
  "MerchantId" => "All",
18
19
  "ResponseGroup" => ["ItemAttributes"] }
19
20
 
20
- Sucker.stub(worker)
21
-
22
21
  # The first ASIN exists, the latter two do not.
23
22
  worker << { "ItemId" => ["0816614024", "0007218095", "0007218176"] }
24
- @response = worker.get
23
+ worker.get
25
24
  end
26
25
 
27
26
  it "returns two errors" do
28
- errors = @response.node("Error")
27
+ errors = response.node("Error")
29
28
  errors.size.should eql 2
30
29
  errors.first["Message"].should include "not a valid value"
31
30
  end
32
31
 
33
32
  it "returns one item" do
34
- items = @response.node("ItemAttributes")
33
+ items = response.node("ItemAttributes")
35
34
  items.size.should eql 1
36
35
  end
37
36
  end
@@ -2,51 +2,33 @@
2
2
  require "spec_helper"
3
3
 
4
4
  module Sucker
5
- describe "Un lookup français" do
6
- before do
7
- @worker = Sucker.new(
5
+ describe "A French lookup" do
6
+ use_vcr_cassette "integration/france", :record => :new_episodes
7
+
8
+ let(:item) do
9
+ worker = Sucker.new(
8
10
  :locale => "fr",
9
11
  :key => amazon["key"],
10
12
  :secret => amazon["secret"])
11
13
 
12
- # @worker.curl { |curl| curl.verbose = true }
13
-
14
- @worker << {
14
+ worker << {
15
15
  "Operation" => "ItemLookup",
16
16
  "IdType" => "ASIN",
17
17
  "Condition" => "All",
18
18
  "MerchantId" => "All",
19
- "ResponseGroup" => ["ItemAttributes", "OfferFull"] }
20
-
21
- Sucker.stub(@worker)
19
+ "ResponseGroup" => ["ItemAttributes", "OfferFull"],
20
+ "ItemId" => "2070119874" }
21
+ worker.get.node("Item").first
22
22
  end
23
23
 
24
- context "single item" do
25
- before do
26
- @worker << { "ItemId" => "2070119874" }
27
- @item = @worker.get.node("Item").first
28
- end
29
-
30
- it "returns an item" do
31
- @item.should be_an_instance_of Hash
32
- end
33
-
34
- it "includes requested response groups" do
35
- @item["ItemAttributes"].should be_an_instance_of Hash
36
- @item["Offers"].should be_an_instance_of Hash
37
- end
24
+ it "returns an item" do
25
+ item.should be_an_instance_of Hash
38
26
  end
39
27
 
40
- context "multiple items" do
41
- before do
42
- @worker << { "ItemId" => ["0816614024", "0143105825"] }
43
- @items = @worker.get.node("Item")
44
- end
45
-
46
- it "returns two items" do
47
- @items.should be_an_instance_of Array
48
- @items.size.should eql 2
49
- end
28
+ it "includes requested response groups" do
29
+ item["ItemAttributes"].should be_an_instance_of Hash
30
+ item["Offers"].should be_an_instance_of Hash
31
+ item["ItemAttributes"]["Binding"].should eql "Broché"
50
32
  end
51
33
  end
52
34
  end
@@ -1,34 +1,34 @@
1
+ # encoding: utf-8
1
2
  require "spec_helper"
2
3
 
3
4
  module Sucker
4
5
  describe "Images response group" do
5
- before do
6
- @worker = Sucker.new(
6
+ use_vcr_cassette "integration/images", :record => :new_episodes
7
+
8
+ let(:item) do
9
+ worker = Sucker.new(
7
10
  :locale => "us",
8
11
  :key => amazon["key"],
9
12
  :secret => amazon["secret"])
10
13
 
11
- @worker << {
14
+ worker << {
12
15
  "Operation" => "ItemLookup",
13
16
  "IdType" => "ASIN",
14
- "ResponseGroup" => "Images" }
15
-
16
- Sucker.stub(@worker)
17
-
18
- @worker << { "ItemId" => "0816614024" }
19
- @item = @worker.get.node("Item").first
17
+ "ResponseGroup" => "Images",
18
+ "ItemId" => "0816614024" }
19
+ worker.get.node("Item").first
20
20
  end
21
21
 
22
22
  it "has an ASIN" do
23
- @item["ASIN"].should eql "0816614024"
23
+ item["ASIN"].should eql "0816614024"
24
24
  end
25
25
 
26
26
  it "has a large image URL" do
27
- @item["LargeImage"]["URL"].should match /^http.*jpg$/
27
+ item["LargeImage"]["URL"].should match /^http.*jpg$/
28
28
  end
29
29
 
30
30
  it "has an image set" do
31
- @item["ImageSets"]["ImageSet"].should be_an_instance_of Hash
31
+ item["ImageSets"]["ImageSet"].should be_an_instance_of Hash
32
32
  end
33
33
  end
34
34
  end
@@ -1,60 +1,63 @@
1
+ # encoding: utf-8
1
2
  require "spec_helper"
2
3
 
3
4
  module Sucker
4
5
  describe "Item lookup" do
5
- before do
6
- @worker = Sucker.new(
6
+ let(:worker) do
7
+ worker = Sucker.new(
7
8
  :locale => "us",
8
9
  :key => amazon["key"],
9
10
  :secret => amazon["secret"])
10
11
 
11
- # @worker.curl { |curl| curl.verbose = true }
12
-
13
- @worker << {
12
+ worker << {
14
13
  "Operation" => "ItemLookup",
15
14
  "IdType" => "ASIN",
16
15
  "Condition" => "All",
17
16
  "MerchantId" => "All",
18
17
  "ResponseGroup" => ["ItemAttributes", "OfferFull"] }
19
-
20
- Sucker.stub(@worker)
18
+ worker
21
19
  end
22
20
 
23
21
  context "single item" do
24
- before do
25
- @worker << { "ItemId" => "0816614024" }
26
- @response = @worker.get
27
- @item = @response.node("Item").first
22
+ use_vcr_cassette "integration/item_lookup/single", :record => :new_episodes
23
+
24
+ let(:response) do
25
+ worker << { "ItemId" => "0816614024" }
26
+ worker.get
28
27
  end
29
28
 
29
+ let(:item) { response.node("Item").first }
30
+
30
31
  it "returns an item" do
31
- @item.should be_an_instance_of Hash
32
+ item.should be_an_instance_of Hash
32
33
  end
33
34
 
34
35
  it "includes an ASIN string" do
35
- @item["ASIN"].should eql "0816614024"
36
+ item["ASIN"].should eql "0816614024"
36
37
  end
37
38
 
38
39
  it "includes requested response groups" do
39
- @item["ItemAttributes"].should be_an_instance_of Hash
40
- @item["Offers"].should be_an_instance_of Hash
40
+ item["ItemAttributes"].should be_an_instance_of Hash
41
+ item["Offers"].should be_an_instance_of Hash
41
42
  end
42
43
 
43
44
  it "returns no errors" do
44
- @response.node("Error").should be_empty
45
- @response.node("Error").should be_an_instance_of Array
45
+ response.node("Error").should be_empty
46
+ response.node("Error").should be_an_instance_of Array
46
47
  end
47
48
  end
48
49
 
49
50
  context "multiple items" do
50
- before do
51
- @worker << { "ItemId" => ["0816614024", "0143105825"] }
52
- @items = @worker.get.node("Item")
51
+ use_vcr_cassette "integration/item_lookup/multiple", :record => :new_episodes
52
+
53
+ let(:items) do
54
+ worker << { "ItemId" => ["0816614024", "0143105825"] }
55
+ worker.get.node("Item")
53
56
  end
54
57
 
55
58
  it "returns two items" do
56
- @items.should be_an_instance_of Array
57
- @items.size.should eql 2
59
+ items.should be_an_instance_of Array
60
+ items.size.should eql 2
58
61
  end
59
62
  end
60
63
  end
@@ -1,33 +1,37 @@
1
+ # encoding: utf-8
2
+
1
3
  # http://github.com/papercavalier/sucker/issues#issue/2
2
4
 
3
5
  require "spec_helper"
4
6
 
5
7
  module Sucker
6
8
  describe "Item Search" do
7
- before do
8
- @worker = Sucker.new(
9
+ use_vcr_cassette "integration/item_search", :record => :new_episodes
10
+
11
+ let(:worker) do
12
+ worker = Sucker.new(
9
13
  :locale => "us",
10
14
  :key => amazon["key"],
11
15
  :secret => amazon["secret"])
12
16
 
13
- @worker << {
17
+ worker << {
14
18
  "Operation" => "ItemSearch",
15
19
  "SearchIndex" => "Books",
16
20
  "Author" => "Orwell" }
17
-
18
- #Sucker.stub(@worker)
21
+ worker
19
22
  end
20
23
 
21
24
  it "works for Orwell" do
22
- @worker.get.should be_valid
25
+ worker.get.should be_valid
23
26
  end
24
27
 
25
28
  it "works for George Orwell, too" do
26
- @worker << {
29
+ worker << {
27
30
  "Operation" => "ItemSearch",
28
31
  "SearchIndex" => "Books",
29
32
  "Author" => "George Orwell" }
30
- response = @worker.get
33
+
34
+ response = worker.get
31
35
  response.should be_valid
32
36
  response.node("TotalPages").first.should be_an_instance_of String
33
37
  end
@@ -1,30 +1,27 @@
1
+ # encoding: utf-8
1
2
  require "spec_helper"
2
3
 
3
4
  module Sucker
4
5
  describe "A Japanese request" do
5
- before do
6
- @worker = Sucker.new(
6
+ use_vcr_cassette "integration/japan", :record => :new_episodes
7
+
8
+ let(:item) do
9
+ worker = Sucker.new(
7
10
  :locale => "jp",
8
11
  :key => amazon["key"],
9
12
  :secret => amazon["secret"])
10
13
 
11
- @worker << {
14
+ worker << {
12
15
  "Operation" => "ItemLookup",
13
16
  "IdType" => "ASIN",
14
- "ResponseGroup" => ["ItemAttributes", "OfferFull"] }
15
-
16
- Sucker.stub(@worker)
17
+ "ResponseGroup" => ["ItemAttributes", "OfferFull"],
18
+ "ItemId" => "482224816X" }
19
+ worker.get.node("Item").first
17
20
  end
18
21
 
19
- context "single item" do
20
- before do
21
- @worker << { "ItemId" => "482224816X" }
22
- @item = @worker.get.node("Item").first
23
- end
24
-
25
- it "returns an array of items" do
26
- @item.should be_an_instance_of Hash
27
- end
22
+ it "returns an array of items" do
23
+ item.should be_an_instance_of Hash
24
+ item["ItemAttributes"]["Binding"].should eql "単行本(ソフトカバー)"
28
25
  end
29
26
  end
30
27
  end
@@ -1,37 +1,42 @@
1
+ # encoding: utf-8
1
2
  require "spec_helper"
2
3
 
3
4
  module Sucker
4
5
  describe "Related items" do
5
- before do
6
- @worker = Sucker.new(
6
+ let(:worker) do
7
+ worker = Sucker.new(
7
8
  :locale => "us",
8
9
  :key => amazon["key"],
9
10
  :secret => amazon["secret"])
10
11
 
11
- @worker << {
12
+ worker << {
12
13
  "Operation" => "ItemLookup",
13
14
  "IdType" => "ASIN",
14
15
  "ResponseGroup" => ["RelatedItems"],
15
16
  "RelationshipType" => "AuthorityTitle" }
16
17
 
17
- Sucker.stub(@worker)
18
+ worker
18
19
  end
19
20
 
20
- it "finds authority title and related items" do
21
- @worker << { "ItemId" => "0415246334" }
22
- response = @worker.get
23
- response.node("RelatedItem").size.should eql 1
24
- parent_asin = response.node("RelatedItem").first["Item"]["ASIN"]
21
+ context "Child" do
22
+ use_vcr_cassette "integration/related_items/child", :record => :new_episodes
25
23
 
26
- @worker << { "ItemId" => parent_asin }
27
- response = @worker.get
28
- response.node("RelatedItem").size.should > 1
24
+ it "finds parent and related items" do
25
+ worker << { "ItemId" => "0415246334" }
26
+ response = worker.get
27
+ response.node("RelatedItem").size.should eql 1
28
+ parent_asin = response.node("RelatedItem").first["Item"]["ASIN"]
29
+ end
29
30
  end
30
31
 
31
- it "foos items with no related items" do
32
- @worker << { "ItemId" => "0804819491" }
33
- response = @worker.get
34
- response.node("RelatedItem").size.should eql 0
32
+ context "Parent" do
33
+ use_vcr_cassette "integration/related_items/parent", :record => :new_episodes
34
+
35
+ it "finds related items" do
36
+ worker << { "ItemId" => "B000ASPUES" }
37
+ response = worker.get
38
+ response.node("RelatedItem").size.should > 1
39
+ end
35
40
  end
36
41
  end
37
42
  end
@@ -1,31 +1,30 @@
1
+ # encoding: utf-8
1
2
  require "spec_helper"
2
3
 
3
4
  module Sucker
4
5
  describe "Seller listing search" do
5
- before do
6
- @worker = Sucker.new(
6
+ use_vcr_cassette "integration/seller_listings_search", :record => :new_episodes
7
+
8
+ let(:listings) do
9
+ worker = Sucker.new(
7
10
  :locale => "us",
8
11
  :key => amazon["key"],
9
12
  :secret => amazon["secret"])
10
13
 
11
- # @worker.curl { |curl| curl.verbose = true }
12
-
13
- @worker << {
14
+ worker << {
14
15
  "Operation" => "SellerListingSearch",
15
16
  "SellerId" => "A31N271NVIORU3" }
16
17
 
17
- Sucker.stub(@worker)
18
-
19
- @listings = @worker.get.node("SellerListings").first
18
+ worker.get.node("SellerListings").first
20
19
  end
21
20
 
22
21
  it "returns page count" do
23
- @listings["TotalPages"].to_i.should be > 0
22
+ listings["TotalPages"].to_i.should be > 0
24
23
  end
25
24
 
26
25
  it "returns listings" do
27
- @listings["SellerListing"].size.should be > 0
28
- @listings["SellerListing"].first.has_key?("Price").should be_true
26
+ listings["SellerListing"].size.should be > 0
27
+ listings["SellerListing"].first.has_key?("Price").should be_true
29
28
  end
30
29
  end
31
30
  end
@@ -1,18 +1,26 @@
1
- # A word of caution: It seems Amazon will deprecate multiple requests
2
- # on October 15 2010. We're petitioning them not to.
3
-
1
+ # encoding: utf-8
4
2
  require "spec_helper"
5
3
 
6
4
  module Sucker
7
5
  describe "Twenty items in one request" do
8
- before do
9
- @worker = Sucker.new(
6
+ use_vcr_cassette "integration/twenty_items", :record => :new_episodes
7
+
8
+ let(:asins) do
9
+ %w{
10
+ 0816614024 0143105825 0485113600 0816616779 0942299078
11
+ 0816614008 144006654X 0486400360 0486417670 087220474X
12
+ 0486454398 0268018359 1604246014 184467598X 0312427182
13
+ 1844674282 0745640974 0745646441 0826489540 1844672972 }
14
+ end
15
+
16
+ let(:items) do
17
+ worker = Sucker.new(
10
18
  :locale => "us",
11
19
  :key => amazon["key"],
12
20
  :secret => amazon["secret"])
13
21
 
14
22
  # Prep worker
15
- @worker << {
23
+ worker << {
16
24
  "Operation" => "ItemLookup",
17
25
  "ItemLookup.Shared.IdType" => "ASIN",
18
26
  "ItemLookup.Shared.Condition" => "All",
@@ -20,23 +28,16 @@ module Sucker
20
28
  "ItemLookup.Shared.ResponseGroup" => "OfferFull" }
21
29
 
22
30
  # Push twenty ASINs to worker
23
- @asins = %w{
24
- 0816614024 0143105825 0485113600 0816616779 0942299078
25
- 0816614008 144006654X 0486400360 0486417670 087220474X
26
- 0486454398 0268018359 1604246014 184467598X 0312427182
27
- 1844674282 0745640974 0745646441 0826489540 1844672972 }
28
- @worker << {
29
- "ItemLookup.1.ItemId" => @asins[0, 10],
30
- "ItemLookup.2.ItemId" => @asins[10, 10] }
31
-
32
- Sucker.stub(@worker)
31
+ worker << {
32
+ "ItemLookup.1.ItemId" => asins[0, 10],
33
+ "ItemLookup.2.ItemId" => asins[10, 10] }
33
34
 
34
- @items = @worker.get.node("Item")
35
+ worker.get.node("Item")
35
36
  end
36
37
 
37
38
  it "returns 20 items" do
38
- @items.count.should eql 20
39
- @items.map { |item| item["ASIN"] }.should eql @asins
39
+ items.count.should eql 20
40
+ items.map { |item| item["ASIN"] }.should eql asins
40
41
  end
41
42
  end
42
43
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require "rubygems"
2
3
  require "bundler/setup"
3
4
  require "rspec"
@@ -0,0 +1,2 @@
1
+ key: AKIAI66X5P3HPKX56PNQ
2
+ secret: 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
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  def amazon
2
3
  @amazon ||= YAML::load_file(File.dirname(__FILE__) + "/amazon.yml")
3
4
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  def asins_fixture
2
3
  File.new(File.expand_path("../../fixtures/asins.txt", __FILE__), "r").map { |line| line.chomp }
3
4
  end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+ require 'vcr'
3
+
4
+ VCR.config do |c|
5
+ c.cassette_library_dir = File.dirname(__FILE__) + '/../fixtures/cassette_library'
6
+ c.http_stubbing_library = :webmock
7
+ c.default_cassette_options = {
8
+ :record => :new_episodes,
9
+ :match_requests_on => [:host] }
10
+ end
11
+
12
+ RSpec.configure do |config|
13
+ config.extend VCR::RSpec::Macros
14
+ end