Class: Tvdb2::Client
- Inherits:
-
Object
- Object
- Tvdb2::Client
- Extended by:
- Memoist
- Includes:
- HTTParty, API
- Defined in:
- lib/tvdb2/client.rb
Overview
This class works as a client to retrieve data from TVDB json api version 2. Make http requests to api.thetvdb.com.
This class cache all http requests so only the first time a request is made (Memoist gem is used).
Instance Attribute Summary collapse
-
#language ⇒ Object
The language in which you want get data.
Class Method Summary collapse
-
.image_url(path) ⇒ String
Helper method to get the full url of an image from the relative path retrieved from api.
Instance Method Summary collapse
-
#initialize(apikey:, language: 'en') ⇒ Client
constructor
Create an object client.
-
#refresh_token! ⇒ String
Refresh your api token.
-
#with_language(locale) { ... } ⇒ Object
Inside the block change the language in which you want get data.
Methods included from API
#actors, #best_search, #episode, #episodes, #images, #images_summary, #languages, #search, #series, #series_summary
Constructor Details
#initialize(apikey:, language: 'en') ⇒ Client
Create an object client. Take 2 keyword arguments:
42 43 44 45 46 47 |
# File 'lib/tvdb2/client.rb', line 42 def initialize(apikey:, language: 'en') @language = language response = post('/login', apikey: apikey) raise RequestError.new(response) if response.code != 200 @token = response.parsed_response['token'] end |
Instance Attribute Details
#language ⇒ Object
The language in which you want get data.
28 29 30 |
# File 'lib/tvdb2/client.rb', line 28 def language @language end |
Class Method Details
.image_url(path) ⇒ String
Helper method to get the full url of an image from the relative path retrieved from api.
91 92 93 |
# File 'lib/tvdb2/client.rb', line 91 def self.image_url(path) URI::join("https://thetvdb.com/banners/", path).to_s end |
Instance Method Details
#refresh_token! ⇒ String
Refresh your api token.
52 53 54 55 56 57 |
# File 'lib/tvdb2/client.rb', line 52 def refresh_token! response = get('/refresh_token') raise RequestError.new(response) if response.code != 200 @token = response['token'] return @token end |
#with_language(locale) { ... } ⇒ Object
Inside the block change the language in which you want get data.
71 72 73 74 75 76 |
# File 'lib/tvdb2/client.rb', line 71 def with_language(locale, &block) tmp_language = @language @language = locale.to_s block.call(self) @language = tmp_language end |