class SimpleTheMovieDB::Client
Constants
- BASE_URL
Attributes
api_key[R]
Public Class Methods
new(api_key)
click to toggle source
# File lib/simple_themoviedb.rb, line 10 def initialize(api_key) @api_key = api_key end
Public Instance Methods
get_cast(id)
click to toggle source
# File lib/simple_themoviedb.rb, line 48 def get_cast(id) url = "/movie/#{id}/casts?" get_and_parse(url) end
get_configuration()
click to toggle source
# File lib/simple_themoviedb.rb, line 31 def get_configuration url = '/configuration?' get_and_parse(url) end
get_images(id)
click to toggle source
# 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)
click to toggle source
# File lib/simple_themoviedb.rb, line 36 def get_movie(id, lang = nil) url = "/movie/#{id}?" options = { api_key: @api_key } options = options.merge(language: lang) if lang get_and_parse(url, options) end
get_person(id)
click to toggle source
# File lib/simple_themoviedb.rb, line 53 def get_person(id) url = "/person/#{id}?" get_and_parse(url) end
get_person_credits(id)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/simple_themoviedb.rb, line 14 def search(title, adult = nil) url = '/search/movie?' options = { query: title, api_key: @api_key } options = options.merge(include_adult: adult) if adult response = get_and_parse(url, options) total_pages = response['total_pages'] return unless total_pages && total_pages.is_a?(Integer) (2..total_pages).inject(response['results']) do |res, page| options[:page] = page page_results = get_and_parse(url, options)['results'] || [] res + page_results end end
Private Instance Methods
get_and_parse(url, options = { api_key: @api_key })
click to toggle source
# File lib/simple_themoviedb.rb, line 70 def get_and_parse(url, options = { api_key: @api_key }) response = HTTParty.get( BASE_URL + url + to_query(options), headers: { 'accept' => 'applcation/json' }, format: :json ) response.parsed_response end
to_query(options)
click to toggle source
# File lib/simple_themoviedb.rb, line 80 def to_query(options) options.map do |key, value| "#{key}=#{value}" end.join('&') end