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 +4 -0
- data/README.rdoc +4 -0
- data/allocine_parser.gemspec +1 -1
- data/lib/allocine_parser.rb +1 -0
- data/lib/allocine_parser/allocine_base.rb +40 -4
- data/lib/allocine_parser/person.rb +63 -0
- data/lib/allocine_parser/version.rb +1 -1
- data/script/console +2 -2
- data/spec/allocine/movie_spec.rb +12 -8
- data/spec/spec_helper.rb +3 -3
- metadata +7 -6
data/History.txt
CHANGED
data/README.rdoc
CHANGED
data/allocine_parser.gemspec
CHANGED
data/lib/allocine_parser.rb
CHANGED
@@ -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
|
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
|
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
|
+
|
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
|
-
|
10
|
-
libs << " -r /
|
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"
|
data/spec/allocine/movie_spec.rb
CHANGED
@@ -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
|
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.
|
30
|
-
@movie.
|
31
|
-
@movie.
|
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
|
-
|
6
|
+
# gem 'rspec'
|
7
|
+
require 'spec'
|
8
8
|
end
|
9
9
|
|
10
10
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
11
|
-
require '
|
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.
|
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:
|
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: &
|
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: *
|
25
|
+
version_requirements: *2151962540
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rspec
|
28
|
-
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: *
|
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
|