amazon_seller_central 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/README.md +42 -5
  2. data/VERSION +1 -1
  3. data/amazon_seller_central.gemspec +22 -4
  4. data/lib/amazon_seller_central/feedback_page.rb +1 -13
  5. data/lib/amazon_seller_central/inventory.rb +23 -0
  6. data/lib/amazon_seller_central/inventory_page.rb +126 -0
  7. data/lib/amazon_seller_central/listing.rb +42 -0
  8. data/lib/amazon_seller_central/listing_set.rb +13 -0
  9. data/lib/amazon_seller_central/mechanizer.rb +10 -5
  10. data/lib/amazon_seller_central/page.rb +26 -0
  11. data/lib/amazon_seller_central.rb +5 -0
  12. data/spec/lib/feedback_page_spec.rb +5 -25
  13. data/spec/lib/inventory_page_spec.rb +120 -0
  14. data/spec/lib/inventory_spec.rb +26 -0
  15. data/spec/lib/listing_set_spec.rb +39 -0
  16. data/spec/lib/listing_spec.rb +78 -0
  17. data/spec/lib/mechanizer_spec.rb +24 -19
  18. data/spec/spec_helper.rb +3 -0
  19. data/spec/support/page_body_regexen.rb +7 -0
  20. data/spec/support/page_examples.rb +23 -0
  21. data/spec/support/sample_pages/Feedback Manager.html +1 -1
  22. data/spec/support/sample_pages/another_listings_page.html +12299 -0
  23. data/spec/support/sample_pages/listings_last_page.html +3345 -0
  24. data/spec/support/sample_pages/listings_page_1.html +12937 -0
  25. data/spec/support/sample_pages/listings_page_2.html +12970 -0
  26. data/spec/support/sample_pages/update_inventory_result_from_last_page.html +3345 -0
  27. data/spec/support/sample_pages/update_inventory_result_from_page_1.html +12939 -0
  28. data/spec/support/sample_pages/update_inventory_result_from_page_2.html +11274 -0
  29. data/spec/support/sample_pages.rb +25 -12
  30. metadata +82 -64
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "ListingSet" do
4
+ before :all do
5
+ @listing_set = AmazonSellerCentral::Inventory.load_first_page.listings
6
+ end
7
+
8
+ it "is an enumerable" do
9
+ @listing_set.should be_kind_of(Enumerable)
10
+ end
11
+
12
+ it "allows find by sku" do
13
+ listing = @listing_set.find("PR27880-11")
14
+ listing.sku.should == "PR27880-11"
15
+ listing.asin.should == "B003962DXE"
16
+ end
17
+
18
+ it "allows find by asin" do
19
+ listings = @listing_set.find("B0019MU9C2")
20
+ listings.should be_kind_of(Enumerable)
21
+ listings.first.sku.should == "PR30122-11"
22
+ listings.first.asin.should == "B0019MU9C2"
23
+ end
24
+
25
+ # it "allows where by quantity" do
26
+ # pending "When I need this, just thoughts for now"
27
+ # @listing_set.where(:quantity => 1)
28
+ # end
29
+
30
+ # it "allows where by price" do
31
+ # pending "When I need this, just thoughts for now"
32
+ # @listing_set.where(:price => 75.79)
33
+ # end
34
+
35
+ # it "allows where with gt, lt" do
36
+ # pending "When I need this, just thoughts for now"
37
+ # @listing_set.where(:price.gt => 10, :price.lt => 40)
38
+ # end
39
+ end
@@ -0,0 +1,78 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Listing" do
4
+ before :all do
5
+ @listing = AmazonSellerCentral::Listing.new
6
+ end
7
+ %w{sku asin product_name created_at quantity condition price_cents low_price_cents status}.each do |expected_attribute|
8
+ it "Has an attribute \"#{expected_attribute}\"" do
9
+ @listing.send("#{expected_attribute}=", 31313)
10
+ @listing.send(expected_attribute).should == 31313
11
+ end
12
+ end
13
+
14
+ it "knows if a string is an asin" do
15
+ AmazonSellerCentral::Listing.is_asin?("1234").should be_false
16
+ AmazonSellerCentral::Listing.is_asin?("B003962DXE").should be_true
17
+ end
18
+
19
+ it "accepts qty as an alias for quantity" do
20
+ @listing.quantity = 12
21
+ @listing.qty.should == 12
22
+ @listing.qty = 50
23
+ @listing.quantity.should == 50
24
+ end
25
+
26
+ it "accepts your_price as an alias for price" do
27
+ @listing.price = 12
28
+ @listing.your_price.should == 12
29
+ @listing.your_price = 50
30
+ @listing.price.should == 50
31
+ end
32
+
33
+ it "accepts product as an alias for product_name" do
34
+ @listing.product_name = 12
35
+ @listing.product.should == 12
36
+ @listing.product = 50
37
+ @listing.product_name.should == 50
38
+ end
39
+
40
+ it "returns dollars for price" do
41
+ @listing.price_cents = 1252
42
+ @listing.price.should == 12.52
43
+ end
44
+
45
+ it "accepts dollars for price" do
46
+ @listing.price = 52.25
47
+ @listing.price_cents.should == 5225
48
+ end
49
+
50
+ it "rounds to the nearest cent when accepting dollars for price" do
51
+ @listing.price = 52.258
52
+ @listing.price_cents.should == 5226
53
+ @listing.price = 52.251
54
+ @listing.price_cents.should == 5225
55
+ end
56
+
57
+ it "returns dollars or true for low_price" do
58
+ @listing.low_price_cents = 9621
59
+ @listing.low_price.should == 96.21
60
+ @listing.low_price_cents = true
61
+ @listing.low_price.should == true
62
+ end
63
+
64
+ it "accepts nil for price" do
65
+ @listing.price = nil
66
+ @listing.price.should be_nil
67
+ end
68
+
69
+ it "accepts nil for low_price" do
70
+ @listing.low_price = nil
71
+ @listing.low_price.should be_nil
72
+ end
73
+
74
+ it "is a little helpful ;)" do
75
+ #STDOUT.should_receive(:puts).with(/InventoryPage#apply_listings/)
76
+ @listing.save.should be_false
77
+ end
78
+ end
@@ -1,39 +1,35 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Mechanizer" do
4
- before :all do
5
- mock_seller_central_page_results!
6
- end
7
-
8
- it "retains access to the last page loaded" do
9
- mech = AmazonSellerCentral.mechanizer
10
- mech.login_to_seller_central
11
- mech.last_page.body.should =~ /Welcome! You are signed in as/
12
- end
4
+ it "retains access to the last page loaded" do
5
+ mech = AmazonSellerCentral.mechanizer
6
+ mech.login_to_seller_central
7
+ mech.last_page.body.should =~ /Welcome! You are signed in as/
8
+ end
13
9
 
