allocine_api 1.0.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
1
  == 0.0.1 2011-11-05
2
2
 
3
3
  * First release of the Allocine gem. [mlamarque]
4
+
5
+ == 1.5.0 2011-11-06
6
+
7
+ * Add Serie, Season, Episode [mlamarque]
@@ -22,12 +22,31 @@ Movies:
22
22
  #=> "Star Wars : Episode I - La Menace fantôme"
23
23
 
24
24
 
25
+ Serie:
26
+
27
+ i = Allocine::Serie.new(223)
28
+ i.title
29
+ #=> "Lost, les disparus"
30
+
31
+
32
+ Season:
33
+
34
+ i = Allocine::Season.new(12277)
35
+ i.episode_ids
36
+ #=> [233014, 233015, 233016, 233017, 233018, 233019, 233020, 233021, 233022, 233023, 233024, 233025, 233026, 233027, 233028, 233029, 233030, 247699]
37
+
38
+ Episode:
39
+
40
+ s = Allocine::Episode.new(233014)
41
+ s.title
42
+ #=> "On efface tout"
43
+
25
44
  == TESTING:
26
45
 
27
46
  You'll need rspec installed to run the specs.
28
47
 
29
48
  $ bundle install
30
- $ rspec spec/imdb/movie_spec.rb
49
+ $ rspec spec
31
50
 
32
51
  == LICENSE:
33
52
 
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Matthieu Lamarque"]
10
10
  s.email = ["lamarque.matthieu@gmail.com"]
11
11
  s.homepage = "http://github.com/mlamarque/allocine"
12
- s.summary = %q{Easily access the publicly available information on Allocine website.}
13
- s.description = %q{Easily use Ruby to find information on allocine website.}
12
+ s.summary = %q{Easily access the API information on Allocine API.}
13
+ s.description = %q{Easily use Ruby to find information on allocine API.}
14
14
 
15
15
  s.rubyforge_project = "allocine"
16
16
 
@@ -11,3 +11,6 @@ require 'allocine/movie'
11
11
  require 'allocine/movie_list'
12
12
  require 'allocine/search'
13
13
  require 'allocine/version'
14
+ require 'allocine/serie'
15
+ require 'allocine/season'
16
+ require 'allocine/episode'
@@ -6,9 +6,9 @@ module Allocine
6
6
 
7
7
  # Represents a AllocineBase
8
8
  class AllocineBase
9
- attr_accessor :id, :url, :title, :also_known_as
9
+ attr_accessor :id, :url, :title
10
10
 
11
- def initialize(allocine_id, title = nil, also_known_as = [])
11
+ def initialize(allocine_id, title = nil)
12
12
  @id = allocine_id
13
13
  @url = "http://api.allocine.fr/rest/v3/movie?code=#{allocine_id}&profile=large&format=json&partner=YW5kcm9pZC12M3M"
14
14
  end
@@ -0,0 +1,65 @@
1
+ module Allocine
2
+
3
+ class Episode
4
+
5
+ # Represent an Episode on Allocine website
6
+ # s = Allocine::Episode.new(233014)
7
+ # e = s.title
8
+
9
+ attr_accessor :title, :synopsis, :number, :release_date
10
+
11
+ def initialize(allocine_id)
12
+ @id = allocine_id
13
+ end
14
+
15
+ # Returns the season parent
16
+ def season
17
+ Allocine::Season.new(document["parentSeason"]["code"])
18
+ end
19
+
20
+ # Returns the serie parent
21
+ def serie
22
+ Allocine::Serie.new(document["parentSeries"]["code"])
23
+ end
24
+
25
+ # Returns the title
26
+ def title
27
+ document["title"] rescue nil
28
+ end
29
+
30
+ # Returns the original title
31
+ def original_title
32
+ document["originalTitle"] rescue nil
33
+ end
34
+
35
+ # Returns the broadcast date
36
+ def original_broadcast_date
37
+ document["originalBroadcastDate"] rescue nil
38
+ end
39
+
40
+ # Returns the plot
41
+ def plot(short = true)
42
+ short == true ? document["synopsisShort"] : document["synopsis"]
43
+ end
44
+
45
+ def episode_number_series
46
+ document["episodeNumberSeries"]
47
+ end
48
+
49
+ def episode_number_season
50
+ document["episodeNumberSeason"]
51
+ end
52
+
53
+ private
54
+
55
+ def document
56
+ @document ||= Allocine::Episode.find_by_id(@id)
57
+ end
58
+
59
+ def self.find_by_id(allocine_id)
60
+ url = "http://api.allocine.fr/rest/v3/episode?partner=YW5kcm9pZC12M3M&code=#{allocine_id}&profile=large&format=json"
61
+ JSON.parse(Net::HTTP.get_response(URI.parse(url)).body)["episode"]
62
+ end
63
+
64
+ end
65
+ end
@@ -1,7 +1,21 @@
1
1
  module Allocine
2
2
 
3
3
  class MovieList
4
-
4
+ def movies
5
+ @movies ||= parse_movies
6
+ end
7
+
8
+ private
9
+ def parse_movies
10
+ id, originalTitle = nil
11
+ movies = []
12
+ document["movie"].each do |element|
13
+ id = element['code']
14
+ title = element['originalTitle']
15
+ movies << Allocine::Movie.new(id, originalTitle)
16
+ end
17
+ movies
18
+ end
5
19
  end
6
-
20
+
7
21
  end
@@ -1,6 +1,31 @@
1
1
  module Allocine
2
2
 
3
3
  class Search < MovieList
4
+ attr_reader :query
5
+
6
+ # Initialize a new Allocine search with the specified query
7
+ #
8
+ # search = Allocine::Search.new("Superman")
9
+ #
10
+ def initialize(query)
11
+ @query = query
12
+ end
13
+
14
+ # Returns an array of Allocine::Movie objects for easy search result yielded.
15
+ def movies
16
+ @movies ||= parse_movies
17
+ end
18
+
19
+ private
20
+ def document
21
+ @document ||= Allocine::Search.query(@query)
22
+ end
23
+
24
+ def self.query(query)
25
+ url = "http://api.allocine.fr/rest/v3/search?partner=YW5kcm9pZC12M3M&filter=movie,tvseries&q=#{query}&format=json"
26
+ JSON.parse(Net::HTTP.get_response(URI.parse(URI.encode(url))).body)["feed"] rescue nil
27
+ end
28
+
4
29
 
5
30
  end
6
31
  end
@@ -0,0 +1,63 @@
1
+ module Allocine
2
+
3
+ class Season
4
+ attr_accessor :id, :url, :season_number, :episodes
5
+
6
+ # Represent a serie Season on Allocine website
7
+ # s = Allocine::Season.new(12277)
8
+ # e = s.episodes.first
9
+
10
+
11
+ def initialize(id)
12
+ @id = id
13
+ @episodes = []
14
+ end
15
+
16
+ # Returns parent serie
17
+ def serie
18
+ Allocine::Serie.new(document["parentSeries"]["code"])
19
+ end
20
+
21
+ # Returns season number
22
+ def season_number
23
+ document["seasonNumber"] rescue nil
24
+ end
25
+
26
+ # Returns numbers of episode
27
+ def episode_count
28
+ document["episodeCount"] rescue nil
29
+ end
30
+
31
+ # Returns numbers of episode
32
+ def episode_numbers
33
+ document["episode"].size rescue nil
34
+ end
35
+
36
+ # Returns an Array of episode ids
37
+ def episode_ids
38
+ document["episode"].map { |episode| episode["code"]} rescue []
39
+ end
40
+
41
+ # Returns an Array of Allocine::Episode
42
+ def episodes
43
+ s = []
44
+ episode_ids.each do |allocine_id|
45
+ s << Allocine::Episode.new(allocine_id)
46
+ end
47
+ s
48
+ end
49
+
50
+ private
51
+
52
+ def document
53
+ @document ||= Allocine::Season.find_by_id(@id)
54
+ end
55
+
56
+ def self.find_by_id(allocine_id)
57
+ url = "http://api.allocine.fr/rest/v3/season?partner=YW5kcm9pZC12M3M&code=#{allocine_id}&profile=large&format=json"
58
+ JSON.parse(Net::HTTP.get_response(URI.parse(url)).body)["season"]
59
+ end
60
+
61
+ end
62
+
63
+ end
@@ -0,0 +1,54 @@
1
+ module Allocine
2
+
3
+ class Serie < AllocineBase
4
+
5
+ # s = Allocine::Serie.new(223)
6
+ # e = s.seasons.first.episodes.first
7
+
8
+
9
+ def initialize(allocine_id, title = nil)
10
+ @id = allocine_id
11
+ @url = "http://api.allocine.fr/rest/v3/tvseries?partner=YW5kcm9pZC12M3M&code=#{allocine_id}&profile=large&format=json"
12
+ end
13
+
14
+ def number_of_seasons
15
+ document["seasonCount"] rescue nil
16
+ end
17
+
18
+ def number_of_episodes
19
+ document["episodeCount"] rescue nil
20
+ end
21
+
22
+ def year_start
23
+ document["yearStart"] rescue nil
24
+ end
25
+
26
+ def year_end
27
+ document["yearEnd"] rescue nil
28
+ end
29
+
30
+ def season_ids
31
+ document["season"].map { |season| season["code"]} rescue []
32
+ end
33
+
34
+ def seasons
35
+ s = []
36
+ season_ids.each do |allocine_id|
37
+ s << Allocine::Season.new(allocine_id)
38
+ end
39
+ s
40
+ end
41
+
42
+ private
43
+
44
+ def document
45
+ @document ||= Allocine::Serie.find_by_id(@id)
46
+ end
47
+
48
+ def self.find_by_id(allocine_id)
49
+ url = "http://api.allocine.fr/rest/v3/tvseries?partner=YW5kcm9pZC12M3M&code=#{allocine_id}&profile=large&format=json"
50
+ JSON.parse(Net::HTTP.get_response(URI.parse(url)).body)["tvseries"]
51
+ end
52
+
53
+ end
54
+ end
@@ -1,3 +1,3 @@
1
1
  module Allocine
2
- VERSION = '1.0.0'
2
+ VERSION = '1.5.0'
3
3
  end
@@ -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 /path.../allocine/lib/allocine.rb"
9
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
10
+ libs << " -r /Users/matthieu/Dev/rails/perso/allocine/lib/allocine.rb"
11
11
  puts "Loading allocine gem"
12
12
  exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
4
+
5
+ # This test uses "Lost - season 6 episode 1" as a testing sample:
6
+ #
7
+ # http://api.allocine.fr/rest/v3/episode?partner=YW5kcm9pZC12M3M&code=#{allocine_id}&profile=large&format=json
8
+ #
9
+
10
+ describe "Allocine::Episode" do
11
+
12
+ describe "valid episode" do
13
+
14
+ before(:each) do
15
+ @episode = Allocine::Episode.new("233014")
16
+ end
17
+
18
+ it "should find the plot" do
19
+ @episode.plot.should eql("Deux situations parallèles se font face. Dans la première, l'explosion a eu l'effet escompté. A bord du vol Oceanic 815 entre Sydney à Los Angeles, l'appareil subit de violentes turbulences qui cessent rapidement. Mais des choses ont changé : Desmond est là alors qu'à l'origine, il n'était pas à bord...")
20
+ end
21
+
22
+ it "should find the title" do
23
+ @episode.title.should =~ /On efface tout/
24
+ end
25
+
26
+ it "should find the the broadcast date" do
27
+ @episode.original_broadcast_date.should eql("2010-02-02")
28
+ end
29
+
30
+ it "should find the serie parent" do
31
+ @episode.serie.id.should eql(223)
32
+ end
33
+
34
+ it "should find the season parent" do
35
+ @episode.season.id.should eql(12277)
36
+ end
37
+ end
38
+
39
+ end
@@ -63,10 +63,6 @@ describe "Allocine::Movie" do
63
63
  @movie.press_rating.should eql(3.125)
64
64
  end
65
65
 
66
- it "should find the user rating" do
67
- @movie.user_rating.should eql(3.64026)
68
- end
69
-
70
66
  it "should find the title" do
