Skip to content

Instantly share code, notes, and snippets.

@numinit
Last active Dec 31, 2015
Embed
What would you like to do?
#!/usr/bin/env ruby
# usage: $0 <app ID> <passcode>
require 'uri'
require 'json'
require 'net/http'
module Valve
URI_FORMAT = 'http://store.steampowered.com/actions/clues?key=%s'.freeze
REFERER_FORMAT = 'http://store.steampowered.com/app/%d'.freeze
def self.clue passcode, cookie, app_id
uri = URI.parse(URI_FORMAT % URI.escape(passcode))
req = Net::HTTP::Get.new uri
req['Cookie'.freeze] = cookie unless cookie.nil?
req['Referer'.freeze] = REFERER_FORMAT % app_id
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https'.freeze) {|h| h.request(req)}
if res.is_a? Net::HTTPSuccess
JSON.parse res.body
else
raise "got HTTP #{res.code} from #{uri}"
end
end
end
begin
raise ArgumentError, "usage: #$0 <app id> <passcode>" unless ARGV.length == 2
res = Valve.clue ARGV[1], ENV['COOKIE'], Integer(ARGV[0])
STDOUT.puts res.inspect
exit 0
rescue => e
STDERR.puts "#$0: #{e.class}: #{e.message}"
STDERR.puts e.backtrace
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment