class Tvdbjson::Authentication

Constants

TVDB_API_KEY
TVDB_USER_KEY
TVDB_USER_NAME

Attributes

expiry[RW]
token[RW]

Public Class Methods

new() click to toggle source
# File lib/tvdbjson/authentication.rb, line 10
def initialize()
  new_token
end

Public Instance Methods

new_token() click to toggle source
# File lib/tvdbjson/authentication.rb, line 18
def new_token
  @expiry = Time.now + 86400
  @token = get_token
end
token_expired?() click to toggle source
# File lib/tvdbjson/authentication.rb, line 14
def token_expired?
  Time.now >= @expiry
end

Private Instance Methods

get_token() click to toggle source
# File lib/tvdbjson/authentication.rb, line 25
def get_token
  options = {}
  options[:uri] = "/login"
  options[:body] = { "apikey" => TVDB_API_KEY, "userkey" => TVDB_USER_KEY, "username" => TVDB_USER_NAME }
  options[:header] = { "Content-Type" => "application/json" }

  request = Request.new(options)
  response = request.post
  response.parsed_response["token"]
end