kosher 0.1.12 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Kosher
4
- describe Algorithm do
5
- use_vcr_cassette 'batch-request'
6
-
7
- let(:asins) do
8
-
9
- # The last ASIN does not exist.
10
- %w{
11
- 0816614024 0143105825 0485113600 0816616779 0942299078
12
- 0816614008 144006654X 0486400360 0486417670 087220474X
13
- 0486454398 0268018359 1604246014 184467598X 0312427182
14
- 1844674282 0745640974 0745646441 0826489540 2081232191 }
15
- end
16
-
17
- let(:algorithm) do
18
- request = Request.new(credentials)
19
- request.locale = :us
20
- request.batchify(asins)
21
- request.get
22
- end
23
-
24
- describe ".new" do
25
- it "raises an error if response is not valid" do
26
- response = mock('Response')
27
- response.stub!(:valid?).and_return(false)
28
-
29
- expect do
30
- Algorithm.new(response)
31
- end.to raise_error ResponseNotValidError
32
- end
33
- end
34
-
35
- describe "#items" do
36
- it "should return found items" do
37
- algorithm.items.count.should eql 19
38
- algorithm.items.first.should be_a Item
39
- end
40
- end
41
-
42
- describe "#errors" do
43
- it "should return ASINs that are not found" do
44
- algorithm.errors.count.should eql 1
45
- algorithm.errors.first.should eql '2081232191'
46
- end
47
- end
48
- end
49
- end
@@ -1,50 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Kosher
4
- describe Item do
5
- it "should descend from Kosher::Struct" do
6
- Item.ancestors.should include Kosher::Struct
7
- end
8
-
9
- describe ".build" do
10
- use_vcr_cassette '0143105825'
11
-
12
- let(:asin) { '0143105825' }
13
-
14
- it "should build an item" do
15
- request = Request.new(credentials)
16
- request.locale = :us
17
- request.batchify([asin])
18
- algorithm = request.get
19
- response = algorithm.instance_variable_get(:@response)
20
- doc = response.find('Item').first
21
- item = Item.build(doc)
22
-
23
- item.should be_a Item
24
- item.asin.should eql asin
25
- item.offers_count.should be > 0
26
- item.sales_rank.should be > 0
27
- item.offers.count.should > 0
28
- item.offers.first.should be_a Offer
29
- end
30
-
31
- it "should senify Yen in Japanese requests" do
32
- request = Request.new(credentials)
33
- request.locale = :jp
34
- request.batchify([asin])
35
- algorithm = request.get
36
- response = algorithm.instance_variable_get(:@response)
37
- doc = response.find('Item').first
38
-
39
- doc['Offers']['Offer'].each do |offer|
40
- offer['OfferListing']['Price']['Amount'] = 1
41
- end
42
- item = Item.build(doc)
43
-
44
- item.offers.each do |offer|
45
- offer.cents.should eql 100
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,42 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Kosher
4
- describe Request do
5
- let(:request) { Request.new(credentials) }
6
-
7
- describe ".new" do
8
- it "should define a batch request" do
9
- request.parameters['Operation'].should eql 'ItemLookup'
10
- request.parameters['ItemLookup.Shared.IdType'].should eql 'ASIN'
11
- request.parameters['ItemLookup.Shared.Condition'].should eql 'All'
12
- request.parameters['ItemLookup.Shared.MerchantId'].should eql 'All'
13
- request.parameters['ItemLookup.Shared.ResponseGroup'].should eql ['OfferFull', 'SalesRank']
14
- end
15
- end
16
-
17
- describe "#batchify" do
18
- it "should add up to 20 ASINs to the worker's parameters" do
19
- asins = (0..19).to_a
20
- request.batchify(asins)
21
-
22
- request.parameters['ItemLookup.1.ItemId'].should eql (0..9).to_a
23
- request.parameters['ItemLookup.2.ItemId'].should eql (10..19).to_a
24
- end
25
- end
26
-
27
- describe "#request" do
28
- before do
29
- VCR.http_stubbing_adapter.http_connections_allowed = true
30
- end
31
-
32
- it "should return an algorithm" do
33
- Kosher::Request.stub!(:get)
34
-
35
- request.locale = :us
36
- request.batchify('foo')
37
-
38
- request.get.should be_a Algorithm
39
- end
40
- end
41
- end
42
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Kosher
4
- describe Struct do
5
- before(:all) do
6
- class Foo < Struct.new(:bar); end
7
- end
8
-
9
- describe "to_json" do
10
- it "converts to JSON" do
11
- foo = Foo.new
12
- foo.bar = 1
13
-
14
- foo.to_json.should eql "{\"bar\":1}"
15
- end
16
-
17
- it "handles nested structs" do
18
- foo_1 = Foo.new
19
- foo_2 = Foo.new
20
-
21
- foo_2.bar = 1
22
- foo_1.bar = foo_2
23
-
24
- foo_1.to_json.should eql "{\"bar\":{\"bar\":1}}"
25
- end
26
- end
27
- end
28
- end
@@ -1,3 +0,0 @@
1
- def credentials
2
- @credentials ||= YAML::load_file(File.dirname(__FILE__) + "/credentials.yml")
3
- end
@@ -1,19 +0,0 @@
1
- module Faker
2
- module Amazon
3
- class << self
4
- def asin
5
- raw = 9.times.map { rand(10).to_s }
6
- (raw << Bookland::ISBN.new.send(:check_digit_10, raw)).join
7
- end
8
-
9
- def ean
10
- Bookland::ISBN.to_13(asin)
11
- end
12
-
13
- def merchant_id
14
- seed = ('A'..'Z').to_a + (0..9).to_a
15
- 14.times.map { seed[rand(seed.size)] }.join
16
- end
17
- end
18
- end
19
- end
data/spec/support/vcr.rb DELETED
@@ -1,12 +0,0 @@
1
- require 'vcr'
2
-
3
- VCR.config do |c|
4
- c.cassette_library_dir = "#{File.dirname(__FILE__)}/../fixtures/cassette_library"
5
- c.stub_with :webmock
6
- c.ignore_localhost = true
7
- c.default_cassette_options = { :record => :new_episodes, :match_requests_on => [:host] }
8
- end
9
-
10
- RSpec.configure do |config|
11
- config.extend VCR::RSpec::Macros
12
- end
data/walter_benjamin.jpg DELETED
Binary file