tmdb_party 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
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 jduff-tmdb_party
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.imdb
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.categories.collect{|cat| cat.name}.include?("Adventure Film")
32
+ transformers.genres.collect{|cat| cat.name}.include?("Adventure")
33
33
  # => true
34
34
 
35
35
  = what is themoviedb.org?
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
+ :patch: 0
2
3
  :major: 0
3
- :minor: 3
4
- :patch: 1
4
+ :minor: 4
@@ -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
@@ -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(url)
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 |url|
12
- Image.new(url)
16
+ data.collect do |image|
17
+ Image.new(image["image"])
13
18
  end
14
19
  else
15
- Image.new(data)
20
+ Image.new(image["image"])
16
21
  end
17
22
  end
18
23
  end
@@ -3,16 +3,20 @@ module TMDBParty
3
3
  include Attributes
4
4
  attr_reader :tmdb
5
5
 
6
- attributes :title, :short_overview, :id, :score, :imdb, :type, :url, :popularity, :alternative_title
7
- attributes :release, :type=>DateTime
8
- attributes :id, :runtime, :type => Integer
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!, :type=> Video
14
- attributes :categories, :lazy => :get_info!, :type=> Category
15
- attributes :people, :lazy => :get_info!, :type=> Person
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
- find_people('director')
33
+ find_cast('Director')
30
34
  end
31
35
 
32
36
  def actors
33
- find_people('actor')
37
+ find_cast('Actor')
34
38
  end
35
39
 
36
40
  def writers
37
- find_people('writer')
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 find_people(type)
44
- return [] unless people
45
- people.select{|p| p.job == type}
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
@@ -9,7 +9,6 @@ module TMDBParty
9
9
 
10
10
  def self.parse(data)
11
11
  return unless data
12
- data = data["person"]
13
12
  if data.is_a?(Array)
14
13
  data.collect do |person|
15
14
  Person.new(person)
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/category'
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.0'
19
- format :xml
18
+ base_uri 'http://api.themoviedb.org/2.1'
19
+ format :json
20
20
 
21
21
  def initialize(key)
22
- self.class.default_params :api_key => key
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('/Movie.search', :query=>{:title=>query})
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('/Movie.imdbLookup', :query=>{:imdb_id=>imdb_id})
40
- case data['results']['moviematches']['movie']
41
- when String
42
- return nil
43
- when Hash
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('/Movie.getInfo', :query=>{:id=>id})
50
- Movie.new(data['results']['moviematches']['movie'], self)
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."]