Class: SimpleTheMovieDB::Client
- Inherits:
-
Object
- Object
- SimpleTheMovieDB::Client
- Defined in:
- lib/simple_themoviedb.rb
Constant Summary collapse
- BASE_URL =
'http://api.themoviedb.org/3'.freeze
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Instance Method Summary collapse
- #get_cast(id) ⇒ Object
- #get_configuration ⇒ Object
- #get_images(id) ⇒ Object
- #get_movie(id, lang = nil) ⇒ Object
- #get_person(id) ⇒ Object
- #get_person_credits(id) ⇒ Object
- #get_person_images(id) ⇒ Object
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
- #search(title, adult = nil) ⇒ Object
Constructor Details
#initialize(api_key) ⇒ Client
Returns a new instance of Client.
10 11 12 |
# File 'lib/simple_themoviedb.rb', line 10 def initialize(api_key) @api_key = api_key end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/simple_themoviedb.rb', line 6 def api_key @api_key end |
Instance Method Details
#get_cast(id) ⇒ Object
48 49 50 51 |
# File 'lib/simple_themoviedb.rb', line 48 def get_cast(id) url = "/movie/#{id}/casts?" get_and_parse(url) end |
#get_configuration ⇒ Object
31 32 33 34 |
# File 'lib/simple_themoviedb.rb', line 31 def get_configuration url = '/configuration?' get_and_parse(url) end |
#get_images(id) ⇒ Object
43 44 45 46 |
# File 'lib/simple_themoviedb.rb', line 43 def get_images(id) url = "/movie/#{id}/images?" get_and_parse(url) end |
#get_movie(id, lang = nil) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/simple_themoviedb.rb', line 36 def get_movie(id, lang = nil) url = "/movie/#{id}?" = { api_key: @api_key } = .merge(language: lang) if lang get_and_parse(url, ) end |
#get_person(id) ⇒ Object
53 54 55 56 |
# File 'lib/simple_themoviedb.rb', line 53 def get_person(id) url = "/person/#{id}?" get_and_parse(url) end |
#get_person_credits(id) ⇒ Object
63 64 65 66 |
# File 'lib/simple_themoviedb.rb', line 63 def get_person_credits(id) url = "/person/#{id}/credits?" get_and_parse(url) end |
#get_person_images(id) ⇒ Object
58 59 60 61 |
# File 'lib/simple_themoviedb.rb', line 58 def get_person_images(id) url = "/person/#{id}/images?" get_and_parse(url) end |
#search(title, adult = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/simple_themoviedb.rb', line 14 def search(title, adult = nil) url = '/search/movie?' = { query: title, api_key: @api_key } = .merge(include_adult: adult) if adult response = get_and_parse(url, ) total_pages = response['total_pages'] return unless total_pages && total_pages.is_a?(Integer) (2..total_pages).inject(response['results']) do |res, page| [:page] = page page_results = get_and_parse(url, )['results'] || [] res + page_results end end |