class Distimo::Client

Attributes

password[RW]
private_key[RW]
public_key[RW]
token[RW]
username[RW]

Public Class Methods

new(opts) click to toggle source
# File lib/distimo/client.rb, line 12
def initialize opts
  opts.each {|k,v| send("#{k}=",v)}
end

Public Instance Methods

get(path, query) click to toggle source
# File lib/distimo/client.rb, line 16
def get path, query
  options = prepare(query)
  response = self.class.get path, options
  raise Error.from_response(response) if response.code >= 400
  response
end

Private Instance Methods

prepare(query) click to toggle source
# File lib/distimo/client.rb, line 25
def prepare query
  time = Time.now.utc.to_i
  hash  = prepare_hash query,time
  _query = query.merge(apikey: public_key, hash: hash, t: time)
  _auth = prepare_auth
  {query: _query}.merge(_auth)
end
prepare_auth() click to toggle source
# File lib/distimo/client.rb, line 38
def prepare_auth
  if token
    {headers: {"Authorization" => "Bearer #{token}"}}
  else
    {basic_auth: {:username => username, :password => password}}
  end
end
prepare_hash(query,time) click to toggle source
# File lib/distimo/client.rb, line 33
def prepare_hash query,time
  _query = query.map{|k,v| "#{k}=#{v}"}.join("&")
  OpenSSL::HMAC.hexdigest('sha1', private_key, _query + time.to_s)
end