zimdb 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -0
- data/Rakefile +17 -1
- data/lib/zimdb/movie.rb +5 -2
- data/lib/zimdb/version.rb +1 -1
- data/spec/movie_spec.rb +91 -70
- data/spec/spec_helper.rb +3 -1
- metadata +8 -8
data/README.md
CHANGED
@@ -15,6 +15,11 @@ Now you can do things like this:
|
|
15
15
|
movie.director # => "Todd Phillips"
|
16
16
|
# and more...
|
17
17
|
|
18
|
+
You may also find a movie via its IMDb id:
|
19
|
+
|
20
|
+
movie = Zimdb::Movie.new(:id => "tt0151804")
|
21
|
+
movie.title # => "Office Space"
|
22
|
+
|
18
23
|
Check out [this spec file](https://github.com/indrode/zimdb/blob/master/spec/movie_spec.rb) to see which movie attributes are currently available.
|
19
24
|
|
20
25
|
##License
|
data/Rakefile
CHANGED
@@ -1 +1,17 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
desc 'Default: run specs.'
|
5
|
+
task :default => :spec
|
6
|
+
|
7
|
+
desc "Run specs"
|
8
|
+
RSpec::Core::RakeTask.new do |t|
|
9
|
+
t.pattern = "./spec/**/*_spec.rb" # default behavior
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Generate code coverage"
|
13
|
+
RSpec::Core::RakeTask.new(:coverage) do |t|
|
14
|
+
t.pattern = "./spec/**/*_spec.rb" # default behavior
|
15
|
+
t.rcov = true
|
16
|
+
t.rcov_opts = ['--exclude', 'spec']
|
17
|
+
end
|
data/lib/zimdb/movie.rb
CHANGED
@@ -2,8 +2,11 @@ module Zimdb
|
|
2
2
|
class Movie
|
3
3
|
|
4
4
|
def initialize(params)
|
5
|
-
|
6
|
-
|
5
|
+
@json = params[:id].nil? ? get_movie("t", URI::encode(params[:title])) : get_movie("i", params[:id])
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_movie(param, val)
|
9
|
+
JSON.parse(HTTParty.get("http://www.imdbapi.com/?#{param}=#{val}")).symbolize_keys
|
7
10
|
end
|
8
11
|
|
9
12
|
def response
|
data/lib/zimdb/version.rb
CHANGED
data/spec/movie_spec.rb
CHANGED
@@ -1,77 +1,98 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Zimdb::Movie do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
4
|
+
describe "by movie title" do
|
5
|
+
before(:each) do
|
6
|
+
@movie = Zimdb::Movie.new(:title => "Hangover")
|
7
|
+
@movie.response.should == true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return a false response if not found" do
|
11
|
+
movie2 = Zimdb::Movie.new(:title => "asdasd")
|
12
|
+
movie2.response.should == false
|
13
|
+
movie2.title.should be_nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should allow more than one word in movie title" do
|
17
|
+
movie3 = Zimdb::Movie.new(:title => "The Hangover")
|
18
|
+
movie3.response.should == true
|
19
|
+
movie3.title.should == "The Hangover"
|
20
|
+
movie3.year.should == 2009
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return the title" do
|
24
|
+
@movie.title.should == "The Hangover"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return the year" do
|
28
|
+
@movie.year.should == 2009
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return the rating" do
|
32
|
+
@movie.rated.should == "R"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return the release date" do
|
36
|
+
@movie.released.should == "5 Jun 2009"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return the genre" do
|
40
|
+
@movie.genre.should == "Comedy, Crime"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return the director" do
|
44
|
+
@movie.director.should == "Todd Phillips"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return the writer" do
|
48
|
+
@movie.writer.should == "Jon Lucas, Scott Moore"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return the actors" do
|
52
|
+
@movie.actors.should == "Zach Galifianakis, Bradley Cooper, Justin Bartha, Ed Helms"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return the plot" do
|
56
|
+
@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."
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should return the poster URL" do
|
60
|
+
@movie.poster.should == "http://ia.media-imdb.com/images/M/MV5BMTU1MDA1MTYwMF5BMl5BanBnXkFtZTcwMDcxMzA1Mg@@._V1._SX320.jpg"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return the runtime" do
|
64
|
+
@movie.runtime.should == "1 hr 40 mins"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should return the rating" do
|
68
|
+
@movie.rating.should == 7.9
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should return the number of votes" do
|
72
|
+
@movie.votes.should == 142757
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should return the id" do
|
76
|
+
@movie.imdb_id.should == "tt1119646"
|
77
|
+
end
|
72
78
|
end
|
73
79
|
|
74
|
-
|
75
|
-
|
80
|
+
describe "by IMDB id" do
|
81
|
+
before(:each) do
|
82
|
+
@movie_by_id = Zimdb::Movie.new(:id => "tt0151804")
|
83
|
+
@movie_by_id.response.should == true
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should return the title" do
|
87
|
+
@movie_by_id.title.should == "Office Space"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should return the year" do
|
91
|
+
@movie_by_id.year.should == 1999
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should return the id" do
|
95
|
+
@movie_by_id.imdb_id.should == "tt0151804"
|
96
|
+
end
|
76
97
|
end
|
77
98
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,8 +9,10 @@ RSpec.configure do |config|
|
|
9
9
|
File.dirname(__FILE__) + '/fixtures/' + filename
|
10
10
|
end
|
11
11
|
|
12
|
+
config.color_enabled = true
|
13
|
+
|
12
14
|
FakeWeb.register_uri(:get, "http://www.imdbapi.com/?t=Hangover", :body => open(fixture("hangover.json")))
|
13
15
|
FakeWeb.register_uri(:get, "http://www.imdbapi.com/?t=The%20Hangover", :body => open(fixture("hangover.json")))
|
14
16
|
FakeWeb.register_uri(:get, "http://www.imdbapi.com/?t=asdasd", :body => open(fixture("asdasd.json")))
|
15
|
-
|
17
|
+
FakeWeb.register_uri(:get, "http://www.imdbapi.com/?i=tt0151804", :body => open(fixture("office_space.json")))
|
16
18
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zimdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
16
|
-
requirement: &
|
16
|
+
requirement: &70267884995940 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70267884995940
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70267884994620 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '2.6'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70267884994620
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: fakeweb
|
38
|
-
requirement: &
|
38
|
+
requirement: &70267884993980 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '1.3'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70267884993980
|
47
47
|
description: Access movie information from IMDb via the API offered by http://www.imdbapi.com/
|
48
48
|
email:
|
49
49
|
- indro.de@gmail.com
|