Last active
December 31, 2015 00:50
-
-
Save numinit/a0e5ea08376b42039113 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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