Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #17 from favelafabric/fix-missing-offers
Browse files Browse the repository at this point in the history
Fix for missing <Offers> element
  • Loading branch information
avdgaag committed Jun 25, 2013
2 parents 9d315ca + 1e00688 commit 4ecbb99
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/bol/parsers/products.rb
Expand Up @@ -15,6 +15,7 @@ def parse_object(el)
product.attributes[field.to_sym] = el.at(_field).content.gsub(/\n\s+/, ' ').strip
end
end

product[:offers] = []
el.at('Offers').elements.each do |offer|
o = %w[id first_edition special_edition state price list_price availability_code availability_description comment second_hand seller].inject({}) do |output, field|
Expand All @@ -25,7 +26,8 @@ def parse_object(el)
output
end
product[:offers] << OpenStruct.new(o)
end
end if el.at('Offers')

product[:url] = el.at('Urls').at('Main').content.strip
if el.at('ReleaseDate')
product[:release_date] = Time.parse(el.at('ReleaseDate').content)
Expand Down
8 changes: 8 additions & 0 deletions spec/bol/parsers/products_spec.rb
Expand Up @@ -51,6 +51,14 @@
end
end

describe 'products without offers' do
let(:body) { fixture('product-without-offers.xml') }

it 'parses the product correctly' do
product.offers.should eq []
end
end

describe 'parsing product search results' do
let(:body) { fixture('searchproducts-music.xml') }
let(:products) { Bol::Parsers::Products.new(request).objects }
Expand Down
58 changes: 58 additions & 0 deletions spec/fixtures/product-without-offers.xml
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<ProductResponse xmlns="http://openapi.bol.com/openapi-3.0.0">
<SessionId>F759BF74-918B-41D3-9B45-9D7E51A13C7C</SessionId>
<Product>
<Id>1001004006016448</Id>
<Title>Harry Potter Boxed Set (Adult Edition)</Title>
<Subtitle>Volume 1 - 7, paperback</Subtitle>
<Type>book</Type>
<Publisher>Bloomsbury Publishing PLC</Publisher>
<ShortDescription>This is a fabulous opportunity to finally own
all seven Harry Potter titles - Harry Potter and the
Philosopher's Stone , Harry Potter and the Chamber of Secrets ,
Harry Potter and the Prisoner of Azkaban , Harry Potter and the
Goblet of Fire , Harry Potter and the Order of the Phoenix ,
Harry Potter and the Half-Blood Prince and Harry Potter and the
Deathly Hallows - in a fantastic boxed set.</ShortDescription>
<LongDescription>This is a fabulous opportunity to finally own
all seven Harry Potter titles - Harry Potter and the
Philosopher's Stone , Harry Potter and the Chamber of Secrets ,
Harry Potter and the Prisoner of Azkaban , Harry Potter and the
Goblet of Fire , Harry Potter and the Order of the Phoenix ,
Harry Potter and the Half-Blood Prince and Harry Potter and the
Deathly Hallows - in a fantastic boxed set.</LongDescription>
<ReleaseDate>2008-10-01+02:00</ReleaseDate>
<Ean>9780747595847</Ean>
<Rating>5</Rating>
<BindingCode>1101</BindingCode>
<BindingDescription>Paperback</BindingDescription>
<LanguageCode>en</LanguageCode>
<LanguageDescription>Engels</LanguageDescription>
<Urls>
<Main>
http://www.bol.com/nl/p/engelse-boeken/harry-potter-boxed-set/1001004006016448/index.html</Main>
</Urls>
<Authors>
<Author>
<Id>231315</Id>
<Name>J. K. Rowling</Name>
</Author>
<Author>
<Id>540846</Id>
<Name>J.K. Rowling</Name>
</Author>
</Authors>
<Images>
<ExtraSmall>
http://s-bol.com/imgbase0/imagebase/mini/FC/8/4/4/6/1001004006016448.jpg</ExtraSmall>
<Small>
http://s-bol.com/imgbase0/imagebase/tout/FC/8/4/4/6/1001004006016448.jpg</Small>
<Medium>
http://s-bol.com/imgbase0/imagebase/thumb/FC/8/4/4/6/1001004006016448.jpg</Medium>
<Large>
http://s-bol.com/imgbase0/imagebase/regular/FC/8/4/4/6/1001004006016448.jpg</Large>
<ExtraLarge>
http://s-bol.com/imgbase0/imagebase/large/FC/8/4/4/6/1001004006016448.jpg</ExtraLarge>
</Images>
</Product>
</ProductResponse>

0 comments on commit 4ecbb99

Please sign in to comment.