Class: Enceladus::Configuration::Api
- Inherits:
-
Object
- Object
- Enceladus::Configuration::Api
- Includes:
- Singleton
- Defined in:
- lib/enceladus/configuration/api.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#include_adult ⇒ Object
Returns the value of attribute include_adult.
-
#language ⇒ Object
Returns the value of attribute language.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#connect(api_key) ⇒ Object
Fetches the TMDb account configuration.
-
#initialize ⇒ Api
constructor
:nodoc:#.
-
#url_for(action, params = {}) ⇒ Object
Returns a string with a URL for one of TMDb API endpoints.
Constructor Details
#initialize ⇒ Api
:nodoc:#
11 12 13 14 15 16 |
# File 'lib/enceladus/configuration/api.rb', line 11 def initialize #:nodoc:# self.base_url = "https://api.themoviedb.org".freeze self.version = "3".freeze self.include_adult = false self.language = "en" end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/enceladus/configuration/api.rb', line 8 def api_key @api_key end |
#base_url ⇒ Object
Returns the value of attribute base_url.
8 9 10 |
# File 'lib/enceladus/configuration/api.rb', line 8 def base_url @base_url end |
#include_adult ⇒ Object
Returns the value of attribute include_adult.
9 10 11 |
# File 'lib/enceladus/configuration/api.rb', line 9 def include_adult @include_adult end |
#language ⇒ Object
Returns the value of attribute language.
9 10 11 |
# File 'lib/enceladus/configuration/api.rb', line 9 def language @language end |
#version ⇒ Object
Returns the value of attribute version.
8 9 10 |
# File 'lib/enceladus/configuration/api.rb', line 8 def version @version end |
Instance Method Details
#connect(api_key) ⇒ Object
Fetches the TMDb account configuration. This method hits the following TMDb endpoints:
Once the request has succeeded, Enceladus will populate the following Enceladus::Configuration::Image attributes: base_url, secure_base_url, backdrop_sizes, logo_sizes, poster_sizes, profile_sizes and still_sizes.
A failing request will reset/nullify all those mentioned attributes.
Return a boolean indicating whether the request has succeeded or not.
Examples:
Enceladus::Configuration::Api.instance.connect("cceebf51cb1f8d707d10a132d9544b76")
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/enceladus/configuration/api.rb', line 33 def connect(api_key) begin self.api_key = api_key Enceladus::Configuration::Image.instance.setup! true rescue Enceladus::Exception::Api self.api_key = nil Enceladus::Configuration::Image.instance.reset! false end end |
#url_for(action, params = {}) ⇒ Object
Returns a string with a URL for one of TMDb API endpoints. Examples:
Enceladus::Configuration::Api.instance.url_for("movies", { term: "Lola Benvenutti" })
=> https://api.themoviedb.org/3/movies?term=Lola+Benvenutti&api_key=token
51 52 53 54 55 56 |
# File 'lib/enceladus/configuration/api.rb', line 51 def url_for(action, params={}) params[:api_key] = api_key url = URI.join(base_url, "/#{version}/", action) url.query = URI.encode_www_form(params) url.to_s end |