Class: Hatsrank::Client
- Inherits:
-
Object
- Object
- Hatsrank::Client
- Defined in:
- lib/hatsrank/client.rb
Instance Method Summary collapse
Instance Method Details
#listings(hat) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/hatsrank/client.rb', line 22 def listings hat response = faraday.get hat.uri + '/render/', query: '', start: 0, count: 100 body = JSON.parse response.body # the values are the listings listings = body["listinginfo"].values.map do |listing| l = Listing.new l.listing_id = listing['listingid'] l.price = listing['price'] l.currency = listing['currencyid'] asset_info = listing['asset'] asset_id = asset_info['id'] asset_app = asset_info['appid'] asset_context = asset_info['contextid'] asset = body['assets'][asset_app.to_s][asset_context.to_s][asset_id.to_s] item = Item.new item.name = asset['name'] asset['descriptions'].each do |description| d = Description.new d.type = description['type'] d.value = description['value'] d.color = description['color'] item.descriptions << d end l.item = item l end end |
#unusual_hats ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/hatsrank/client.rb', line 8 def unusual_hats response = faraday.get 'market/search/render/', query: 'appid:440 unusual', search_descriptions: 0, start: 0, count: 1000 body = JSON.parse response.body results_html = body["results_html"] content = Nokogiri::HTML(results_html) content.css('.market_listing_row_link').map do |marketable_link| Marketable.new self, marketable_link['href'] end end |