allocine_parser 1.5.0 → 1.5.1

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/History.txt CHANGED
@@ -5,3 +5,7 @@
5
5
  == 1.5.0 2011-11-06
6
6
 
7
7
  * Add Serie, Season, Episode [mlamarque]
8
+
9
+ == 1.5.1 2011-11-06
10
+
11
+ * Doc [mlamarque]
data/README.rdoc CHANGED
@@ -14,6 +14,10 @@ Allocine currently features the following:
14
14
 
15
15
  == SYNOPSIS:
16
16
 
17
+ SEARCH:
18
+
19
+ search = Allocine::Search.new("Superman")
20
+
17
21
  Movies:
18
22
 
19
23
  i = Allocine::Movie.new("20754")
@@ -4,7 +4,7 @@ require "allocine/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "allocine_parser"
7
- s.version = Allocine::VERSION
7
+ s.version = "1.5.1"
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Matthieu Lamarque"]
10
10
  s.email = ["lamarque.matthieu@gmail.com"]
@@ -13,3 +13,4 @@ require 'allocine_parser/version'
13
13
  require 'allocine_parser/serie'
14
14
  require 'allocine_parser/season'
15
15
  require 'allocine_parser/episode'
16
+ require 'allocine_parser/person'
@@ -3,7 +3,8 @@ module Allocine
3
3
  require 'rubygems'
4
4
  require 'json'
5
5
  require 'net/http'
6
-
6
+
7
+ #m= Allocine::Movie.new(20754)
7
8
  # Represents a AllocineBase
8
9
  class AllocineBase
9
10
  attr_accessor :id, :url, :title
@@ -14,15 +15,51 @@ module Allocine
14
15
  end
15
16
 
16
17
  # Returns the name of the director
17
- def directors
18
+ def directors_name
18
19
  document["castingShort"]["directors"].split(", ") rescue nil
19
20
  end
21
+
22
+ # Returns directors
23
+ def directors
24
+ directors = []
25
+ directors_ids.each do |id|
26
+ directors << Allocine::Person.new(id)
27
+ end
28
+ directors
29
+ end
30
+
31
+ # Returns ids of directors
32
+ def directors_ids
33
+ directors_ids = []
34
+ directors_name.each_with_index do |director, index|
35
+ directors_ids << document["castMember"][index]["person"]["code"] if director == document["castMember"][index]["person"]["name"]
36
+ end
37
+ directors_ids
38
+ end
20
39
 
21
40
  # Returns an array with cast members
22
- def actors
41
+ def actors_name
23
42
  document["castingShort"]["actors"].split(", ") rescue nil
24
43
  end
25
44
 
45
+ # Returns ids of actors (major)
46
+ def actors_ids
47
+ actors_ids = []
48
+ actors_name.each_with_index do |actor, index|
49
+ actors_ids << document["castMember"][directors_name.size + index]["person"]["code"] if actor == document["castMember"][directors_name.size + index]["person"]["name"]
50
+ end
51
+ actors_ids
52
+ end
53
+
54
+ # Returns actors
55
+ def actors
56
+ actors = []
57
+ actors_ids.each do |id|
58
+ actors << Allocine::Person.new(id)
59
+ end
60
+ actors
61
+ end
62
+
26
63
  # Returns an array of genres (as strings)
27
64
  def genres
28
65
  document["genre"].collect {|gender| gender["$"]} rescue nil
@@ -77,7 +114,6 @@ module Allocine
77
114
  document["originalTitle"] rescue nil
78
115
  end
79
116
 
80
-
81
117
  # Returns release date for the movie.
82
118
  def release_date
83
119
  document["release"]["releaseDate"] rescue nil
