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

59 lines
1.8 KiB
Markdown
Raw Normal View History

2017-03-20 15:35:19 +00:00
+++
date = "2009-06-03"
title = "Ruby Gem: IMDB"
tags = ["General", "Ruby", "imdb", "gem", "api"]
slug = "ruby-gem-imdb"
+++
2015-03-26 11:28:08 +00:00
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
2017-03-20 15:35:19 +00:00
``` shell
sudo gem install imdb
```
2015-03-26 11:28:08 +00:00
This will also install the dependencies Hpricot and HTTParty.
## Usage
In your project, include the gem (and possibly rubygems as well).
2017-03-20 15:35:19 +00:00
``` ruby
require 'rubygems'
require 'imdb'
2015-03-26 11:28:08 +00:00
2017-03-20 15:35:19 +00:00
search = Imdb::Search.new('Star Trek')
=> #<Imdb::Search:0x18289e8 @query="Star Trek">
2015-03-26 11:28:08 +00:00
2017-03-20 15:35:19 +00:00
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)
2015-03-26 11:28:08 +00:00
2017-03-20 15:35:19 +00:00
st = Imdb::Movie.new("0796366")
=> #<Imdb::Movie:0x16ff904 @url="http://www.imdb.com/title/tt0796366/", @id="0796366", @title=nil>
2015-03-26 11:28:08 +00:00
2017-03-20 15:35:19 +00:00
st.title
=> "Star Trek"
st.year
=> 2009
st.rating
=> 8.4
st.cast_members[0..2].join(", ")
=> "Chris Pine, Zachary Quinto, Leonard Nimoy"
```
2015-03-26 11:28:08 +00:00
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
2017-03-20 15:35:19 +00:00
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.