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

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