71
67
  @movie.title.should =~ /Star Wars : Episode I - La Menace fantôme/
72
68
  end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
4
+
5
+ # This test uses "Lost - season 6" as a testing sample:
6
+ #
7
+ # http://api.allocine.fr/rest/v3/season?partner=YW5kcm9pZC12M3M&code=#{allocine_id}&profile=large&format=json
8
+ #
9
+
10
+ describe "Allocine::Season" do
11
+
12
+ describe "valid season" do
13
+
14
+ before(:each) do
15
+ @serie = Allocine::Season.new("12277")
16
+ end
17
+
18
+ it "should find the season_number" do
19
+ @serie.season_number.should eql(6)
20
+ end
21
+
22
+ it "should find the episode count" do
23
+ @serie.episode_count.should eql(18)
24
+ end
25
+
26
+ it "should find the serie parent" do
27
+ @serie.serie.id.should eql(223)
28
+ end
29
+
30
+ end
31
+
32
+ end
File without changes
@@ -1,12 +1,3 @@
1
- # By default if you have the FakeWeb gem installed when the specs are
2
- # run they will hit recorded responses. However, if you don't have
3
- # the FakeWeb gem installed or you set the environment variable
4
- # LIVE_TEST then the tests will hit the live site IMDB.com.
5
- #
6
- # Having both methods available for testing allows you to quickly
7
- # refactor and add features, while also being able to make sure that
8
- # no changes to the IMDB.com interface have affected the parser.
9
- ###
10
1
 
11
2
  begin
12
3
  require 'spec'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: allocine_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.5.0
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-05 00:00:00.000000000 +01:00
12
+ date: 2011-11-06 00:00:00.000000000 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hpricot
17
- requirement: &2168755320 !ruby/object:Gem::Requirement
17
+ requirement: &2164553800 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.8.4
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2168755320
25
+ version_requirements: *2164553800
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rdoc
28
- requirement: &2168754820 !ruby/object:Gem::Requirement
28
+ requirement: &2164550840 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *2168754820
36
+ version_requirements: *2164550840
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &2168754240 !ruby/object:Gem::Requirement
39
+ requirement: &2164541800 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,8 +44,8 @@ dependencies:
44
44
  version: 1.3.2
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2168754240
48
- description: Easily use Ruby to find information on allocine website.
47
+ version_requirements: *2164541800
48
+ description: Easily use Ruby to find information on allocine API.
49
49
  email:
50
50
  - lamarque.matthieu@gmail.com
51
51
  executables: []
@@ -60,12 +60,18 @@ files:
60
60
  - allocine.gemspec
61
61
  - lib/allocine.rb
62
62
  - lib/allocine/allocine_base.rb
63
+ - lib/allocine/episode.rb
63
64
  - lib/allocine/movie.rb
64
65
  - lib/allocine/movie_list.rb
65
66
  - lib/allocine/search.rb
67
+ - lib/allocine/season.rb
68
+ - lib/allocine/serie.rb
66
69
  - lib/allocine/version.rb
67
70
  - script/console
68
- - spec/imdb/movie_spec.rb
71
+ - spec/allocine/episode_spec.rb
72
+ - spec/allocine/movie_spec.rb
73
+ - spec/allocine/season_spec.rb
74
+ - spec/allocine/serie_spec.rb
69
75
  - spec/spec_helper.rb
70
76
  has_rdoc: true
71
77
  homepage: http://github.com/mlamarque/allocine
@@ -91,7 +97,10 @@ rubyforge_project: allocine
91
97
  rubygems_version: 1.6.2
92
98
  signing_key:
93
99
  specification_version: 3
94
- summary: Easily access the publicly available information on Allocine website.
100
+ summary: Easily access the API information on Allocine API.
95
101
  test_files:
96
- - spec/imdb/movie_spec.rb
102
+ - spec/allocine/episode_spec.rb
103
+ - spec/allocine/movie_spec.rb
104
+ - spec/allocine/season_spec.rb
105
+ - spec/allocine/serie_spec.rb
97
106
  - spec/spec_helper.rb