Class: GS::Ci

Inherits:
Object
  • Object
show all
Defined in:
lib/goldshark_gem/ci.rb

Instance Method Summary collapse

Constructor Details

#initializeCi

Returns a new instance of Ci.



3
4
# File 'lib/goldshark_gem/ci.rb', line 3

def initialize
end

Instance Method Details

#buy_now(sku_id, rgid) ⇒ Object



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

#get_call(uri) ⇒ Object



30
31
32
33
34
35
# File 'lib/goldshark_gem/ci.rb', line 30

def get_call(uri)
	http = Net::HTTP.new(uri.host, uri.port)
	request = Net::HTTP::Get.new(uri.request_uri)
	response = http.request(request)
	return response.body
end