tmdb_party 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1 @@
1
+ ["Nothing found."]
File without changes
File without changes
@@ -0,0 +1,38 @@
1
+ [
2
+ {
3
+ "score": 1,
4
+ "popularity": 3,
5
+ "name": "Megan Fox",
6
+ "id": 19537,
7
+ "biography": "\u003Cb\u003ECareer\u003C/b\u003E\\n \\n",
8
+ "url": "http://www.themoviedb.org/person/19537",
9
+ "profile": [{
10
+ "image": {
11
+ "type": "profile",
12
+ "size": "original",
13
+ "height": 1510,
14
+ "width": 1000,
15
+ "url": "http://i2.themoviedb.org/profiles/845/4be38d2b017a3c35b7000845/megan-fox-original.jpg",
16
+ "id": "4be38d2b017a3c35b7000845"
17
+ }
18
+ }, {
19
+ "image": {
20
+ "type": "profile",
21
+ "size": "profile",
22
+ "height": 279,
23
+ "width": 185,
24
+ "url": "http://i1.themoviedb.org/profiles/845/4be38d2b017a3c35b7000845/megan-fox-profile.jpg",
25
+ "id": "4be38d2b017a3c35b7000845"
26
+ }
27
+ }, {
28
+ "image": {
29
+ "type": "profile",
30
+ "size": "thumb",
31
+ "height": 68,
32
+ "width": 45,
33
+ "url": "http://i2.themoviedb.org/profiles/845/4be38d2b017a3c35b7000845/megan-fox-thumb.jpg",
34
+ "id": "4be38d2b017a3c35b7000845"
35
+ }
36
+ }]
37
+ }
38
+ ]
@@ -1,5 +1,9 @@
1
1
  [{
2
- "studios": [],
2
+ "studios": [{
3
+ "name": "DreamWorks SKG",
4
+ "url": "http:\/\/www.themoviedb.org\/company\/38"
5
+ }],
6
+ "translated": true,
3
7
  "rating": "7.46667",
4
8
  "alternative_name": "The Transformers",
5
9
  "name": "Transformers",
@@ -7,6 +11,10 @@
7
11
  "overview": "The Earth is caught in the middle of an intergalactic war between two races of robots, the heroic Autobots and the evil Decepticons, which are able to change into a variety of objects, including cars, trucks, planes and other technological creations.",
8
12
  "url": "http:\/\/www.themoviedb.org\/movie\/1858",
9
13
  "id": 1858,
14
+ "language": "en",
15
+ "imdb_id": "tt0418279",
16
+ "tagline": "Their war. Our world.",
17
+ "certification": "PG-13",
10
18
  "posters": [{
11
19
  "image": {
12
20
  "size": "original",
@@ -883,7 +891,11 @@
883
891
  "id": "10631",
884
892
  "job": "Special Effects"
885
893
  }],
886
- "countries": [],
894
+ "countries": [{
895
+ "code": "US",
896
+ "name": "United States of America",
897
+ "url": "http://www.themoviedb.org/country/us"
898
+ }],
887
899
  "genres": [{
888
900
  "name": "Action",
889
901
  "url": "http:\/\/themoviedb.org\/encyclopedia\/category\/28"
@@ -899,5 +911,6 @@
899
911
  "budget": 150000000,
900
912
  "movie_type": "movie",
901
913
  "revenue": 708226810,
902
- "popularity": 52
914
+ "popularity": 52,
915
+ "last_modified_at": "2010-05-07 15:53:59"
903
916
  }]
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe TMDBParty::CastMember do
4
+ let :cast_member do
5
+ {
6
+ "name" => "Megan Fox",
7
+ "profile" => "http://images.themoviedb.org/profiles/598/meghan_thumb.jpg",
8
+ "character" => "Mikaela Banes",
9
+ "url" => "http://www.themoviedb.org/person/19537",
10
+ "id" => "19537",
11
+ "job" => "Actor"
12
+ }
13
+ end
14
+
15
+ let(:megan) { TMDBParty::CastMember.new(cast_member, TMDBParty::Base.new('key')) }
16
+
17
+ it "should have an id" do
18
+ megan.id.should == 19537
19
+ end
20
+
21
+ it "should have a name" do
22
+ megan.name.should == "Megan Fox"
23
+ end
24
+
25
+ it "should have a url" do
26
+ megan.url.should == "http://www.themoviedb.org/person/19537"
27
+ end
28
+
29
+ it "should have a character name" do
30
+ megan.character_name.should == "Mikaela Banes"
31
+ end
32
+
33
+ it "should have a image url" do
34
+ megan.image_url.should == "http://images.themoviedb.org/profiles/598/meghan_thumb.jpg"
35
+ end
36
+
37
+ it "should have a job" do
38
+ megan.job.should == 'Actor'
39
+ end
40
+
41
+ it "should have a person" do
42
+ stub_get('/Person.getInfo/en/json/key/19537', 'megan_fox.json')
43
+ megan.person.should be_instance_of(TMDBParty::Person)
44
+ end
45
+
46
+ it ".parse should return an array" do
47
+ tmdb = TMDBParty::Base.new('key')
48
+ TMDBParty::CastMember.parse(cast_member, tmdb).should be_instance_of(Array)
49
+ TMDBParty::CastMember.parse(cast_member, tmdb).first.should be_instance_of(TMDBParty::CastMember)
50
+ end
51
+
52
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe TMDBParty::Country do
4
+ let :country do
5
+ { "code" => "US", "name" => "United States of America", "url" => "http://www.themoviedb.org/country/us" }
6
+ end
7
+
8
+ it "should have a code" do
9
+ TMDBParty::Country.new(country).code.should == :us
10
+ end
11
+
12
+ it "should have a name" do
13
+ TMDBParty::Country.new(country).name.should == 'United States of America'
14
+ end
15
+
16
+ it "should have a url" do
17
+ TMDBParty::Country.new(country).url.should == 'http://www.themoviedb.org/country/us'
18
+ end
19
+
20
+ it ".parse should return an array" do
21
+ TMDBParty::Country.parse(country).should be_instance_of(Array)
22
+ TMDBParty::Country.parse(country).first.should be_instance_of(TMDBParty::Country)
23
+ end
24
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe TMDBParty::Image do
4
+ let :single_image do
5
+ {
6
+ "image" => {
7
+ "size" => "original", "url" => "http://images.themoviedb.org/backdrops/35222/Transformers_4.jpg", "type" => "backdrop", "id" => 35222
8
+ }
9
+ }
10
+ end
11
+
12
+ let :image_collection do
13
+ [
14
+ {
15
+ "image" => {
16
+ "size" => "original", "url" => "http://images.themoviedb.org/backdrops/35222/Transformers_4.jpg", "type" => "backdrop", "id" => 35222
17
+ }
18
+ },
19
+ {
20
+ "image" => {
21
+ "size" => "poster", "url" => "http://images.themoviedb.org/backdrops/35222/Transformers_4_poster.jpg", "type" => "backdrop", "id" => 35222
22
+ }
23
+ },
24
+ {
25
+ "image" => {
26
+ "size" => "thumb", "url" => "http://images.themoviedb.org/backdrops/35222/Transformers_4_thumb.jpg", "type" => "backdrop", "id" => 35222
27
+ }
28
+ },
29
+ ]
30
+ end
31
+
32
+ it "should have an id" do
33
+ TMDBParty::Image.parse(image_collection).first.id.should == 35222
34
+ end
35
+
36
+ it "should have a type" do
37
+ TMDBParty::Image.parse(image_collection).first.type.should == :backdrop
38
+ end
39
+
40
+ it "should have a set of sizes" do
41
+ TMDBParty::Image.parse(image_collection).first.sizes.should == [:original, :poster, :thumb].to_set
42
+ end
43
+
44
+ it "should have an url for all the sizes" do
45
+ image = TMDBParty::Image.parse(image_collection).first
46
+
47
+ image.original_url.should =~ /_4.jpg$/
48
+ image.poster_url.should =~ /_poster.jpg$/
49
+ image.thumb_url.should =~ /_thumb.jpg$/
50
+ end
51
+
52
+ it "#url should be an alias for #original_url" do
53
+ TMDBParty::Image.parse(image_collection).first.url.should =~ /_4.jpg$/
54
+ end
55
+
56
+ it "should have nil urls for sizes which the image doesn't have" do
57
+ image = TMDBParty::Image.parse(image_collection.reject { |img| img['image']['size'] == 'thumb' }).first
58
+
59
+ image.thumb_url.should be_nil
60
+ end
61
+
62
+ it ".parse should merge images by id and return them as an array" do
63
+ images = %w[original thumb].product([1, 2]).map do |size, id|
64
+ { "image" => single_image['image'].merge('size' => size, 'url' => "/#{size}.jpg", 'id' => id) }
65
+ end
66
+
67
+ parsed = TMDBParty::Image.parse(images)
68
+
69
+ parsed.should have(2).items
70
+ parsed.first.should be_instance_of(TMDBParty::Image)
71
+ end
72
+
73
+ end
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+ require 'httparty'
3
+
4
+ describe TMDBParty::Movie do
5
+ before(:each) do
6
+ stub_get('/Movie.getInfo/en/json/key/1858', 'transformers.json')
7
+ end
8
+
9
+ let :transformers do
10
+ HTTParty::Parser.call(fixture_file('transformers.json'), :json).first
11
+ end
12
+
13
+ let :transformers_movie do
14
+ TMDBParty::Movie.new(transformers, TMDBParty::Base.new('key'))
15
+ end
16
+
17
+ it "should take an attributes hash and a TMDBParty::Base instance when initialized" do
18
+ expect { TMDBParty::Movie.new({}, TMDBParty::Base.new('key')) }.to_not raise_error
19
+ end
20
+
21
+ describe "attributes" do
22
+ it "should have a score when coming from search results" do
23
+ TMDBParty::Movie.new({'score' => '0.374527342'}, TMDBParty::Base.new('key')).score.should == 0.374527342
24
+ end
25
+
26
+ [:posters, :backdrops, :homepage, :trailer, :runtime, :genres, :cast, :countries, :tagline, :studios].each do |attribute|
27
+ it "should load #{attribute} attribute by looking up the movie if it is missing" do
28
+ movie = TMDBParty::Movie.new({ 'id' => 1858 }, TMDBParty::Base.new('key'))
29
+ movie.send(attribute).should_not be_nil
30
+ end
31
+
32
+ it "should not look up the movie when #{attribute} is not missing" do
33
+ tmdb = mock(TMDBParty::Base)
34
+ movie = TMDBParty::Movie.new({ 'id' => 1858, attribute.to_s => transformers[attribute.to_s] }, tmdb)
35
+
36
+ tmdb.should_not_receive(:get_info)
37
+ movie.send(attribute)
38
+ end
39
+ end
40
+
41
+ it "should have a release date" do
42
+ transformers_movie.released.should == Date.new(2007, 7, 4)
43
+ end
44
+
45
+ it "should have a translated? attribute" do
46
+ transformers_movie.should be_translated
47
+ end
48
+
49
+ it "should have a language" do
50
+ transformers_movie.language.should == :en
51
+ end
52
+
53
+ it "should have a tagline" do
54
+ transformers_movie.tagline.should == "Their war. Our world."
55
+ end
56
+
57
+ it "should have a certification" do
58
+ transformers_movie.certification.should == "PG-13"
59
+ end
60
+
61
+ it "should have a last modified at timestamp" do
62
+ transformers_movie.last_modified_at.should == Time.parse('2010-05-07 22:53:59 UTC')
63
+ end
64
+
65
+ it "should have a cast" do
66
+ transformers_movie.cast.should have(36).members
67
+ transformers_movie.cast.first.should be_instance_of(TMDBParty::CastMember)
68
+ end
69
+
70
+ it "should have a list of directors" do
71
+ transformers_movie.directors.map { |p| p.name }.should == ['Michael Bay']
72
+ end
73
+
74
+ it "should have a list of actors" do
75
+ transformers_movie.should have(17).actors
76
+ end
77
+
78
+ it "should have a list of writers" do
79
+ transformers_movie.writers.should == []
80
+ end
81
+
82
+ it "should have a list of poster images" do
83
+ transformers_movie.should have(10).posters
84
+ poster = transformers_movie.posters.first
85
+ poster.sizes.should include(:cover, :thumb, :mid, :original)
86
+ end
87
+
88
+ it "should have a list of backdrop images" do
89
+ transformers_movie.should have(11).backdrops
90
+ backdrop = transformers_movie.backdrops.first
91
+ backdrop.sizes.should include(:thumb, :poster, :original)
92
+ end
93
+
94
+ it "should have a list of genres" do
95
+ transformers_movie.should have(3).genres
96
+ transformers_movie.genres.map { |g| g.name }.should include('Action', 'Adventure', 'Science Fiction')
97
+ end
98
+
99
+ it "should have a list of countries" do
100
+ transformers_movie.should have(1).countries
101
+ transformers_movie.countries.first.url.should == 'http://www.themoviedb.org/country/us'
102
+ end
103
+
104
+ it "should have a list of studios" do
105
+ transformers_movie.should have(1).studios
106
+ transformers_movie.studios.first.name.should == 'DreamWorks SKG'
107
+ end
108
+ end
109
+
110
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe TMDBParty::Person do
4
+ let :person do
5
+ HTTParty::Parser.call(fixture_file('megan_fox.json'), :json).first
6
+ end
7
+
8
+ let(:megan) { TMDBParty::Person.new(person, TMDBParty::Base.new('key')) }
9
+
10
+ describe "attributes" do
11
+ it "should have a score when coming from search results" do
12
+ TMDBParty::Person.new({'score' => '0.374527342'}, TMDBParty::Base.new('key')).score.should == 0.374527342
13
+ end
14
+
15
+ it "should have an id" do
16
+ megan.id.should == 19537
17
+ end
18
+
19
+ it "should have a name" do
20
+ megan.name.should == "Megan Fox"
21
+ end
22
+
23
+ it "should have a popularity" do
24
+ megan.popularity.should == 3
25
+ end
26
+
27
+ it "should have a url" do
28
+ megan.url.should == "http://www.themoviedb.org/person/19537"
29
+ end
30
+
31
+ it "should have a biography" do
32
+ megan.biography.should be_a(String)
33
+ end
34
+
35
+ it "should have a birthplace" do
36
+ megan.birthplace.should == "Oakridge, TN"
37
+ end
38
+
39
+ it "should have a birthday" do
40
+ megan.birthday.should == Date.new(1986, 5, 16)
41
+ end
42
+
43
+ describe "biography" do
44
+ it "should have proper newlines" do
45
+ megan.biography.should include("\n")
46
+ end
47
+
48
+ it "should properly get HTML tags" do
49
+ # HTTParty does not parse the encoded hexadecimal properly. It does not consider 000F to be a hex, but 000f is
50
+ megan.biography.should include("<b>Career</b>")
51
+ end
52
+ end
53
+ end
54
+
55
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe TMDBParty::Studio do
4
+ let :studio do
5
+ { "name" => "Paramount Pictures", "url" => "http://www.themoviedb.org/company/4" }
6
+ end
7
+
8
+ it "should have a name" do
9
+ TMDBParty::Studio.new(studio).name.should == 'Paramount Pictures'
10
+ end
11
+
12
+ it "should have a url" do
13
+ TMDBParty::Studio.new(studio).url.should == 'http://www.themoviedb.org/company/4'
14
+ end
15
+
16
+ it ".parse should return an array" do
17
+ TMDBParty::Studio.parse(studio).should be_instance_of(Array)
18
+ TMDBParty::Studio.parse(studio).first.should be_instance_of(TMDBParty::Studio)
19
+ end
20
+ end
@@ -0,0 +1,103 @@
1
+ require 'spec_helper'
2
+
3
+ describe TMDBParty::Base do
4
+ it "should take an api key when initialized" do
5
+ expect { TMDBParty::Base.new('key') }.to_not raise_error
6
+ end
7
+
8
+ it "should take an optional preferred language when initialized" do
9
+ expect { TMDBParty::Base.new('key', 'sv') }.to_not raise_error
10
+ end
11
+
12
+ let :tmdb do
13
+ TMDBParty::Base.new('key')
14
+ end
15
+
16
+ describe "#search" do
17
+ it "should return an empty array when no matches was found" do
18
+ stub_get('/Movie.search/en/json/key/NothingFound', 'nothing_found.json')
19
+ tmdb.search('NothingFound').should == []
20
+ end
21
+
22
+ it "should return an array of movies" do
23
+ stub_get('/Movie.search/en/json/key/Transformers', 'search.json')
24
+ tmdb.search('Transformers').should have(5).movies
25
+ tmdb.search('Transformers').first.should be_instance_of(TMDBParty::Movie)
26
+ end
27
+
28
+ it "should use the preferred language" do
29
+ stub_get('/Movie.search/en/json/key/Transformers', 'shitty_shit_result.json')
30
+ stub_get('/Movie.search/sv/json/key/Transformers', 'search.json')
31
+
32
+ TMDBParty::Base.new('key', 'sv').search('Transformers').should have(5).movies
33
+ end
34
+ end
35
+
36
+ describe "#imdb_lookup" do
37
+ it "should return nil when no movie could be found" do
38
+ stub_get('/Movie.imdbLookup/en/json/key/tt0418279dd', 'imdb_no_results.json')
39
+ tmdb.imdb_lookup('tt0418279dd').should be_nil
40
+ end
41
+
42
+ it "should return a single movie when found" do
43
+ stub_get('/Movie.imdbLookup/en/json/key/tt0418279', 'imdb_search.json')
44
+ tmdb.imdb_lookup('tt0418279').should be_instance_of(TMDBParty::Movie)
45
+ end
46
+
47
+ it "should use the preferred language" do
48
+ stub_get('/Movie.imdbLookup/en/json/key/tt0418279', 'shitty_shit_result.json')
49
+ stub_get('/Movie.imdbLookup/sv/json/key/tt0418279', 'imdb_search.json')
50
+
51
+ TMDBParty::Base.new('key', 'sv').imdb_lookup('tt0418279').should_not be_nil
52
+ end
53
+ end
54
+
55
+ describe "#get_info" do
56
+ it "should return a movie instance" do
57
+ stub_get('/Movie.getInfo/en/json/key/1858', 'transformers.json')
58
+ tmdb.get_info(1858).should be_instance_of(TMDBParty::Movie)
59
+ end
60
+
61
+ it "should use the preferred language" do
62
+ stub_get('/Movie.getInfo/en/json/key/1858', 'shitty_shit_result.json')
63
+ stub_get('/Movie.getInfo/sv/json/key/1858', 'transformers.json')
64
+
65
+ TMDBParty::Base.new('key', 'sv').get_info(1858).should_not be_nil
66
+ end
67
+ end
68
+
69
+ describe "#search_person" do
70
+ it "should return empty array when no people was found" do
71
+ stub_get('/Person.search/en/json/key/Megatron%20Fox', 'nothing_found.json')
72
+ tmdb.search_person('Megatron Fox').should be_empty
73
+ end
74
+
75
+ it "should return instances of Person" do
76
+ stub_get('/Person.search/en/json/key/Megan%20Fox', 'search_person.json')
77
+ tmdb.search_person('Megan Fox').should have(1).person
78
+ tmdb.search_person('Megan Fox').first.should be_instance_of(TMDBParty::Person)
79
+ end
80
+
81
+ it "should use the preferred language" do
82
+ stub_get('/Person.search/en/json/key/Megan%20Fox', 'shitty_shit_result.json')
83
+ stub_get('/Person.search/sv/json/key/Megan%20Fox', 'search_person.json')
84
+
85
+ TMDBParty::Base.new('key', 'sv').search_person('Megan Fox').should have(1).movie
86
+ end
87
+ end
88
+
89
+ describe "#get_person" do
90
+ it "should return a person instance" do
91
+ stub_get('/Person.getInfo/en/json/key/19537', 'megan_fox.json')
92
+ tmdb.get_person(19537).should be_instance_of(TMDBParty::Person)
93
+ end
94
+
95
+ it "should use the preferred language" do
96
+ stub_get('/Person.getInfo/en/json/key/19537', 'shitty_shit_result.json')
97
+ stub_get('/Person.getInfo/sv/json/key/19537', 'megan_fox.json')
98
+
99
+ TMDBParty::Base.new('key', 'sv').get_person(19537).name.should == 'Megan Fox'
100
+ end
101
+ end
102
+
103
+ end