Sha256: f549cf546f1c1957240ef7c017b19c458d75855f02f058277769d7b8ff1b86ad
Contents?: true
Size: 1.49 KB
Versions: 1
Compression:
Stored size: 1.49 KB
Contents
require 'mechanize' require 'goodwill/csspaths' require 'goodwill/urlpaths' require 'goodwill/mechanize' module Goodwill class Auction include Goodwill::Mechanize include CSSPaths include URLPaths attr_reader :bids attr_reader :current attr_reader :end attr_reader :href attr_reader :item attr_reader :itemid attr_reader :seller attr_reader :shipping def initialize(itemid, zipcode = '97222', state = 'OR', country = 'United States') @itemid = itemid @zipcode = zipcode @state = state @country = country @href = ITEM_SEARCH_URL + itemid.to_s item_page = mechanize.get(@href) @bids = item_page.search(BIDS_PATH).text[/\d+/] @current = item_page.search(CURRENT_PRICE_PATH).text @end = item_page.search(END_TIME_PATH).text @item = item_page.search(ITEM_TITLE_PATH).text @seller = item_page.search(SELLER_PATH).text @bidding = false @shipping = calculate_shipping(@itemid, @zipcode, @state, @country) end def ==(another_auction) self.itemid == another_auction.itemid end def to_hash hash = {} instance_variables.each {|var| hash[var.to_s.delete("@")] = instance_variable_get(var) } hash end private def calculate_shipping(itemid, zipcode, state, country) params = "?itemid=#{itemid}&zip=#{zipcode}&state=#{state}&country=#{country}" page = mechanize.get(SHIPPING_URL + params) page.search(SHIPPING_PATH).text end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
goodwill-0.2.1 | lib/goodwill/auction.rb |