devroom.io/drafts/2009-06-03-ruby-gem-imdb.md

60 lines
1.8 KiB
Markdown
Raw Normal View History

2013-03-22 22:53:57 +00:00
---
title: "Ruby Gem: IMDB"
kind: article
slug: ruby-gem-imdb
created_at: 2009-06-03
tags:
- General
- Ruby
- imdb
- gem
- api
---
I just released version 0.1.0 of my IMDB gem which allows your app to search IMDB for IMDB movie ID's and access most data that's publicly available.
## Installation
sudo gem install imdb
This will also install the dependencies Hpricot and HTTParty.
## Usage
In your project, include the gem (and possibly rubygems as well).
:::ruby
require 'rubygems'
require 'imdb'
search = Imdb::Search.new('Star Trek')
=> #<Imdb::Search:0x18289e8 @query="Star Trek">
puts search.movies[0..3].collect{ |m| [m.id, m.title].join(" - ") }.join("\n")
=> 0060028 - "Star Trek" (1966) (TV series)
0796366 - Star Trek (2009)
0092455 - "Star Trek: The Next Generation" (1987) (TV series)
0112178 - "Star Trek: Voyager" (1995) (TV series)
st = Imdb::Movie.new("0796366")
=> #<Imdb::Movie:0x16ff904 @url="http://www.imdb.com/title/tt0796366/", @id="0796366", @title=nil>
st.title
=> "Star Trek"
st.year
=> 2009
st.rating
=> 8.4
st.cast_members[0..2].join(", ")
=> "Chris Pine, Zachary Quinto, Leonard Nimoy"
As you can see, both `Imdb::Search` and `Imdb::Movie` are lazy loading, only doing a HTTP request when you actually request data. Also, the remote HTTP data is cached trhough-out the life span of your Imdb::Movie object.
## Documentation
Generated RDoc documentation can be found at [http://ariejan.github.com/imdb/][1].
[1]: http://ariejan.github.com/imdb/
## Issues, feature requests, patches, the works
Please use <a href="https://github.com/ariejan/imdb">https://github.com/ariejan/imdb</a> to supply patches (preferably through a pull-request) and to report issues.