tmdb

Gem Version

Simple ruby wrapper for The MovieDB based on HTTParty (starting to transform into more of an abstraction than a wrapper: http://wynnnetherland.com/journal/what-makes-a-good-api-wrapper)

Installation

tmdb is hosted at rubygems.org

gem install tmdb

Compatability

I wrote this gem while using ruby 2.0.0, I haven't tested compatability with other versions.

API Coverage

Current available:

  • API
    • ::api_key=
    • ::config
    • ::genres(source)
  • Movie
    • ::search
    • ::advanced_search
    • ::id
    • ::popular
    • #poster(size)
    • #backdrop(size)
  • TV
    • ::search
    • ::id

Todo:

  • Movie
    • ::top_rated
  • TV
    • ::popular
    • ::top_rated
  • People/Person
    • ::id
    • ::search

Examples

API

require 'tmdb'

# Always run API's api_key class method first to set the api key class variable
TMDB::API.api_key = "YOUR_API_KEY"

# Get the configuration data
TMDB::API.config
# => (see http://docs.themoviedb.apiary.io/#configuration)

# Get a hash of genres (for Movies or TV)
TMDB::API.genres
# {28=>"Action", 12=>"Adventure", etc..}
# (Default is for movies)

TMDB::API.genres("tv")
# (for TV)

Movies

Class Methods

# To search for movies by title (returns an array of TMDB:Movie objects)
movies = TMDB::Movie.search('the matrix')
# => <TMDB::Movie "adult"=>false,
  "backdrop_path"=>"/7u3pxc0K1wx32IleAkLv78MKgrw.jpg",
  "id"=>603,
  "original_title"=>"The Matrix",
  "release_date"=>"1999-03-30",
  "poster_path"=>"/gynBNzwyaHKtXqlEKKLioNkjKgN.jpg",
  "popularity"=>10.3021669763687,
  "title"=>"The Matrix",
  "vote_average"=>7.4,
  "vote_count"=>3674> ...

# Then you can pull the data from the results, ie.
movies.first.title
# => "The Matrix"
# Use .advanced_search to find by various parameters (ie. release date)
movies = TMDB::Movie.advanced_search('release_date.gte' => '2014-01-01',
                            'release_date.lte' => (Time.now.strftime("%Y-%m-%d")),
                            primary_release_year: 2014)
# => Array of <TMDB::Movie>s
::id
# To pull all the information for a particular movie, run an id search:
movie = TMDB::Movie.id(550)
# => <Hashie::Mash "adult"=>false,
"backdrop_path"=>"/hNFMawyNDWZKKHU4GYCBz1krsRM.jpg",
"belongs_to_collection"=>nil,
"budget"=>63000000,
"genres"=>
 [{"id"=>28, "name"=>"Action"},
  {"id"=>18, "name"=>"Drama"},
  {"id"=>53, "name"=>"Thriller"}],
"homepage"=>"",
"id"=>550,
"imdb_id"=>"tt0137523",
"original_title"=>"Fight Club",
"overview"=>
 "A ticking-time-bomb insomniac and a slippery soap salesman channel primal male aggression into a shocking new form of therapy. Their concept catches on, with underground \"fight clubs\" forming in every town, until an eccentric gets in the way and ignites an out-of-control spiral toward oblivion."...>
# Use .popular to final recent popular movies (according to The Movie Database)
movies = TMDB::Movie.popular
# => Array of <Hashie::Mash> movies

Instance Methods

#poster
# Use .poster to return a particular TMDB::Movie's poster path, default is 'original'
# Poster Sizes: ["w92", "w154", "w185", "w342", "w500", "w780", "original"]
TMDB::Movie.id(550).poster
# => http://image.tmdb.org/t/p/original/2lECpi35Hnbpa4y46JX0aY3AWTy.jpg
#backdrop
# Same as #poster but for backdrops
# Backdrop Sizes: ["w300", "w780", "w1280", "original"]
TMDB::Movie.id(550).backdrop('w300')
# => http://image.tmdb.org/t/p/w300/hNFMawyNDWZKKHU4GYCBz1krsRM.jpg

TV

Class Methods

# Similar to Movies
TMDB::TV.search(query: 'walking dead')
# => <Hashie::Mash {"backdrop_path"=>"/nGzg3mn3C6fYVE0SvXHmY2XX4P2.jpg",
 "created_by"=>
  [{"id"=>4027,
    "name"=>"Frank Darabont",
    "profile_path"=>"/fLKzpG3J88lPr8y8dCJbcFKN6iX.jpg"}],
 "episode_run_time"=>[60, 45],
 "first_air_date"=>"2010-10-31",
 "genres"=>
  [{"id"=>18, "name"=>"Drama"},
   {"id"=>27, "name"=>"Horror"},
   {"id"=>53, "name"=>"Thriller"}],
 "homepage"=>"http://www.amctv.com/shows/the-walking-dead/",
 "id"=>1402,
 "in_production"=>true,
 "languages"=>["en"],
 "last_air_date"=>"2014-03-30",
 "name"=>"The Walking Dead" ...>

More Examples

You can look through the tests for more examples

Usage

TODO

tmdb is a work in progress and isn't really usable at the moment. It's my first gem so I'm going to take some time working on it

Testing

Make sure to create an 'api_key' file at 'test/api_key' in order to run the tests. I'll work offline testing into the gem later.

Copyright © 2014 Cody Barr. See LICENSE.md for further details.