Class: TVDB::Authorization

Inherits:
Object
  • Object
show all
Defined in:
lib/tvdb_client/authorization.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Authorization

Returns a new instance of Authorization.



8
9
10
11
12
13
# 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

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



5
6
7
# File 'lib/tvdb_client/authorization.rb', line 5

def api_key
  @api_key
end

#connectionObject

Returns the value of attribute connection.



6
7
8
# File 'lib/tvdb_client/authorization.rb', line 6

def connection
  @connection
end

#passwordObject (readonly)

Returns the value of attribute password.



5
6
7
# File 'lib/tvdb_client/authorization.rb', line 5

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



5
6
7
# File 'lib/tvdb_client/authorization.rb', line 5

def username
  @username
end

Instance Method Details

#loginObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tvdb_client/authorization.rb', line 15

def 
  credentials = {
    :username => username, 
    :userpass => password,
    :apikey   => api_key
  }

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

  handle_response( response )
end

#refresh_tokenObject



27
28
29
30
31
# File 'lib/tvdb_client/authorization.rb', line 27

def refresh_token
  response = connection.get( '/refresh_token' )

  handle_response( response )
end