class SellDotCom::Search
Attributes
results[R]
search_phrase[RW]
search_uri[R]
Public Class Methods
new(search_phrase)
click to toggle source
# File lib/selldotcom/search.rb, line 7 def initialize(search_phrase) @search_phrase ||= search_phrase @search_uri ||= search_uri end
Public Instance Methods
search()
click to toggle source
# File lib/selldotcom/search.rb, line 12 def search response = Typhoeus::Request.get(@search_uri) @results = parse(response.body) end
Private Instance Methods
parse(html)
click to toggle source
# File lib/selldotcom/search.rb, line 20 def parse(html) doc = Nokogiri::XML(html) results = [] doc.xpath("//item").each do |item| title = item.xpath("title").text url = item.xpath("link").text posted_on = item.xpath("pubDate").text item_id = parse_item_id(url) results << { :title => title, :url => url, :item_id => item_id, :posted_on => posted_on } end results end
parse_item_id(url)
click to toggle source
# File lib/selldotcom/search.rb, line 33 def parse_item_id(url) /sell.com\/([\S]+)\z/.match(url)[1] end