class OMDB::Client

Client for handling requests to the omdbapi.com API.

@see omdbapi.com

Public Instance Methods

find(title)
Alias for: search
id(imdb_id, options = {}) click to toggle source

Retrieves a movie or show based on its IMDb ID.

@param imdb_id [String] The IMDb ID of the movie or show. @option options [Boolean] :tomatoes Include Rotten Tomatoes ratings. @return [Hash] @example

OMDB.id('tt0944947')
# File lib/omdbapi/client.rb, line 40
def id(imdb_id, options = {})
  params = { i: imdb_id }
  params[:tomatoes] = options[:tomatoes] if options[:tomatoes]
  get '/', params
end
title(title, options = {}) click to toggle source

Retrieves a movie or show based on its title.

@param title [String] The title of the movie or show. @param options [Hash] Options for the title, plot or year. @option options [Integer] :year The year of the movie. @option options [String] :plot ‘short’ (default), ‘full’ @option options [Integer] :season The season to retrieve. @option options [Integer] :episode The episode to retrieve. Requires the season parameter. @option options [Boolean] :tomatoes Include Rotten Tomatoes ratings. @return [Hash] @example

OMDB.title('Game of Thrones')
# File lib/omdbapi/client.rb, line 23
def title(title, options = {})
  params = { t: title }
  params[:y] = options[:year] if options[:year]
  params[:plot] = options[:plot] if options[:plot]
  params[:season] = options[:season] if options[:season]
  params[:episode] = options[:episode] if options[:episode]
  params[:tomatoes] = options[:tomatoes] if options[:tomatoes]
  get '/', params
end

Private Instance Methods

build_params(title, options) click to toggle source

Build parameters for a request.

@param title [String] The title of the show. @param options [Hash] The optional parameters. @return [Hash]

# File lib/omdbapi/client.rb, line 87
def build_params(title, options)
  params = { t: title }
  params[:y] = options[:year] if options[:year]
  params
end
convert_hash_keys(value) click to toggle source

Performs a method on all hash keys.

@param value [Array, Hash, Object] @return [Array, Hash, Object]

# File lib/omdbapi/client.rb, line 71
def convert_hash_keys(value)
  case value
  when Array
    value.map { |v| convert_hash_keys(v) }
  when Hash
    Hash[value.map { |k, v| [k.to_snake_case.to_sym, convert_hash_keys(v)] }]
  else
    value
  end
end
get(url, params={}) click to toggle source

Performs a get request.

@param url [String] The url to perform the get request to. @param params [Hash] The parameters to pass in the query string. @return [Hash] The response from the get request. @example

get '/users', { username: 'caseyscarborough' }
# File lib/omdbapi/client.rb, line 100
def get(url, params={})
  request = self.class.get '/', query: params
  convert_hash_keys(request.parsed_response)
end