@@ -0,0 +1,63 @@
1
+ module Allocine
2
+
3
+ class Person
4
+
5
+ # s = Allocine::Person.new(41339)
6
+ # e = s.name
7
+
8
+ def initialize(allocine_id, title = nil)
9
+ @id = allocine_id
10
+ @url = "http://api.allocine.fr/rest/v3/person?partner=YW5kcm9pZC12M3M&profile=large&code=#{allocine_id}&format=json"
11
+ end
12
+
13
+ # Returns name of person
14
+ def name
15
+ document["name"]["given"] + " " +document["name"]["family"] rescue nil
16
+ end
17
+
18
+ # Returns nationality of person
19
+ def nationality
20
+ document["nationality"].collect {|nation| nation["$"]} rescue nil
21
+ end
22
+
23
+ # Returns gender of person
24
+ def gender
25
+ # 1 => male
26
+ # 0 => female
27
+ document["gender"] rescue nil
28
+ end
29
+
30
+ # Returns activities of person
31
+ def activity_short
32
+ document["activityShort"] rescue nil
33
+ end
34
+
35
+ # Returns biography of person
36
+ def biography(short = true)
37
+ short == true ? document["biographyShort"] : document["biography"] rescue nil
38
+ end
39
+
40
+ # Returns birth_date of person
41
+ def birth_date
42
+ document["birthDate"] rescue nil
43
+ end
44
+
45
+ # Returns picture of person
46
+ def picture
47
+ document["picture"]["href"] rescue nil
48
+ end
49
+
50
+ private
51
+
52
+ def document
53
+ @document ||= Allocine::Person.find_by_id(@id)
54
+ end
55
+
56
+ def self.find_by_id(allocine_id)
57
+ url = "http://api.allocine.fr/rest/v3/person?partner=YW5kcm9pZC12M3M&profile=large&code=#{allocine_id}&format=json"
58
+ JSON.parse(Net::HTTP.get_response(URI.parse(url)).body)["person"]
59
+ end
60
+
61
+ end
62
+ end
63
+
@@ -1,3 +1,3 @@
1
1
  module Allocine
2
- VERSION = '1.5.0'
2
+ VERSION = '1.5.2'
3
3
  end
data/script/console CHANGED
@@ -6,7 +6,7 @@ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
6
6
  require "awesome_print"
7
7
 
8
8
  libs = " -r irb/completion"
9
- # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
10
- libs << " -r /Users/matthieu/Dev/rails/perso/allocine/lib/allocine_api.rb"
9
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
10
+ #libs << " -r /path.../allocine/lib/allocine.rb"
11
11
  puts "Loading allocine gem"
12
12
  exec "#{irb} #{libs} --simple-prompt"
@@ -17,20 +17,24 @@ describe "Allocine::Movie" do
17
17
 
18
18
  it "should find the cast members" do
19
19
  cast = @movie.actors
20
-
21
20
  cast.should be_an(Array)
22
- cast.should include("Liam Neeson")
23
- cast.should include("Natalie Portman")
24
- cast.should include("Jake Lloyd")
25
- cast.should include("Ian McDiarmid")
21
+ cast.first.name.should =~ /Liam Neeson/
26
22
  end
27
23
 
28
24
  it "should find the directors" do
29
- @movie.directors.should be_an(Array)
30
- @movie.directors.size.should eql(1)
31
- @movie.directors.first.should =~ /George Lucas/
25
+ @movie.directors_name.should be_an(Array)
26
+ @movie.directors_name.size.should eql(1)
27
+ @movie.directors_name.first.should =~ /George Lucas/
32
28
  end
33
29
 
30
+ it "should find the directors" do
31
+ cast = @movie.directors
32
+ cast.should be_an(Array)
33
+ cast.first.name.should =~ /George Lucas/
34
+ cast.first.birth_date.should =~ /1944-05-14/
35
+ cast.first.gender.should =~ /1/
36
+ end
37
+
34
38
  it "should find the genres" do
35
39
  genres = @movie.genres
36
40
  genres.should be_an(Array)
data/spec/spec_helper.rb CHANGED
@@ -3,12 +3,12 @@ begin
3
3
  require 'spec'
4
4
  rescue LoadError
5
5
  require 'rubygems'
6
- gem 'rspec'
7
- # require 'spec'
6
+ # gem 'rspec'
7
+ require 'spec'
8
8
  end
9
9
 
10
10
  $:.unshift(File.dirname(__FILE__) + '/../lib')
11
- require 'allocine'
11
+ require 'allocine_parser'
12
12
 
13
13
  def read_fixture(path)
14
14
  File.read(File.expand_path(File.join(File.dirname(__FILE__), "fixtures", path)))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: allocine_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-06 00:00:00.000000000 +01:00
12
+ date: 2013-03-13 00:00:00.000000000 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rdoc
17
- requirement: &2165201360 !ruby/object:Gem::Requirement
17
+ requirement: &2151962540 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *2165201360
25
+ version_requirements: *2151962540
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec
28
- requirement: &2165200860 !ruby/object:Gem::Requirement
28
+ requirement: &2151960300 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: 1.3.2
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *2165200860
36
+ version_requirements: *2151960300
37
37
  description: Easily use Ruby to find information on allocine API.
38
38
  email:
39
39
  - lamarque.matthieu@gmail.com
@@ -53,6 +53,7 @@ files:
53
53
  - lib/allocine_parser/episode.rb
54
54
  - lib/allocine_parser/movie.rb
55
55
  - lib/allocine_parser/movie_list.rb
56
+ - lib/allocine_parser/person.rb
56
57
  - lib/allocine_parser/search.rb
57
58
  - lib/allocine_parser/season.rb
58
59
  - lib/allocine_parser/serie.rb