Module: LeisureKing::Authentication

Defined in:
lib/leisureking/authentication.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.tokenObject

Returns the value of attribute token.



9
10
11
# File 'lib/leisureking/authentication.rb', line 9

def token
  @token
end

Class Method Details

.api_key_valid_untilObject



37
38
39
40
# File 'lib/leisureking/authentication.rb', line 37

def api_key_valid_until
  decoded_token = JWT.decode self.token, nil, false
  Time.at(decoded_token.first["exp"])
end

.get_tokenObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/leisureking/authentication.rb', line 19

def get_token
  body = {
    apikey: LeisureKing::Config.api_key,
    secret: LeisureKing::Config.api_secret
  }
  result = LeisureKing::API.send_request("authenticate", body)
  if result["status"] && result["status"] == "OK"
    self.token = result["data"]["token"]
  end
  return result
end

.has_valid_api_keyObject

represents a date in the future.



33
34
35
# File 'lib/leisureking/authentication.rb', line 33

def has_valid_api_key
  return self.token != nil && api_key_valid_until > Time.now
end

.init!Hash

Set’s the default value’s to nil and false

Returns:

  • (Hash)

    conguration options



13
14
15
16
17
# File 'lib/leisureking/authentication.rb', line 13

def init!
  @defaults = {
    :@token    => nil,
  }
end