module Trustev

Constants

ADDRESS_TYPES
REASON_TYPES
SCORE_PARAMETERS
SCORE_SOURCES
SOCIAL_NETWORK_TYPES
STATUS_TYPES
VERSION

Public Class Methods

api_url(url='') click to toggle source
# File lib/trustev.rb, line 122
def self.api_url(url='')
  @@api_base + @@api_version + '/' + url
end
password() click to toggle source
# File lib/trustev.rb, line 94
def self.password
  @@password
end
password=(password) click to toggle source
# File lib/trustev.rb, line 90
def self.password=(password)
  @@password = password
end
private_key() click to toggle source
# File lib/trustev.rb, line 110
def self.private_key
  @@private_key
end
private_key=(private_key) click to toggle source
# File lib/trustev.rb, line 106
def self.private_key=(private_key)
  @@private_key = private_key
end
public_key() click to toggle source
# File lib/trustev.rb, line 118
def self.public_key
  @@public_key
end
public_key=(public_key) click to toggle source
# File lib/trustev.rb, line 114
def self.public_key=(public_key)
  @@public_key = public_key
end
send_request(path, body, method, expect_json=false, requires_token=true) click to toggle source
# File lib/trustev.rb, line 142
def self.send_request(path, body, method, expect_json=false, requires_token=true)

  if requires_token && invalid_token?
    Authenticate.retrieve_token
  end

  raise Error.new('Auth token missing or expired') if requires_token && invalid_token?

  headers = { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
  headers['X-Authorization'] = "#{@@username} #{@@token}" if requires_token

  body = { request:  body }

  options = { body: body.to_json, headers: headers}

  response = HTTParty.post(api_url(path), options) if method == 'POST'
  response = HTTParty.get(api_url(path), options) if method == 'GET'
  response = HTTParty.put(api_url(path), options) if method == 'PUT'
  response = HTTParty.delete(api_url(path), options) if method == 'DELETE'

  raise Error.new('Bad API response', response.code, response.message) if response.code != 200

  if expect_json
    begin
      response = MultiJson.load(response.body, symbolize_keys: true)
    rescue MultiJson::DecodeError
      raise Error.new('Invalid API response', response.code, response.message)
    end
  end

  response
end
shared_secret() click to toggle source
# File lib/trustev.rb, line 102
def self.shared_secret
  @@shared_secret
end
shared_secret=(shared_secret) click to toggle source
# File lib/trustev.rb, line 98
def self.shared_secret=(shared_secret)
  @@shared_secret = shared_secret
end
token() click to toggle source
# File lib/trustev.rb, line 130
def self.token
  @@token
end
token=(token) click to toggle source
# File lib/trustev.rb, line 126
def self.token=(token)
  @@token = token
end
token_expire() click to toggle source
# File lib/trustev.rb, line 138
def self.token_expire
  @@token_expire
end
token_expire=(token_expire) click to toggle source
# File lib/trustev.rb, line 134
def self.token_expire=(token_expire)
  @@token_expire = token_expire
end
username() click to toggle source
# File lib/trustev.rb, line 86
def self.username
  @@username
end
username=(username) click to toggle source
# File lib/trustev.rb, line 82
def self.username=(username)
  @@username = username
end

Private Class Methods

invalid_token?() click to toggle source
# File lib/trustev.rb, line 177
def self.invalid_token?
  @@token.nil? || @@token_expire-600 <= Time.now.to_i
end