module LeisureKing::Authentication

Attributes

token[RW]

Public Class Methods

api_key_valid_until() click to toggle source
# 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_token() click to toggle source
# 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_key() click to toggle source

Parses the current API key and checks if the 'exp' attribute represents a date in the future.

# File lib/leisureking/authentication.rb, line 33
def has_valid_api_key
  return self.token != nil && api_key_valid_until > Time.now
end
init!() click to toggle source

Set's the default value's to nil and false @return [Hash] conguration options

# File lib/leisureking/authentication.rb, line 13
def init!
  @defaults = {
    :@token    => nil,
  }
end