allocine_api 1.0.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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ == 0.0.1 2011-11-05
2
+
3
+ * First release of the Allocine gem. [mlamarque]
data/Manifest.txt ADDED
File without changes
data/README.rdoc ADDED
@@ -0,0 +1,55 @@
1
+ = allocine
2
+
3
+ Allows you to search and inspect movies and series from allocine API
4
+
5
+ == DESCRIPTION:
6
+
7
+ This packages allows you to easy access publicly available data from Allocine API.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ Allocine currently features the following:
12
+
13
+ * Querying details movie info
14
+
15
+ == SYNOPSIS:
16
+
17
+ Movies:
18
+
19
+ i = Allocine::Movie.new("20754")
20
+
21
+ i.title
22
+ #=> "Star Wars : Episode I - La Menace fantôme"
23
+
24
+
25
+ == TESTING:
26
+
27
+ You'll need rspec installed to run the specs.
28
+
29
+ $ bundle install
30
+ $ rspec spec/imdb/movie_spec.rb
31
+
32
+ == LICENSE:
33
+
34
+ (The MIT License)
35
+
36
+ Copyright (c) 2011 Matthieu Lamarque
37
+
38
+ Permission is hereby granted, free of charge, to any person obtaining
39
+ a copy of this software and associated documentation files (the
40
+ 'Software'), to deal in the Software without restriction, including
41
+ without limitation the rights to use, copy, modify, merge, publish,
42
+ distribute, sublicense, and/or sell copies of the Software, and to
43
+ permit persons to whom the Software is furnished to do so, subject to
44
+ the following conditions:
45
+
46
+ The above copyright notice and this permission notice shall be
47
+ included in all copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
50
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
51
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
52
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
53
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
54
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
55
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/allocine.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "allocine/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "allocine_api"
7
+ s.version = Allocine::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Matthieu Lamarque"]
10
+ s.email = ["lamarque.matthieu@gmail.com"]
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.}
14
+
15
+ s.rubyforge_project = "allocine"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency 'hpricot', '~> 0.8.4'
23
+
24
+ s.add_development_dependency 'rdoc'
25
+ s.add_development_dependency 'rspec', '~> 1.3.2'
26
+ end
@@ -0,0 +1,114 @@
1
+ module Allocine
2
+
3
+ require 'rubygems'
4
+ require 'json'
5
+ require 'net/http'
6
+
7
+ # Represents a AllocineBase
8
+ class AllocineBase
9
+ attr_accessor :id, :url, :title, :also_known_as
10
+
11
+ def initialize(allocine_id, title = nil, also_known_as = [])
12
+ @id = allocine_id
13
+ @url = "http://api.allocine.fr/rest/v3/movie?code=#{allocine_id}&profile=large&format=json&partner=YW5kcm9pZC12M3M"
14
+ end
15
+
16
+ # Returns the name of the director
17
+ def directors
18
+ document["castingShort"]["directors"].split(", ") rescue nil
19
+ end
20
+
21
+ # Returns an array with cast members
22
+ def actors
23
+ document["castingShort"]["actors"].split(", ") rescue nil
24
+ end
25
+
26
+ # Returns an array of genres (as strings)
27
+ def genres
28
+ document["genre"].collect {|gender| gender["$"]} rescue nil
29
+ end
30
+
31
+ # Returns an array of countries as strings.
32
+ def countries
33
+ document["nationality"].collect {|nation| nation["$"]} rescue nil
34
+ end
35
+
36
+ # Returns the duration of the movie in minutes as an integer.
37
+ def length
38
+ document["runtime"].to_i/60 rescue nil
39
+ end
40
+
41
+ # Returns a string containing the URL to the movie poster.
42
+ def poster
43
+ document["poster"]["href"] rescue nil
44
+ end
45
+
46
+ # Returns a string containing trailer code.
47
+ def trailer_id
48
+ document["trailer"]["code"] rescue nil
49
+ end
50
+
51
+ # Returns a string containing the URL to the movie trailer.
52
+ def trailer
53
+ document["trailer"]["href"] rescue nil
54
+ end
55
+
56
+ # Returns a float containing the average user rating
57
+ def press_rating
58
+ document["statistics"]["pressRating"] rescue nil
59
+ end
60
+
61
+ # Returns an int containing the number of user ratings
62
+ def user_rating
63
+ document["statistics"]["userRating"] rescue nil
64
+ end
65
+
66
+ # Returns a string containing the title
67
+ def title(force_refresh = false)
68
+ if @title && !force_refresh
69
+ @title
70
+ else
71
+ @title = document["title"] rescue nil
72
+ end
73
+ end
74
+
75
+ # Returns originalTitle.
76
+ def original_title
77
+ document["originalTitle"] rescue nil
78
+ end
79
+
80
+
81
+ # Returns release date for the movie.
82
+ def release_date
83
+ document["release"]["releaseDate"] rescue nil
84
+ end
85
+
86
+ # Return production Year for the movie
87
+ def production_year
88
+ document["productionYear"]
89
+ end
90
+
91
+ def plot(short = true)
92
+ short ? document["synopsisShort"] : document["synopsis"]
93
+ end
94
+
95
+ private
96
+
97
+ # Returns a new Hpricot document for parsing.
98
+ def document
99
+ @document ||= Allocine::Movie.find_by_id(@id)
100
+ end
101
+
102
+ def self.find_by_id(allocine_id)
103
+ url = "http://api.allocine.fr/rest/v3/movie?code=#{allocine_id}&profile=large&format=json&partner=YW5kcm9pZC12M3M"
104
+ JSON.parse(Net::HTTP.get_response(URI.parse(url)).body)["movie"] rescue nil
105
+ end
106
+
107
+ # Convenience method for search
108
+ def self.search(query)
109
+ Allocine::Search.new(query).movies
110
+ end
111
+
112
+ end
113
+
114
+ end
@@ -0,0 +1,9 @@
1
+ module Allocine
2
+
3
+ # Represents a Movie on Allocine website
4
+ class Movie < AllocineBase
5
+
6
+
7
+ end
8
+
9
+ end
@@ -0,0 +1,7 @@
1
+ module Allocine
2
+
3
+ class MovieList
4
+
5
+ end
6
+
7
+ end
@@ -0,0 +1,6 @@
1
+ module Allocine
2
+
3
+ class Search < MovieList
4
+
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Allocine
2
+ VERSION = '1.0.0'
3
+ end
data/lib/allocine.rb ADDED
@@ -0,0 +1,13 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'open-uri'
5
+ require 'rubygems'
6
+ require 'hpricot'
7
+ require 'awesome_print'
8
+
9
+ require 'allocine/allocine_base'
10
+ require 'allocine/movie'
11
+ require 'allocine/movie_list'
12
+ require 'allocine/search'
13
+ require 'allocine/version'
data/script/console ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+
6
+ require "awesome_print"
7
+
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"
11
+ puts "Loading allocine gem"
12
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,87 @@
1
+ # coding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
4
+
5
+ # This test uses "Star Wars : Episode I - La Menace fantôme " as a testing sample:
6
+ #
7
+ # http://api.allocine.fr/rest/v3/movie?code=20754&profile=large&format=json&partner=YW5kcm9pZC12M3M
8
+ #
9
+
10
+ describe "Allocine::Movie" do
11
+
12
+ describe "valid movie" do
13
+
14
+ before(:each) do
15
+ @movie = Allocine::Movie.new("20754")
16
+ end
17
+
18
+ it "should find the cast members" do
19
+ cast = @movie.actors
20
+
21
+ 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")
26
+ end
27
+
28
+ 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/
32
+ end
33
+
34
+ it "should find the genres" do
35
+ genres = @movie.genres
36
+ genres.should be_an(Array)
37
+ genres.should include('Science fiction')
38
+ genres.should include('Fantastique')
39
+ genres.should include('Aventure')
40
+ end
41
+
42
+ it "should find the countries" do
43
+ countries = @movie.countries
44
+
45
+ countries.should be_an(Array)
46
+ countries.size.should eql(1)
47
+ countries.should include('U.S.A.')
48
+ end
49
+
50
+ it "should find the length (in minutes)" do
51
+ @movie.length.should eql(133)
52
+ end
53
+
54
+ it "should find the plot" do
55
+ @movie.plot.should eql("Il y a bien longtemps, dans une galaxie très lointaine... La Fédération du Commerce impose par la force la taxation des routes commerciales à la pacifique planète Naboo. Les chevaliers Jedi Qui-Gon Jinn et Obi-Wan Kenobi sont envoyés sur place...")
56
+ end
57
+
58
+ it "should find the poster" do
59
+ @movie.poster.should eql("http://images.allocine.fr/medias/nmedia/18/86/24/04/19835018.jpg")
60
+ end
61
+
62
+ it "should find the press rating" do
63
+ @movie.press_rating.should eql(3.125)
64
+ end
65
+
66
+ it "should find the user rating" do
67
+ @movie.user_rating.should eql(3.64026)
68
+ end
69
+
70
+ it "should find the title" do
71
+ @movie.title.should =~ /Star Wars : Episode I - La Menace fantôme/
72
+ end
73
+
74
+ it "should find the production year" do
75
+ @movie.production_year.should eql(1999)
76
+ end
77
+
78
+ it "should find the release date" do
79
+ @movie.release_date.should eql("1999-10-13")
80
+ end
81
+
82
+ it "should find the trailer" do
83
+ @movie.trailer.should eql("http://www.allocine.fr/blogvision/19259278")
84
+ end
85
+ end
86
+
87
+ end
@@ -0,0 +1,24 @@
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
+
11
+ begin
12
+ require 'spec'
13
+ rescue LoadError
14
+ require 'rubygems'
15
+ gem 'rspec'
16
+ # require 'spec'
17
+ end
18
+
19
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
20
+ require 'allocine'
21
+
22
+ def read_fixture(path)
23
+ File.read(File.expand_path(File.join(File.dirname(__FILE__), "fixtures", path)))
24
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: allocine_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matthieu Lamarque
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-05 00:00:00.000000000 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hpricot
17
+ requirement: &2168755320 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 0.8.4
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2168755320
26
+ - !ruby/object:Gem::Dependency
27
+ name: rdoc
28
+ requirement: &2168754820 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *2168754820
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ requirement: &2168754240 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 1.3.2
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *2168754240
48
+ description: Easily use Ruby to find information on allocine website.
49
+ email:
50
+ - lamarque.matthieu@gmail.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - History.txt
58
+ - Manifest.txt
59
+ - README.rdoc
60
+ - allocine.gemspec
61
+ - lib/allocine.rb
62
+ - lib/allocine/allocine_base.rb
63
+ - lib/allocine/movie.rb
64
+ - lib/allocine/movie_list.rb
65
+ - lib/allocine/search.rb
66
+ - lib/allocine/version.rb
67
+ - script/console
68
+ - spec/imdb/movie_spec.rb
69
+ - spec/spec_helper.rb
70
+ has_rdoc: true
71
+ homepage: http://github.com/mlamarque/allocine
72
+ licenses: []
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project: allocine
91
+ rubygems_version: 1.6.2
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Easily access the publicly available information on Allocine website.
95
+ test_files:
96
+ - spec/imdb/movie_spec.rb
97
+ - spec/spec_helper.rb