Created
September 15, 2014 14:57
-
-
Save funzoneq/2a9ba74b2dd059817ee5 to your computer and use it in GitHub Desktop.
This file contains 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 | |
require 'httparty' | |
require 'pp' | |
class HiberniaCDN | |
include HTTParty | |
#debug_output $stderr | |
base_uri 'https://portal.hiberniacdn.com/api.json/v1' | |
def initialize (options = {}) | |
@options = options.merge({ :headers => { "User-Agent" => "stupidapi" }}) | |
end | |
def salt | |
self.class.get("/auth/salt/", @options) | |
end | |
def login (email, password, timezone) | |
# Get the salt for the login | |
salt = self.salt() | |
puts "Salt: " | |
pp salt | |
puts | |
# Get the Set-Cookie header, and add that to the next requests | |
@options[:headers] = @options[:headers].merge({ "Cookie" => salt.headers['Set-Cookie'] }) | |
# Hash password and salt | |
key = Digest::SHA256.new("#{password}#{salt['result']}").hexdigest | |
# Post values | |
body = { :key => key, :username => email, :timezone => timezone } | |
puts "Post body: " | |
pp body | |
puts | |
puts "Headers" | |
pp @options | |
puts | |
self.class.post("/auth/login/", :body => body, :headers => @options[:headers] ) | |
end | |
end | |
h = HiberniaCDN.new({}) | |
session = h.login('[email protected]', 'test123', 'Europe/Amsterdam') | |
puts "Response" | |
pp session |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment