ProviderBase = require './ProviderBase'
request = require 'request'
torify = require 'torify'
cheerio = require 'cheerio'
async = require 'async'

class Steam extends ProviderBase
	constructor: (@data) ->

	prices: (args, callback) ->
		additonal = {}
		additonal.prices = []
		torify
			timeout: (1000 * 10)
			url: 'http://store.steampowered.com/search/'
			qs: 
				snr: '1_4_4__12'
				term: (@data.title or @data.game_name)

			,(E, res, body) =>
				$ = cheerio.load(body or "")

				price = NaN
				if $('div.search_price').length
					price = parseFloat ($($('div.search_price')[1]).text().split('$').pop())

				if !isNaN(price)
					additonal.prices.push
						'Steam': price
				callback E, additonal

module.exports = Steam