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 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 "bundler/gem_tasks"
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
@@ -2,8 +2,11 @@ module Zimdb
2
2
  class Movie
3
3
 
4
4
  def initialize(params)
5
- title = URI::encode(params[:title])
6
- @json = JSON.parse(HTTParty.get("http://www.imdbapi.com/?t=#{title}")).symbolize_keys
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
@@ -1,3 +1,3 @@
1
1
  module Zimdb
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,77 +1,98 @@
1
1
  require 'spec_helper'
2
2
 
3
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 allow more than one word in movie title" do
16
- movie3 = Zimdb::Movie.new(:title => "The Hangover")
17
- movie3.response.should == true
18
- movie3.title.should == "The Hangover"
19
- movie3.year.should == 2009
20
- end
21
-
22
- it "should return the title" do
23
- @movie.title.should == "The Hangover"
24
- end
25
-
26
- it "should return the year" do
27
- @movie.year.should == 2009
28
- end
29
-
30
- it "should return the rating" do
31
- @movie.rated.should == "R"
32
- end
33
-
34
- it "should return the release date" do
35
- @movie.released.should == "5 Jun 2009"
36
- end
37
-
38
- it "should return the genre" do
39
- @movie.genre.should == "Comedy, Crime"
40
- end
41
-
42
- it "should return the director" do
43
- @movie.director.should == "Todd Phillips"
44
- end
45
-
46
- it "should return the writer" do
47
- @movie.writer.should == "Jon Lucas, Scott Moore"
48
- end
49
-
50
- it "should return the actors" do
51
- @movie.actors.should == "Zach Galifianakis, Bradley Cooper, Justin Bartha, Ed Helms"
52
- end
53
-
54
- it "should return the plot" do
55
- @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."
56
- end
57
-
58
- it "should return the poster URL" do
59
- @movie.poster.should == "http://ia.media-imdb.com/images/M/MV5BMTU1MDA1MTYwMF5BMl5BanBnXkFtZTcwMDcxMzA1Mg@@._V1._SX320.jpg"
60
- end
61
-
62
- it "should return the runtime" do
63
- @movie.runtime.should == "1 hr 40 mins"
64
- end
65
-
66
- it "should return the rating" do
67
- @movie.rating.should == 7.9
68
- end
69
-
70
- it "should return the number of votes" do
71
- @movie.votes.should == 142757
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
- it "should return the id" do
75
- @movie.imdb_id.should == "tt1119646"
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
@@ -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.2
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-11-17 00:00:00.000000000 Z
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: &70313887340500 !ruby/object:Gem::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: *70313887340500
24
+ version_requirements: *70267884995940
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70313887338240 !ruby/object:Gem::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: *70313887338240
35
+ version_requirements: *70267884994620
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: fakeweb
38
- requirement: &70313887316060 !ruby/object:Gem::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: *70313887316060
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