filmbuff 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History +6 -0
- data/{readme.markdown → README.md} +19 -1
- data/lib/filmbuff/imdb.rb +5 -15
- data/lib/filmbuff/version.rb +1 -1
- data/spec/filmbuff/imdb_spec.rb +8 -18
- data/spec/filmbuff/title_spec.rb +99 -35
- metadata +3 -3
data/History
CHANGED
@@ -41,9 +41,27 @@ If you know the movie's IMDb ID you can get the information as well:
|
|
41
41
|
movie.rating => 8.3
|
42
42
|
movie.genres => ["Adventure", "Comedy", "Family", "Fantasy", "Musical"]
|
43
43
|
|
44
|
+
To retrieve information in a different language, set the instance variable locale to your wanted locale:
|
45
|
+
|
46
|
+
imdb.locale = "de_DE"
|
47
|
+
movie = imdb.find_by_id("tt0032138")
|
48
|
+
|
49
|
+
movie.title => "Das zauberhafte Land"
|
50
|
+
movie.rating => 8.3
|
51
|
+
movie.genres => ["Abenteuer", "Komödie", "Familie", "Fantasy", "Musical"]
|
52
|
+
|
53
|
+
Supported locales are
|
54
|
+
|
55
|
+
- de_DE (German)
|
56
|
+
- en_US (English) (Default)
|
57
|
+
- es_ES (Spanish)
|
58
|
+
- fr_FR (French)
|
59
|
+
- it_IT (Italian)
|
60
|
+
- pt_PT (Portuguese)
|
61
|
+
|
44
62
|
## Authors
|
45
63
|
|
46
|
-
* [Kristoffer Sachse](
|
64
|
+
* [Kristoffer Sachse](https://github.com/sachse)
|
47
65
|
|
48
66
|
## Contribute
|
49
67
|
|
data/lib/filmbuff/imdb.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module FilmBuff
|
2
2
|
class IMDb
|
3
|
-
|
3
|
+
attr_accessor :locale
|
4
4
|
|
5
5
|
include HTTParty
|
6
6
|
include HTTParty::Icebox
|
@@ -10,7 +10,6 @@ module FilmBuff
|
|
10
10
|
default_params = {
|
11
11
|
"api" => "v1",
|
12
12
|
"app_id" => "iphone1_1",
|
13
|
-
"locale" => @locale,
|
14
13
|
"timestamp" => Time.now.utc.to_i,
|
15
14
|
"sig" => "app1_1"
|
16
15
|
}
|
@@ -20,26 +19,17 @@ module FilmBuff
|
|
20
19
|
end
|
21
20
|
|
22
21
|
public
|
23
|
-
def locale=(locale)
|
24
|
-
locales = %w[ de_DE en_US es_ES fr_FR it_IT pt_PT ]
|
25
|
-
|
26
|
-
if locales.include? locale
|
27
|
-
@locale = locale
|
28
|
-
else
|
29
|
-
raise "Unknown locale. Only the following are allowed:\n" <<
|
30
|
-
locales.join(", ")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
22
|
def find_by_id(imdb_id)
|
35
23
|
result = self.class.get('/title/maindetails', :query => {
|
36
|
-
tconst: imdb_id
|
24
|
+
tconst: imdb_id, locale: @locale
|
37
25
|
}).parsed_response
|
38
26
|
Title.new(result["data"])
|
39
27
|
end
|
40
28
|
|
41
29
|
def find_by_title(title)
|
42
|
-
results = self.class.get('/find', :query => {
|
30
|
+
results = self.class.get('/find', :query => {
|
31
|
+
q: title, locale: @locale
|
32
|
+
}).parsed_response
|
43
33
|
find_by_id(results["data"]["results"][0]["list"][0]["tconst"])
|
44
34
|
end
|
45
35
|
end
|
data/lib/filmbuff/version.rb
CHANGED
data/spec/filmbuff/imdb_spec.rb
CHANGED
@@ -12,29 +12,19 @@ describe FilmBuff::IMDb do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "#locale=" do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@imdb.locale.should == "de_DE"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context "given invalid locale" do
|
23
|
-
it "raises an exception" do
|
24
|
-
lambda { @imdb.locale = "da_DK" }.should raise_error StandardError
|
25
|
-
end
|
15
|
+
it "sets locale to the given value" do
|
16
|
+
@imdb.locale = "de_DE"
|
17
|
+
@imdb.locale.should == "de_DE"
|
26
18
|
end
|
27
19
|
end
|
28
20
|
|
29
21
|
describe "#find_by_id" do
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
22
|
+
before(:all) do
|
23
|
+
@title = @imdb.find_by_id("tt0032138")
|
24
|
+
end
|
34
25
|
|
35
|
-
|
36
|
-
|
37
|
-
end
|
26
|
+
it "returns a Title" do
|
27
|
+
@title.instance_of?(FilmBuff::Title).should be_true
|
38
28
|
end
|
39
29
|
end
|
40
30
|
|
data/spec/filmbuff/title_spec.rb
CHANGED
@@ -1,51 +1,115 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
|
2
3
|
|
3
4
|
describe FilmBuff::Title do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
context "given no locale" do
|
6
|
+
before(:all) do
|
7
|
+
@imdb = FilmBuff::IMDb.new
|
8
|
+
@title = @imdb.find_by_id("tt0032138")
|
9
|
+
end
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
it "has an IMDb ID" do
|
12
|
+
@title.imdb_id.should == "tt0032138"
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
it "has a title" do
|
16
|
+
@title.title.should == "The Wizard of Oz"
|
17
|
+
end
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
it "has a tagline" do
|
20
|
+
@title.tagline.should == "\"The Wizard\" Musical Returns By " <<
|
21
|
+
"Unprecedented Demand! [UK re-release]"
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
it "has a plot" do
|
25
|
+
@title.plot.should == "Dorothy Gale is swept away to a magical land in " <<
|
26
|
+
"a tornado and embarks on a quest to see the Wizard who can help her " <<
|
27
|
+
"return home."
|
28
|
+
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
it "has a runtime" do
|
31
|
+
@title.runtime.should == "101 min"
|
32
|
+
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
it "has a rating" do
|
35
|
+
@title.rating.should be_a(Float)
|
36
|
+
end
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
it "has an amount of votes" do
|
39
|
+
@title.votes.should be_a(Integer)
|
40
|
+
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
42
|
+
it "has a poster URL" do
|
43
|
+
@title.poster_url.should match /http:\/\/ia.media-imdb.com\/images\/.*/
|
44
|
+
end
|
45
|
+
|
46
|
+
it "has genres" do
|
47
|
+
@title.genres.should == %w[ Adventure Comedy Family Fantasy Musical]
|
48
|
+
end
|
43
49
|
|
44
|
-
|
45
|
-
|
50
|
+
it "has a release date" do
|
51
|
+
@title.release_date.should == DateTime.parse("1939-08-25")
|
52
|
+
end
|
46
53
|
end
|
47
54
|
|
48
|
-
|
49
|
-
|
55
|
+
context "given locale" do
|
56
|
+
before(:all) do
|
57
|
+
@imdb = FilmBuff::IMDb.new
|
58
|
+
end
|
59
|
+
|
60
|
+
context "\"de_DE\"" do
|
61
|
+
before(:all) do
|
62
|
+
@imdb.locale = "de_DE"
|
63
|
+
@title = @imdb.find_by_id("tt0032138")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns German information" do
|
67
|
+
@title.title.should == "Das zauberhafte Land"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "\"es_ES\"" do
|
72
|
+
before(:all) do
|
73
|
+
@imdb.locale = "es_ES"
|
74
|
+
@title = @imdb.find_by_id("tt0032138")
|
75
|
+
end
|
76
|
+
|
77
|
+
it "returns Spanish information" do
|
78
|
+
@title.title.should == "El mago de Oz"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "\"fr_FR\"" do
|
83
|
+
before(:all) do
|
84
|
+
@imdb.locale = "fr_FR"
|
85
|
+
@title = @imdb.find_by_id("tt0032138")
|
86
|
+
end
|
87
|
+
|
88
|
+
it "returns French information" do
|
89
|
+
@title.title.should == "Le magicien d'Oz"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "\"it_IT\"" do
|
94
|
+
before(:all) do
|
95
|
+
@imdb.locale = "it_IT"
|
96
|
+
@title = @imdb.find_by_id("tt0032138")
|
97
|
+
end
|
98
|
+
|
99
|
+
it "returns Italian information" do
|
100
|
+
@title.title.should == "Il mago di Oz"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "\"pt_PT\"" do
|
105
|
+
before(:all) do
|
106
|
+
@imdb.locale = "pt_PT"
|
107
|
+
@title = @imdb.find_by_id("tt0032138")
|
108
|
+
end
|
109
|
+
|
110
|
+
it "returns Spanish information" do
|
111
|
+
@title.title.should == "O Feiticeiro de Oz"
|
112
|
+
end
|
113
|
+
end
|
50
114
|
end
|
51
115
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: filmbuff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kristoffer Sachse
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-07 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- Gemfile
|
50
50
|
- History
|
51
51
|
- LICENSE
|
52
|
+
- README.md
|
52
53
|
- Rakefile
|
53
54
|
- filmbuff.gemspec
|
54
55
|
- lib/filmbuff.rb
|
@@ -56,7 +57,6 @@ files:
|
|
56
57
|
- lib/filmbuff/imdb.rb
|
57
58
|
- lib/filmbuff/title.rb
|
58
59
|
- lib/filmbuff/version.rb
|
59
|
-
- readme.markdown
|
60
60
|
- spec/filmbuff/imdb_spec.rb
|
61
61
|
- spec/filmbuff/title_spec.rb
|
62
62
|
- spec/filmbuff_spec.rb
|