fassbinder 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
1
  Fassbinder
2
2
  ==========
3
3
 
4
- ![Fassbinder](http://www.ejournal.at/artsite/fassbinder.jpg)
4
+ ![Fassbinder](https://github.com/papercavalier/fassbinder/raw/master/fassbinder.jpg)
data/fassbinder.gemspec CHANGED
@@ -19,8 +19,8 @@ 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.10')
23
- s.add_dependency('sucker', '~> 1.3.1')
22
+ s.add_dependency('kosher', '~> 0.2.14')
23
+ s.add_dependency('sucker', '~> 1.4.0')
24
24
  s.add_development_dependency('rspec', '~> 2.5.0')
25
25
  s.add_development_dependency('ruby-debug19', '~> 0.11.6')
26
26
  s.add_development_dependency('vcr', '~> 1.7.0')
data/fassbinder.jpg ADDED
Binary file
@@ -1,4 +1,8 @@
1
1
  module Fassbinder
2
+
3
+ # And I don't believe that melodramatic feelings are laughable - they should
4
+ # be taken absolutely seriously.
5
+ #
2
6
  class Response
3
7
  def initialize(response, locale)
4
8
  raise InvalidResponseError unless response.valid?
@@ -7,53 +11,17 @@ module Fassbinder
7
11
  @locale = locale
8
12
  end
9
13
 
10
- # And I don't believe that melodramatic feelings are laughable -
11
- # they should be taken absolutely seriously.
12
- def snapshots
13
- @response.map('Item') do |doc|
14
- Kosher::Snapshot.new(
15
- 'amazon.' + Sucker::Request::HOSTS[@locale].match(/[^.]+$/).to_s,
16
- nil,
17
- doc['ASIN'],
18
- doc['SalesRank'].to_i,
19
- doc['Offers']['TotalOffers'].to_i,
20
- [doc['Offers']['Offer']].flatten.compact.map do |doc|
21
- if doc['OfferListing']['Price']['CurrencyCode'] == 'JPY'
22
- doc['OfferListing']['Price']['Amount'] = doc['OfferListing']['Price']['Amount'].to_i * 100
23
- end
14
+ # Yields each snapshot to given block.
15
+ #
16
+ def each
17
+ @response.each('Item') { |doc| yield parse(doc) }
18
+ end
24
19
 
25
- Kosher::Offer.new(
26
- doc['OfferListing']['OfferListingId'],
27
- Kosher::Item.new(doc['OfferListing']['Price']['Amount'].to_i,
28
- doc['OfferListing']['Price']['CurrencyCode'],
29
- doc['OfferListing']['Quantity'].to_i,
30
- Kosher::Condition.new(case doc['OfferAttributes']['SubCondition']
31
- when 'new' then 1
32
- when 'mint' then 2
33
- when 'verygood' then 3
34
- when 'good' then 4
35
- when 'acceptable' then 5
36
- else 6
37
- end),
38
- Kosher::Description.new(doc['OfferAttributes']['ConditionNote'].to_s)),
39
- Kosher::Seller.new(doc['Merchant']['MerchantId'],
40
- doc['Merchant']['Name'],
41
- doc['Merchant']['AverageFeedbackRating'].to_f,
42
- Kosher::Location.new((doc['Merchant']['Location']['CountryCode'] rescue nil), (doc['Merchant']['Location']['StateCode'] rescue nil))),
43
- Kosher::Shipping.new(doc['OfferListing']['IsEligibleForSuperSaverShipping'] == '1' ?
44
- 0 : (case @locale
45
- when :us then 399
46
- when :uk then 280
47
- when :de then 299
48
- when :ca then 649
49
- when :fr then 300
50
- when :jp then 25000
51
- end),
52
- doc['OfferListing']['Price']['CurrencyCode'],
53
- Kosher::Availability.new(doc['OfferListing']['AvailabilityAttributes']['MaximumHours'].to_i))
54
- )
55
- end
56
- )
20
+ # Returns an array of snapshots.
21
+ #
22
+ def to_a
23
+ @response.map('Item') do |doc|
24
+ parse(doc)
57
25
  end
58
26
  end
59
27
 
@@ -62,5 +30,53 @@ module Fassbinder
62
30
  error['Message'].scan(/[0-9A-Z]{10}/).first rescue nil
63
31
  end.compact
64
32
  end
33
+
34
+ private
35
+
36
+ def parse(doc)
37
+ Kosher::Snapshot.new(
38
+ 'amazon.' + Sucker::Request::HOSTS[@locale].match(/[^.]+$/).to_s,
39
+ nil,
40
+ doc['ASIN'],
41
+ doc['SalesRank'].to_i,
42
+ doc['Offers']['TotalOffers'].to_i,
43
+ [doc['Offers']['Offer']].flatten.compact.map do |doc|
44
+ if doc['OfferListing']['Price']['CurrencyCode'] == 'JPY'
45
+ doc['OfferListing']['Price']['Amount'] = doc['OfferListing']['Price']['Amount'].to_i * 100
46
+ end
47
+
48
+ Kosher::Offer.new(
49
+ doc['OfferListing']['OfferListingId'],
50
+ Kosher::Item.new(doc['OfferListing']['Price']['Amount'].to_i,
51
+ doc['OfferListing']['Price']['CurrencyCode'],
52
+ doc['OfferListing']['Quantity'].to_i,
53
+ Kosher::Condition.new(case doc['OfferAttributes']['SubCondition']
54
+ when 'new' then 1
55
+ when 'mint' then 2
56
+ when 'verygood' then 3
57
+ when 'good' then 4
58
+ when 'acceptable' then 5
59
+ else 6
60
+ end),
61
+ Kosher::Description.new(doc['OfferAttributes']['ConditionNote'].to_s)),
62
+ Kosher::Seller.new(doc['Merchant']['MerchantId'],
63
+ doc['Merchant']['Name'],
64
+ doc['Merchant']['AverageFeedbackRating'].to_f,
65
+ Kosher::Location.new((doc['Merchant']['Location']['CountryCode'] rescue nil), (doc['Merchant']['Location']['StateCode'] rescue nil))),
66
+ Kosher::Shipping.new(doc['OfferListing']['IsEligibleForSuperSaverShipping'] == '1' ?
67
+ 0 : (case @locale
68
+ when :us then 399
69
+ when :uk then 280
70
+ when :de then 299
71
+ when :ca then 649
72
+ when :fr then 300
73
+ when :jp then 25000
74
+ end),
75
+ doc['OfferListing']['Price']['CurrencyCode'],
76
+ Kosher::Availability.new(doc['OfferListing']['AvailabilityAttributes']['MaximumHours'].to_i))
77
+ )
78
+ end
79
+ )
80
+ end
65
81
  end
66
82
  end
@@ -1,3 +1,3 @@
1
1
  module Fassbinder
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -31,10 +31,12 @@ module Fassbinder
31
31
  end
32
32
  end
33
33
 
34
- describe "#snapshots" do
35
- it "should return snapshots" do
36
- response.snapshots.count.should eql 19
37
- response.snapshots.first.should be_a Kosher::Snapshot
34
+ describe "#to_a" do
35
+ it "returns an array of snapshots" do
36
+ snapshots = response.to_a
37
+
38
+ snapshots.count.should eql 19
39
+ snapshots.first.should be_a Kosher::Snapshot
38
40
  end
39
41
  end
40
42
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: fassbinder
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.5
5
+ version: 0.0.6
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-10 00:00:00 +00:00
13
+ date: 2011-03-17 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.10
24
+ version: 0.2.14
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  requirements:
33
33
  - - ~>
34
34
  - !ruby/object:Gem::Version
35
- version: 1.3.1
35
+ version: 1.4.0
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
@@ -94,6 +94,7 @@ files:
94
94
  - README.md
95
95
  - Rakefile
96
96
  - fassbinder.gemspec
97
+ - fassbinder.jpg
97
98
  - lib/fassbinder.rb
98
99
  - lib/fassbinder/request.rb
99
100
  - lib/fassbinder/response.rb