Class: OMDB::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/omdbapi/client.rb

Overview

Client for handling requests to the omdbapi.com API.

See Also:

Instance Method Summary collapse

Instance Method Details

#id(imdb_id, options = {}) ⇒ Hash

Retrieves a movie or show based on its IMDb ID.

Examples:

OMDB.id('tt0944947')

Parameters:

  • imdb_id (String)

    The IMDb ID of the movie or show.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :tomatoes (Boolean)

    Include Rotten Tomatoes ratings.

Returns:



40
41
42
43
44
# 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

#search(title) ⇒ Array, Hash Also known as: find

Search for a movie by its title.

Examples:

OMDB.find('Star Wars')

Parameters:

  • title (String)

    The title of the movie or show to search for.

Returns:



52
53
54
55
56
57
58
59
60
61
# File 'lib/omdbapi/client.rb', line 52

def search(title)
  results = get '/', { s: title }
  if results[:search]
    # Return the title if there is only one result, otherwise return the seach results
    search = results.search
    search.size == 1 ? title(search[0].title) : search
  else
    results
  end
end

#title(title, options = {}) ⇒ Hash

Retrieves a movie or show based on its title.

Examples:

OMDB.title('Game of Thrones')

Parameters:

  • title (String)

    The title of the movie or show.

  • options (Hash) (defaults to: {})

    Options for the title, plot or year.

Options Hash (options):

  • :year (Integer)

    The year of the movie.

  • :plot (String)

    ‘short’ (default), ‘full’

  • :season (Integer)

    The season to retrieve.

  • :episode (Integer)

    The episode to retrieve. Requires the season parameter.

  • :tomatoes (Boolean)

    Include Rotten Tomatoes ratings.

Returns:



23
24
25
26
27
28
29
30
31
# 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