tmdb_party 0.3.1 → 0.4.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.
- data/README.rdoc +3 -3
- data/VERSION.yml +2 -2
- data/lib/tmdb_party/attributes.rb +0 -1
- data/lib/tmdb_party/genre.rb +21 -0
- data/lib/tmdb_party/image.rb +11 -6
- data/lib/tmdb_party/movie.rb +38 -13
- data/lib/tmdb_party/person.rb +0 -1
- data/lib/tmdb_party.rb +21 -20
- data/test/fixtures/imdb_no_results.json +1 -0
- data/test/fixtures/imdb_search.json +609 -0
- data/test/fixtures/no_groups.json +109 -0
- data/test/fixtures/rad.json +69 -0
- data/test/fixtures/search.json +299 -0
- data/test/fixtures/single_result.json +69 -0
- data/test/fixtures/transformers.json +903 -0
- data/test/test_helper.rb +1 -1
- data/test/tmdb_party/test_tmdb_party.rb +64 -51
- data/tmdb_party.gemspec +9 -9
- metadata +9 -9
- data/test/fixtures/imdb_no_results.xml +0 -8
- data/test/fixtures/imdb_search.xml +0 -26
- data/test/fixtures/no_groups.xml +0 -37
- data/test/fixtures/rad.xml +0 -26
- data/test/fixtures/search.xml +0 -104
- data/test/fixtures/single_groups.xml +0 -132
- data/test/fixtures/single_result.xml +0 -26
- data/test/fixtures/transformers.xml +0 -358
data/README.rdoc
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Simple ruby wrapper to themoviedb.org (http://api.themoviedb.org/2.0/docs/) using HTTParty
|
4
4
|
|
5
5
|
= usage:
|
6
|
-
sudo gem install
|
6
|
+
sudo gem install tmdb_party -s http://gemcutter.org
|
7
7
|
require 'tmdb_party'
|
8
8
|
|
9
9
|
= example:
|
@@ -20,7 +20,7 @@ Simple ruby wrapper to themoviedb.org (http://api.themoviedb.org/2.0/docs/) usin
|
|
20
20
|
# => 31
|
21
21
|
transformers.score
|
22
22
|
# => 1.0
|
23
|
-
transformers.
|
23
|
+
transformers.imdb_id
|
24
24
|
# => 'tt0418279'
|
25
25
|
|
26
26
|
# some attributes don't come back with the search result, they are lazily loaded on demand
|
@@ -29,7 +29,7 @@ Simple ruby wrapper to themoviedb.org (http://api.themoviedb.org/2.0/docs/) usin
|
|
29
29
|
transformers.trailer.url
|
30
30
|
# => "http://www.youtube.com/watch?v=eduwcuq1Exg"
|
31
31
|
|
32
|
-
transformers.
|
32
|
+
transformers.genres.collect{|cat| cat.name}.include?("Adventure")
|
33
33
|
# => true
|
34
34
|
|
35
35
|
= what is themoviedb.org?
|
data/VERSION.yml
CHANGED
@@ -22,7 +22,6 @@ module TMDBParty
|
|
22
22
|
def attribute(name, options)
|
23
23
|
options.replace({:type => 'nil', :lazy=>false}.merge(options))
|
24
24
|
raise "Name can't be empty" if name.blank?
|
25
|
-
|
26
25
|
lazy_load = "self.#{options[:lazy]} unless self.loaded?" if options[:lazy]
|
27
26
|
class_eval <<-EOS
|
28
27
|
def #{name}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module TMDBParty
|
2
|
+
class Genre
|
3
|
+
include Attributes
|
4
|
+
attributes :name, :url
|
5
|
+
|
6
|
+
def initialize(values)
|
7
|
+
self.attributes = values
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.parse(data)
|
11
|
+
return unless data
|
12
|
+
if data.is_a?(Array)
|
13
|
+
data.collect do |g|
|
14
|
+
Genre.new(g)
|
15
|
+
end
|
16
|
+
else
|
17
|
+
[Genre.new(data)]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/tmdb_party/image.rb
CHANGED
@@ -1,18 +1,23 @@
|
|
1
1
|
module TMDBParty
|
2
2
|
class Image
|
3
|
-
attr_reader :url
|
3
|
+
attr_reader :url, :type, :size
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@url = url
|
5
|
+
def initialize(options={})
|
6
|
+
@url = options["url"]
|
7
|
+
@type = options["type"]
|
8
|
+
@size = options["size"]
|
7
9
|
end
|
8
10
|
|
9
11
|
def self.parse(data)
|
12
|
+
puts data.inspect
|
13
|
+
puts
|
14
|
+
puts
|
10
15
|
if data.is_a?(Array)
|
11
|
-
data.collect do |
|
12
|
-
Image.new(
|
16
|
+
data.collect do |image|
|
17
|
+
Image.new(image["image"])
|
13
18
|
end
|
14
19
|
else
|
15
|
-
Image.new(
|
20
|
+
Image.new(image["image"])
|
16
21
|
end
|
17
22
|
end
|
18
23
|
end
|
data/lib/tmdb_party/movie.rb
CHANGED
@@ -3,16 +3,20 @@ module TMDBParty
|
|
3
3
|
include Attributes
|
4
4
|
attr_reader :tmdb
|
5
5
|
|
6
|
-
attributes :
|
7
|
-
attributes :
|
8
|
-
attributes :id, :
|
6
|
+
attributes :name, :overview, :id, :score, :imdb_id, :movie_type, :url, :popularity, :alternative_title
|
7
|
+
attributes :released
|
8
|
+
attributes :id, :type => Integer
|
9
9
|
attributes :popularity, :score, :type => Float
|
10
|
-
attributes :poster, :backdrop, :type => Image
|
11
10
|
|
11
|
+
attributes :posters, :backdrops, :lazy => :get_info!
|
12
12
|
attributes :homepage, :lazy => :get_info!
|
13
|
-
attributes :trailer, :lazy => :get_info
|
14
|
-
attributes :
|
15
|
-
attributes :
|
13
|
+
attributes :trailer, :lazy => :get_info!
|
14
|
+
attributes :runtime, :lazy => :get_info!, :type => Integer
|
15
|
+
attributes :genres, :lazy => :get_info!, :type => Genre
|
16
|
+
attributes :cast, :lazy => :get_info!, :type => Person
|
17
|
+
|
18
|
+
alias_method :flattened_posters, :posters
|
19
|
+
alias_method :flattened_backdrops, :backdrops
|
16
20
|
|
17
21
|
def initialize(values, tmdb)
|
18
22
|
@tmdb = tmdb
|
@@ -26,23 +30,44 @@ module TMDBParty
|
|
26
30
|
end
|
27
31
|
|
28
32
|
def directors
|
29
|
-
|
33
|
+
find_cast('Director')
|
30
34
|
end
|
31
35
|
|
32
36
|
def actors
|
33
|
-
|
37
|
+
find_cast('Actor')
|
34
38
|
end
|
35
39
|
|
36
40
|
def writers
|
37
|
-
|
41
|
+
find_cast('Writer')
|
42
|
+
end
|
43
|
+
|
44
|
+
def posters
|
45
|
+
process_art(flattened_posters)
|
46
|
+
end
|
47
|
+
|
48
|
+
def backdrops
|
49
|
+
process_art(flattened_backdrops)
|
38
50
|
end
|
39
51
|
|
40
52
|
|
41
53
|
private
|
42
54
|
|
43
|
-
def
|
44
|
-
|
45
|
-
|
55
|
+
def process_art(art)
|
56
|
+
image_groups = {}
|
57
|
+
art.each do |image_hash|
|
58
|
+
the_image = image_hash["image"]
|
59
|
+
if image_groups[the_image["id"]]
|
60
|
+
image_groups[the_image["id"]][the_image["size"]] = the_image["url"]
|
61
|
+
else
|
62
|
+
image_groups[the_image["id"]] = {the_image["size"] => the_image["url"]}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
image_groups.values
|
66
|
+
end
|
67
|
+
|
68
|
+
def find_cast(type)
|
69
|
+
return [] unless cast
|
70
|
+
guys = cast.select{|c| c.job == type}
|
46
71
|
end
|
47
72
|
|
48
73
|
end
|
data/lib/tmdb_party/person.rb
CHANGED
data/lib/tmdb_party.rb
CHANGED
@@ -4,7 +4,7 @@ require 'tmdb_party/core_extensions'
|
|
4
4
|
require 'tmdb_party/httparty_icebox'
|
5
5
|
require 'tmdb_party/attributes'
|
6
6
|
require 'tmdb_party/video'
|
7
|
-
require 'tmdb_party/
|
7
|
+
require 'tmdb_party/genre'
|
8
8
|
require 'tmdb_party/person'
|
9
9
|
require 'tmdb_party/image'
|
10
10
|
require 'tmdb_party/movie'
|
@@ -15,39 +15,40 @@ module TMDBParty
|
|
15
15
|
include HTTParty::Icebox
|
16
16
|
cache :store => 'file', :timeout => 120, :location => Dir.tmpdir
|
17
17
|
|
18
|
-
base_uri 'http://api.themoviedb.org/2.
|
19
|
-
format :
|
18
|
+
base_uri 'http://api.themoviedb.org/2.1'
|
19
|
+
format :json
|
20
20
|
|
21
21
|
def initialize(key)
|
22
|
-
|
22
|
+
@api_key = key
|
23
|
+
end
|
24
|
+
|
25
|
+
def default_path_items
|
26
|
+
path_items = ['en']
|
27
|
+
path_items << 'json'
|
28
|
+
path_items << @api_key
|
23
29
|
end
|
24
30
|
|
25
31
|
def search(query)
|
26
|
-
data = self.class.get(
|
27
|
-
|
28
|
-
case data['results']['moviematches']['movie']
|
29
|
-
when Array
|
30
|
-
data['results']['moviematches']['movie'].collect { |movie| Movie.new(movie, self) }
|
31
|
-
when Hash
|
32
|
-
[Movie.new(data['results']['moviematches']['movie'], self)]
|
33
|
-
else
|
32
|
+
data = self.class.get("/Movie.search/" + default_path_items.join('/') + '/' + URI.escape(query))
|
33
|
+
if data.first == "Nothing found."
|
34
34
|
[]
|
35
|
+
else
|
36
|
+
data.collect { |movie| Movie.new(movie, self) }
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
38
40
|
def imdb_lookup(imdb_id)
|
39
|
-
data = self.class.get(
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
Movie.new(data['results']['moviematches']['movie'], self)
|
41
|
+
data = self.class.get("/Movie.imdbLookup/" + default_path_items.join('/') + '/' + imdb_id)
|
42
|
+
if data.first == "Nothing found."
|
43
|
+
nil
|
44
|
+
else
|
45
|
+
Movie.new(data.first, self)
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
49
|
def get_info(id)
|
49
|
-
data = self.class.get(
|
50
|
-
Movie.new(data
|
50
|
+
data = self.class.get("/Movie.getInfo/" + default_path_items.join('/') + '/' + id.to_s)
|
51
|
+
Movie.new(data.first, self)
|
51
52
|
end
|
52
53
|
end
|
53
54
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
["Nothing found."]
|