Class: Tangerine::Backlot::API

Inherits:
Object
  • Object
show all
Defined in:
lib/tangerine/backlot.rb

Class Method Summary collapse

Class Method Details

.authenticate!(credentials) ⇒ Object



17
18
19
20
21
# File 'lib/tangerine/backlot.rb', line 17

def self.authenticate!(credentials)
  creds = HashWithIndifferentAccess.new credentials
  @secret = creds[:secret]
  HTTP.default_params :pcode => creds[:provider_code]
end

.authenticated?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/tangerine/backlot.rb', line 39

def self.authenticated?
  @secret && HTTP.default_params[:pcode]
end

.get(request_type, params = {}) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/tangerine/backlot.rb', line 23

def self.get(request_type, params={})
  raise NotAuthenticatedError unless self.authenticated?

  params['expires'] ||= (Time.now.to_i + 10).to_s
  params['signature'] = self.signature(params)
  HTTP.get(request_type, {:query => params})
end

.signature(params) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/tangerine/backlot.rb', line 31

def self.signature(params)
  string_to_sign = params.keys.sort.inject(@secret) do |memo, key|
    memo += "#{key}=#{params[key]}"
  end
  digest = Digest::SHA256.digest(string_to_sign)
  Base64::encode64(digest).chomp.gsub(/=+$/, '')
end