6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/goldshark_gem/ci.rb', line 6
def buy_now(sku_id, rgid)
buy_now = []
uri = URI.parse("http://pg.links.channelintelligence.com/pages/plxml.asp?sSKU=#{sku_id}&nRGID=#{rgid}")
data = get_call(uri)
xml = XML::Parser.string(data, :options => XML::Parser::Options::NOBLANKS )
doc = xml.parse
doc.find('//DEALER').each do |d|
buy_now << { id: d.attributes.get_attribute('id').value, logo: d.find('DEALER_LOGO').first.content, name: d.find('DEALER_NAME').first.content }
doc.find('//DEALER_ITEM').each do |di|
item = buy_now.find{|bn| bn[:id] == di.find('DEALER_ID').first.content}
item[:buy_now_link] = di.find('BUY_URL').first.content
item[:product_name] = di.find('NAME').first.content
item[:price] = di.find('PRICE').first.content
item[:product_image] = di.find('IMAGE_URL').first.content
if di.find('AVAILABILITY').first.content == 'YES'
item[:available] = 'Y'
else
next
end
end
return buy_now
end
end
|