Created
August 2, 2013 19:18
-
-
Save jvanbaarsen/6142607 to your computer and use it in GitHub Desktop.
Omdb example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'omdb' | |
# Search for all movies with a name like 'Broken City' | |
movies = Omdb::Api.new.search('Broken city') | |
puts movies[:status] # => 200 | |
puts movies[:movies].size # => 3 | |
# Get the title of the first movie from the search results | |
puts movies[:movies].first.title # => Broken City | |
# Fetch the movie 'Broken City' and call some methods on the Omdb::Movie object | |
broken_city = Omdb::Api.new.fetch('Broken City') | |
puts broken_city[:status] # => 200 | |
puts broken_city[:movie].director # => Allen Hughes | |
puts broken_city[:movie].imdb_id # => tt1235522 | |
# Error handling: | |
# --- | |
# Searching for non existing movie | |
movies = Omdb::Api.new.search('Non Existing movie name') | |
puts movies[:status] # => 404 | |
# Fetching non existing movie | |
movie = Omdb::Api.new.fetch('Non Existing movie name') | |
puts movie[:status] # => 404 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment