Skip to content

Instantly share code, notes, and snippets.

@funzoneq
Created September 15, 2014 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funzoneq/2a9ba74b2dd059817ee5 to your computer and use it in GitHub Desktop.
Save funzoneq/2a9ba74b2dd059817ee5 to your computer and use it in GitHub Desktop.
#!/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('test@blaat.nl', '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