Class: Trustev::Authenticate

Inherits:
Object
  • Object
show all
Defined in:
lib/trustev/authenticate.rb

Constant Summary collapse

SERVICE_URL =
'AuthenticationService.svc/rest/Token'

Class Method Summary collapse

Class Method Details

.retrieve_tokenObject

Raises:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/trustev/authenticate.rb', line 8

def self.retrieve_token

  raise Error.new('No Username provided.') unless Trustev.username
  raise Error.new('No Password provided.') unless Trustev.password
  raise Error.new('No Shared Secret provided.') unless Trustev.shared_secret

  time = Time.now.utc

  body = {
    UserName: Trustev.username,
    Password: password(time),
    Sha256Hash: sha256hash(time),
    Timestamp: "\/Date(#{time.to_i*1000})\/"
  }

  response = Trustev.send_request SERVICE_URL, body, 'POST', true, false
  Trustev.token = response[:Token][:APIToken]
  Trustev.token_expire = response[:Token][:ExpireAt][/\((.*)\)/m, 1].to_i/1000
end