zimdb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in zimdb.gemspec
4
+ gemspec
@@ -0,0 +1,25 @@
1
+ ##What is ZIMDb?
2
+
3
+ Unfortunately, the #1 movie resource website IMDb does not provide a public API for developers. However, there are a bunch of services that can help us out, such as [http://www.imdbapi.com/](http://www.imdbapi.com/) by Brian Fritz. ZIMDb is a simple API wrapper for the imdbapi.com service written in and for Ruby.
4
+
5
+ Install the gem and require it, or add it to you`Gemfile` in Rails.
6
+
7
+ gem install zimdb
8
+
9
+ Now you can do things like this:
10
+
11
+ movie = Zimdb::Movie.new(:title => "The Hangover")
12
+ movie.title # => "The Hangover"
13
+ movie.year # => 2009
14
+ movie.genre # => "Comedy, Crime"
15
+ movie.director # => "Todd Phillips"
16
+ # and more...
17
+
18
+
19
+ Copyright (c) 2011 Indro De
20
+
21
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
22
+
23
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
24
+
25
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,16 @@
1
+ require "rubygems"
2
+ require "httparty"
3
+ require "json"
4
+ require "zimdb/version"
5
+ require "zimdb/hash"
6
+ require "zimdb/movie"
7
+
8
+ module Zimdb
9
+ include HTTParty
10
+
11
+ base_uri 'http://www.imdbapi.com'
12
+
13
+ def self.version_string
14
+ "Zimdb version #{Zimdb::VERSION}"
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ class Hash
2
+ def symbolize_keys
3
+ t = self.dup
4
+ self.clear
5
+ t.each_pair{|k, v| self[k.downcase.to_sym] = v}
6
+ self
7
+ end
8
+ end
@@ -0,0 +1,68 @@
1
+ module Zimdb
2
+ class Movie
3
+
4
+ def initialize(params)
5
+ @json = JSON.parse(HTTParty.get("http://www.imdbapi.com/?t=#{params[:title]}")).symbolize_keys
6
+ end
7
+
8
+ def response
9
+ @json[:response] == "True" ? true : false
10
+ end
11
+
12
+ def year
13
+ @json[:year].to_i
14
+ end
15
+
16
+ def title
17
+ @json[:title]
18
+ end
19
+
20
+ def rated
21
+ @json[:rated]
22
+ end
23
+
24
+ def released
25
+ @json[:released]
26
+ end
27
+
28
+ def genre
29
+ @json[:genre]
30
+ end
31
+
32
+ def director
33
+ @json[:director]
34
+ end
35
+
36
+ def writer
37
+ @json[:writer]
38
+ end
39
+
40
+ def actors
41
+ @json[:actors]
42
+ end
43
+
44
+ def plot
45
+ @json[:plot]
46
+ end
47
+
48
+ def poster
49
+ @json[:poster]
50
+ end
51
+
52
+ def runtime
53
+ @json[:runtime]
54
+ end
55
+
56
+ def rating
57
+ @json[:rating].to_f
58
+ end
59
+
60
+ def votes
61
+ @json[:votes].to_i
62
+ end
63
+
64
+ def imdb_id
65
+ @json[:id]
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ module Zimdb
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ {"Response":"Parse Error"}
@@ -0,0 +1 @@
1
+ {"Title"=>"The Hangover", "Year"=>"2009", "Rated"=>"R", "Released"=>"5 Jun 2009", "Genre"=>"Comedy, Crime", "Director"=>"Todd Phillips", "Writer"=>"Jon Lucas, Scott Moore", "Actors"=>"Zach Galifianakis, Bradley Cooper, Justin Bartha, Ed Helms", "Plot"=>"A Las Vegas-set comedy centered around three groomsmen who lose their about-to-be-wed buddy during their drunken misadventures, then must retrace their steps in order to find him.", "Poster"=>"http://ia.media-imdb.com/images/M/MV5BMTU1MDA1MTYwMF5BMl5BanBnXkFtZTcwMDcxMzA1Mg@@._V1._SX320.jpg", "Runtime"=>"1 hr 40 mins", "Rating"=>"7.9", "Votes"=>"142757", "ID"=>"tt1119646", "Response"=>"True"}
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hash do
4
+ it "should symbolize keys" do
5
+ hash_with_string_keys = { "Title" => "The Hangover", "Year" => "2009" }
6
+ hash_with_string_keys.symbolize_keys
7
+ hash_with_string_keys.should == { :title => "The Hangover", :year => "2009" }
8
+ end
9
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zimdb::Movie do
4
+ before(:each) do
5
+ @movie = Zimdb::Movie.new(:title => "Hangover")
6
+ @movie.response.should == true
7
+ end
8
+
9
+ it "should return a false response if not found" do
10
+ movie2 = Zimdb::Movie.new(:title => "asdasd")
11
+ movie2.response.should == false
12
+ movie2.title.should be_nil
13
+ end
14
+
15
+ it "should return the title" do
16
+ @movie.title.should == "The Hangover"
17
+ end
18
+
19
+ it "should return the title" do
20
+ @movie.year.should == 2009
21
+ end
22
+
23
+ it "should return the rating" do
24
+ @movie.rated.should == "R"
25
+ end
26
+
27
+ it "should return the release date" do
28
+ @movie.released.should == "5 Jun 2009"
29
+ end
30
+
31
+ it "should return the genre" do
32
+ @movie.genre.should == "Comedy, Crime"
33
+ end
34
+
35
+ it "should return the director" do
36
+ @movie.director.should == "Todd Phillips"
37
+ end
38
+
39
+ it "should return the writer" do
40
+ @movie.writer.should == "Jon Lucas, Scott Moore"
41
+ end
42
+
43
+ it "should return the actors" do
44
+ @movie.actors.should == "Zach Galifianakis, Bradley Cooper, Justin Bartha, Ed Helms"
45
+ end
46
+
47
+ it "should return the plot" do
48
+ @movie.plot.should == "A Las Vegas-set comedy centered around three groomsmen who lose their about-to-be-wed buddy during their drunken misadventures, then must retrace their steps in order to find him."
49
+ end
50
+
51
+ it "should return the poster URL" do
52
+ @movie.poster.should == "http://ia.media-imdb.com/images/M/MV5BMTU1MDA1MTYwMF5BMl5BanBnXkFtZTcwMDcxMzA1Mg@@._V1._SX320.jpg"
53
+ end
54
+
55
+ it "should return the runtime" do
56
+ @movie.runtime.should == "1 hr 40 mins"
57
+ end
58
+
59
+ it "should return the rating" do
60
+ @movie.rating.should == 7.9
61
+ end
62
+
63
+ it "should return the number of votes" do
64
+ @movie.votes.should == 142757
65
+ end
66
+
67
+ it "should return the id" do
68
+ @movie.imdb_id.should == "tt1119646"
69
+ end
70
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'zimdb'
4
+ require 'fakeweb'
5
+
6
+ RSpec.configure do |config|
7
+ def fixture(filename)
8
+ File.dirname(__FILE__) + '/fixtures/' + filename
9
+ end
10
+
11
+ FakeWeb.register_uri(:get, "http://www.imdbapi.com/?t=hangover", :body => open(fixture("hangover.json")).read)
12
+ FakeWeb.register_uri(:get, "http://www.imdbapi.com/?t=hangover", :body => open(fixture("asdasd.json")).read)
13
+
14
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zimdb do
4
+ it 'should return the correct version string' do
5
+ Zimdb.version_string.should == "Zimdb version #{Zimdb::VERSION}"
6
+ end
7
+
8
+ it 'should have a base_uri' do
9
+ Zimdb.base_uri.should eql('http://www.imdbapi.com')
10
+ end
11
+ end
@@ -0,0 +1,50 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "zimdb/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "zimdb"
7
+ s.version = Zimdb::VERSION
8
+ s.authors = ["Indro De"]
9
+ s.email = ["indro.de@gmail.com"]
10
+ #s.homepage = "http://ms.indrode.com/i/zimdb"
11
+ s.homepage = "https://github.com/indrode/zimdb"
12
+ s.summary = %q{Wrapper for imdbapi.com}
13
+ s.description = %q{Access movie information from IMDb via the API offered by http://www.imdbapi.com/}
14
+
15
+ s.rubyforge_project = "zimdb"
16
+
17
+ s.files = [
18
+ ".gitignore",
19
+ "Gemfile",
20
+ "README.md",
21
+ "Rakefile",
22
+ "zimdb.gemspec",
23
+ "lib/zimdb.rb",
24
+ "lib/zimdb/hash.rb",
25
+ "lib/zimdb/movie.rb",
26
+ "lib/zimdb/version.rb",
27
+ "spec/fixtures/asdasd.json",
28
+ "spec/fixtures/hangover.json",
29
+ "spec/hash_spec.rb",
30
+ "spec/movie_spec.rb",
31
+ "spec/spec_helper.rb",
32
+ "spec/zimdb_spec.rb"
33
+ ]
34
+ s.test_files = [
35
+ "spec/hash_spec.rb",
36
+ "spec/movie_spec.rb",
37
+ "spec/spec_helper.rb",
38
+ "spec/zimdb_spec.rb"
39
+ ]
40
+
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = Zimdb::VERSION
43
+
44
+ # specify any dependencies here; for example:
45
+ # s.add_development_dependency "rspec"
46
+ s.add_runtime_dependency "httparty"
47
+ s.add_development_dependency "rspec", "~> 2.6"
48
+ s.add_development_dependency "fakeweb", "~> 1.3"
49
+
50
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zimdb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Indro De
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &70158706211160 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70158706211160
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70158706210620 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '2.6'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70158706210620
36
+ - !ruby/object:Gem::Dependency
37
+ name: fakeweb
38
+ requirement: &70158706187320 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '1.3'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70158706187320
47
+ description: Access movie information from IMDb via the API offered by http://www.imdbapi.com/
48
+ email:
49
+ - indro.de@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - README.md
57
+ - Rakefile
58
+ - zimdb.gemspec
59
+ - lib/zimdb.rb
60
+ - lib/zimdb/hash.rb
61
+ - lib/zimdb/movie.rb
62
+ - lib/zimdb/version.rb
63
+ - spec/fixtures/asdasd.json
64
+ - spec/fixtures/hangover.json
65
+ - spec/hash_spec.rb
66
+ - spec/movie_spec.rb
67
+ - spec/spec_helper.rb
68
+ - spec/zimdb_spec.rb
69
+ homepage: https://github.com/indrode/zimdb
70
+ licenses: []
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project: zimdb
89
+ rubygems_version: 1.8.10
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Wrapper for imdbapi.com
93
+ test_files:
94
+ - spec/hash_spec.rb
95
+ - spec/movie_spec.rb
96
+ - spec/spec_helper.rb
97
+ - spec/zimdb_spec.rb