14
- it "logs in and returns the home page" do
15
- mech = AmazonSellerCentral.mechanizer
16
- mech.login_to_seller_central
17
- end
10
+ it "logs in and returns the home page" do
11
+ mech = AmazonSellerCentral.mechanizer
12
+ mech.login_to_seller_central.should be_true
13
+ end
18
14
 
19
15
  it "raises a LinkNotFoundError if the requested link doesn't exist" do
20
- mech = AmazonSellerCentral.mechanizer
21
- mech.login_to_seller_central
16
+ mech = AmazonSellerCentral.mechanizer
17
+ mech.login_to_seller_central
22
18
  lambda {
23
19
  mech.follow_link_with(:text => "Foo")
24
20
  }.should raise_exception(AmazonSellerCentral::Mechanizer::LinkNotFoundError)
25
21
  end
26
22
 
27
23
  it "resets to a nil agent" do
28
- mech = AmazonSellerCentral.mechanizer
29
- mech.login_to_seller_central
24
+ mech = AmazonSellerCentral.mechanizer
25
+ mech.login_to_seller_central
30
26
  lambda {
31
27
  mech.follow_link_with(:text => "Feedback")
32
28
  }.should_not raise_exception
33
29
  AmazonSellerCentral.mechanizer.reset!
34
30
 
35
- mech = AmazonSellerCentral.mechanizer
36
- mech.login_to_seller_central
31
+ mech = AmazonSellerCentral.mechanizer
32
+ mech.login_to_seller_central
37
33
  AmazonSellerCentral.mechanizer.reset!
38
34
  lambda {
39
35
  mech.follow_link_with(:text => "Feedback")
@@ -41,5 +37,14 @@ describe "Mechanizer" do
41
37
  AmazonSellerCentral.mechanizer.last_page.should be_nil
42
38
  end
43
39
 
40
+ it "logs in twice successfully" do
41
+ mech = AmazonSellerCentral.mechanizer
42
+ mech.login_to_seller_central
43
+ mech.last_page.body.should =~ /Welcome! You are signed in as/
44
+ mech.follow_link_with :text => "Feedback"
45
+
46
+ mech.login_to_seller_central
47
+ mech.last_page.body.should =~ /Welcome! You are signed in as/
48
+ end
44
49
 
45
50
  end
data/spec/spec_helper.rb CHANGED
@@ -15,4 +15,7 @@ end
15
15
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
16
16
 
17
17
  RSpec.configure do |config|
18
+ config.before(:all) do
19
+ mock_seller_central_page_results!
20
+ end
18
21
  end
@@ -0,0 +1,7 @@
1
+ INVENTORY_FIRST_PAGE_TEST_REGEX = /inv|PR48698-2|B001AMUFMA/
2
+ INVENTORY_SECOND_PAGE_TEST_REGEX = /inv|PR28268-11|B002ISXBFI/
3
+ INVENTORY_LAST_PAGE_TEST_REGEX = /inv|PR11-11|B000CC0CKY/
4
+
5
+ FEEDBACK_FIRST_PAGE_TEST_REGEX = /Wow! Amazing price, super fast shipping./
6
+ FEEDBACK_SECOND_PAGE_TEST_REGEX = /This printer was not in good shape as the seller described./
7
+ FEEDBACK_LAST_PAGE_TEST_REGEX = /easy to put together - ignore the first review/
@@ -0,0 +1,23 @@
1
+ shared_examples_for "all pages" do
2
+ it "knows if there is a next page" do
3
+ @first_page.has_next?.should be_true
4
+ @second_page.has_next?.should be_true
5
+ @last_page.has_next?.should be_false
6
+ end
7
+
8
+ it "returns the next page when there is one" do
9
+ @first_page.next_page.body.should =~ @second_page_test_regex
10
+ end
11
+
12
+ it "raises an exception when asked for a next page and there is none" do
13
+ lambda {
14
+ @last_page.next_page
15
+ }.should raise_exception(AmazonSellerCentral::Page::NoNextPageAvailableError)
16
+ end
17
+
18
+ it "knows if it is the last page" do
19
+ @first_page.last_page?.should be_false
20
+ @second_page.last_page?.should be_false
21
+ @last_page.last_page?.should be_true
22
+ end
23
+ end
@@ -4,7 +4,7 @@ Server: Server
4
4
  x-amz-id-1: 05PFY70QQCZD59SMABH2
5
5
  x-amz-id-2: yOubWrVSvkD8r7lvPj6BxYhcNzBItHp/7w9pFqI6OTHtXjDNiOZnHg==
6
6
  Vary: Accept-Encoding,User-Agent
7
- Cneonction: close
7
+ Connection: close
8
8
  Content-Type: text/html; charset=UTF-8
9
9
  Set-cookie: session-id-time=1310281200l; path=/; domain=.amazon.com; expires=Mon Jul 11 01:23:14 2011 GMT
10
10
  Set-cookie: session-id=000-0000000-0000000; path=/; domain=.amazon.com; expires=Mon Jul 11 01:23:14 2011 GMT