class TVDB::Authorization

Attributes

api_key[R]
connection[RW]
password[R]
username[R]

Public Class Methods

new( options ) click to toggle source
# File lib/tvdb_client/authorization.rb, line 8
def initialize( options )
  @username    = options.fetch( :username )   { nil }
  @password    = options.fetch( :userpass )   { nil }
  @api_key     = options.fetch( :apikey )     { Settings.tvdb.apikey   }
  @connection  = options.fetch( :connection )
end

Public Instance Methods

login() click to toggle source
# File lib/tvdb_client/authorization.rb, line 15
def login
  credentials = {
    :username => username, 
    :userpass => password,
    :apikey   => api_key
  }

  response = connection.post( "/login", body: credentials )

  handle_response( response )
end
refresh_token() click to toggle source
# File lib/tvdb_client/authorization.rb, line 27
def refresh_token
  response = connection.get( '/refresh_token' )

  handle_response( response )
end

Private Instance Methods

handle_response( response ) click to toggle source
# File lib/tvdb_client/authorization.rb, line 35
def handle_response( response )
  if response.code != 200
    connection.token = ""
  else
    connection.token = response.body["token"]
  end

  return response
end