Module: TMDb
- Extended by:
- TMDb
- Included in:
- TMDb
- Defined in:
- lib/tmdb.rb,
lib/tmdb/person.rb,
lib/tmdb/version.rb,
lib/tmdb/attributes.rb,
lib/tmdb/null_cache.rb,
lib/tmdb/configuration.rb
Defined Under Namespace
Modules: Attributes Classes: Configuration, NullCache, Person
Constant Summary collapse
- VERSION =
'0.3.1'
Instance Method Summary collapse
-
#configuration ⇒ Object
Returns the global TMDb configuration.
-
#configure {|configuration| ... } ⇒ Object
Configure TMDb by calling this method.
-
#get_api_response(path, params = {}) ⇒ Object
Makes a TMDb API request given to the (relative)
pathwith the given queryparamsand using the configured API key.
Instance Method Details
#configuration ⇒ Object
Returns the global TMDb configuration.
5 6 7 |
# File 'lib/tmdb.rb', line 5 def configuration @configuration ||= Configuration.new end |
#configure {|configuration| ... } ⇒ Object
Configure TMDb by calling this method.
10 11 12 |
# File 'lib/tmdb.rb', line 10 def configure yield configuration end |
#get_api_response(path, params = {}) ⇒ Object
Makes a TMDb API request given to the (relative) path with the given query params and using the configured API key. Returns the response as a hash (parsed from the original JSON). This method is not intended to be called directly by client code, instead you should call methods such as Person.find that return TMDb wrapper objects.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tmdb.rb', line 19 def get_api_response(path, params = {}) configuration.cache.fetch([path, params]) do connection = Faraday.new(:url => 'http://api.themoviedb.org/3/') do |builder| builder.request :url_encoded builder.adapter :net_http end response = connection.get( path, params.merge({ :api_key => TMDb.configuration.api_key }) ) JSON.parse(response.body) end end |