fassbinder 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,4 +4,4 @@ pkg/*
4
4
  .rvmrc
5
5
  .rspec
6
6
  Gemfile.lock
7
- amazon.yml
7
+ *.yml
data/fassbinder.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ['lib']
21
21
 
22
- s.add_dependency('kosher', '~> 0.2.7')
22
+ s.add_dependency('kosher', '~> 0.2.8')
23
23
  s.add_dependency('sucker', '~> 1.3.1')
24
24
  s.add_development_dependency('rspec', '~> 2.5.0')
25
25
  s.add_development_dependency('ruby-debug19', '~> 0.11.6')
@@ -16,7 +16,7 @@ module Fassbinder
16
16
  end
17
17
 
18
18
  def get
19
- ResponseWrapper.new(super, locale)
19
+ Response.new(super, locale)
20
20
  end
21
21
  end
22
22
  end
@@ -1,5 +1,5 @@
1
1
  module Fassbinder
2
- class ResponseWrapper
2
+ class Response
3
3
  def initialize(response, locale)
4
4
  raise InvalidResponseError unless response.valid?
5
5
 
@@ -9,12 +9,13 @@ module Fassbinder
9
9
 
10
10
  # And I don't believe that melodramatic feelings are laughable -
11
11
  # they should be taken absolutely seriously.
12
- def items
12
+ def snapshots
13
13
  @response.map('Item') do |doc|
14
- Item.new(
14
+ Kosher::Snapshot.new(
15
+ nil,
15
16
  doc['ASIN'],
16
- doc['Offers']['TotalOffers'].to_i,
17
17
  doc['SalesRank'].to_i,
18
+ doc['Offers']['TotalOffers'].to_i,
18
19
  [doc['Offers']['Offer']].flatten.compact.map do |doc|
19
20
  if doc['OfferListing']['Price']['CurrencyCode'] == 'JPY'
20
21
  doc['OfferListing']['Price']['Amount'] = doc['OfferListing']['Price']['Amount'].to_i * 100
@@ -60,9 +61,5 @@ module Fassbinder
60
61
  error['Message'].scan(/[0-9A-Z]{10}/).first rescue nil
61
62
  end.compact
62
63
  end
63
-
64
- def response
65
- @response
66
- end
67
64
  end
68
65
  end
@@ -1,3 +1,3 @@
1
1
  module Fassbinder
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/fassbinder.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require 'kosher'
2
2
  require 'sucker'
3
3
 
4
- require 'fassbinder/errors'
5
- require 'fassbinder/item'
6
4
  require 'fassbinder/request'
7
- require 'fassbinder/response_wrapper'
5
+ require 'fassbinder/response'
6
+
7
+ module Fassbinder
8
+ class InvalidResponseError < StandardError; end
9
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ module Fassbinder
4
+ describe Response do
5
+ use_vcr_cassette 'batch-request'
6
+
7
+ let(:asins) do
8
+ # The last ASIN does not exist.
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 2081232191 }
14
+ end
15
+
16
+ let(:response) do
17
+ request = Request.new(credentials)
18
+ request.locale = :us
19
+ request.batchify(asins)
20
+ request.get
21
+ end
22
+
23
+ describe ".new" do
24
+ it "raises an error if response is not valid" do
25
+ response = mock('Response')
26
+ response.stub!(:valid?).and_return(false)
27
+
28
+ expect do
29
+ Response.new(response, :us)
30
+ end.to raise_error InvalidResponseError
31
+ end
32
+ end
33
+
34
+ describe "#snapshots" do
35
+ it "should return snapshots" do
36
+ debugger
37
+ response.snapshots.count.should eql 19
38
+ response.snapshots.first.should be_a Kosher::Snapshot
39
+ end
40
+ end
41
+
42
+ describe "#errors" do
43
+ it "should return ASINs that are not found" do
44
+ response.errors.count.should eql 1
45
+ response.errors.first.should eql '2081232191'
46
+ end
47
+ end
48
+ end
49
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: fassbinder
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Paper Cavalier
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-09 00:00:00 +00:00
13
+ date: 2011-03-10 00:00:00 +00:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - ~>
23
23
  - !ruby/object:Gem::Version
24
- version: 0.2.7
24
+ version: 0.2.8
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
@@ -96,12 +96,11 @@ files:
96
96
  - fassbinder.gemspec
97
97
  - lib/fassbinder.rb
98
98
  - lib/fassbinder/errors.rb
99
- - lib/fassbinder/item.rb
100
99
  - lib/fassbinder/request.rb
101
- - lib/fassbinder/response_wrapper.rb
100
+ - lib/fassbinder/response.rb
102
101
  - lib/fassbinder/version.rb
103
102
  - spec/fassbinder/request_spec.rb
104
- - spec/fassbinder/response_wrapper_spec.rb
103
+ - spec/fassbinder/response_spec.rb
105
104
  - spec/spec_helper.rb
106
105
  - spec/support/credentials.rb
107
106
  - spec/support/vcr.rb
@@ -135,7 +134,7 @@ specification_version: 3
135
134
  summary: Wraps Amazon in a loving embrace.
136
135
  test_files:
137
136
  - spec/fassbinder/request_spec.rb
138
- - spec/fassbinder/response_wrapper_spec.rb
137
+ - spec/fassbinder/response_spec.rb
139
138
  - spec/spec_helper.rb
140
139
  - spec/support/credentials.rb
141
140
  - spec/support/vcr.rb
@@ -1,4 +0,0 @@
1
- module Fassbinder
2
- class Item < Struct.new(:asin, :count, :rank, :offers)
3
- end
4
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Fassbinder
4
- describe ResponseWrapper do
5
- describe ".new" do
6
- it "raises an error if response is not valid" do
7
- response = mock('Response')
8
- response.stub!(:valid?).and_return(false)
9
-
10
- expect do
11
- ResponseWrapper.new(response, :us)
12
- end.to raise_error InvalidResponseError
13
- end
14
- end
15
-
16
- describe "#books" do
17
- use_vcr_cassette 'batch-request'
18
-
19
- let(:asins) do
20
- # The last ASIN does not exist.
21
- %w{
22
- 0816614024 0143105825 0485113600 0816616779 0942299078
23
- 0816614008 144006654X 0486400360 0486417670 087220474X
24
- 0486454398 0268018359 1604246014 184467598X 0312427182
25
- 1844674282 0745640974 0745646441 0826489540 2081232191 }
26
- end
27
-
28
- let(:response_wrapper) do
29
- request = Request.new(credentials)
30
- request.locale = :us
31
- request.batchify(asins)
32
- request.get
33
- end
34
-
35
- it "should return found books" do
36
- debugger
37
- response_wrapper.items.count.should eql 19
38
- response_wrapper.items.first.should be_a Book
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