filmaffinity 0.2.4 → 0.3.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.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +22 -4
- data/README.md +21 -5
- data/filmaffinity.gemspec +4 -3
- data/lib/constants/constants.rb +85 -3
- data/lib/filmaffinity.rb +16 -0
- data/lib/filmaffinity/configuration.rb +9 -0
- data/lib/filmaffinity/movie.rb +29 -20
- data/lib/filmaffinity/poster-manager.rb +32 -0
- data/lib/filmaffinity/top.rb +28 -8
- data/spec/filmaffinity/movie_spec.rb +205 -83
- data/spec/filmaffinity/top_spec.rb +43 -3
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52aaf0ced3b0eb4e2eec8f40a956a9491045e073
|
4
|
+
data.tar.gz: 11d38853476bce00f143ac5e3213970029dd34ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa6e4c80f074223966f37466bcb6e315e33fb4a9c4cefef7cb8c550f15f23fadd112d8f2a7c43c3a9f11e094167272bc3d4d3dc353836d9ab11e14db358160fc
|
7
|
+
data.tar.gz: 41d399c3bdc3e920b78cd5314f621e2c67ba785b25face9d9e87f7e4d45ffde85fb1437fb6c3183881395cdb4c4971d7d8dc47dce471df02b643a57fa2c4919d
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,11 +1,27 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
filmaffinity (0.2.4)
|
5
|
+
json (~> 1.8)
|
6
|
+
nokogiri (~> 1.6)
|
7
|
+
|
1
8
|
GEM
|
2
9
|
remote: https://rubygems.org/
|
3
10
|
specs:
|
11
|
+
coderay (1.1.1)
|
4
12
|
diff-lcs (1.2.5)
|
5
|
-
|
13
|
+
json (1.8.3)
|
14
|
+
method_source (0.8.2)
|
6
15
|
mini_portile2 (2.0.0)
|
7
16
|
nokogiri (1.6.7.2)
|
8
17
|
mini_portile2 (~> 2.0.0.rc2)
|
18
|
+
pry (0.10.3)
|
19
|
+
coderay (~> 1.1.0)
|
20
|
+
method_source (~> 0.8.1)
|
21
|
+
slop (~> 3.4)
|
22
|
+
pry-nav (0.2.4)
|
23
|
+
pry (>= 0.9.10, < 0.11.0)
|
24
|
+
rake (10.4.2)
|
9
25
|
rspec (3.4.0)
|
10
26
|
rspec-core (~> 3.4.0)
|
11
27
|
rspec-expectations (~> 3.4.0)
|
@@ -19,14 +35,16 @@ GEM
|
|
19
35
|
diff-lcs (>= 1.2.0, < 2.0)
|
20
36
|
rspec-support (~> 3.4.0)
|
21
37
|
rspec-support (3.4.1)
|
38
|
+
slop (3.6.0)
|
22
39
|
|
23
40
|
PLATFORMS
|
24
41
|
ruby
|
25
42
|
|
26
43
|
DEPENDENCIES
|
27
|
-
|
28
|
-
|
29
|
-
|
44
|
+
filmaffinity!
|
45
|
+
pry-nav
|
46
|
+
rake (~> 10.0)
|
47
|
+
rspec (~> 3.3)
|
30
48
|
|
31
49
|
BUNDLED WITH
|
32
50
|
1.11.2
|
data/README.md
CHANGED
@@ -1,15 +1,32 @@
|
|
1
|
-
#FilmAffinity Scraper Gem
|
1
|
+
# FilmAffinity Scraper Gem
|
2
|
+
[](http://badge.fury.io/rb/filmaffinity)
|
2
3
|
|
3
4
|
## Description
|
4
5
|
|
5
|
-
The filmaffinity gem allows you to easy access publicly available data from **Filmaffinity.com in spanish**.
|
6
|
+
The filmaffinity gem allows you to easy access publicly available data from **Filmaffinity.com in english and spanish**.
|
7
|
+
|
8
|
+
Also available as **REST API** at [heroku](https://filmaffinity-unofficial.herokuapp.com/).
|
6
9
|
|
7
10
|
## Features
|
8
11
|
|
9
12
|
- Search movies for a title
|
10
13
|
- Retrieve complete movie info
|
11
|
-
- Retrieve the Top
|
12
|
-
- Retrieve the Top with the given options
|
14
|
+
- Retrieve the Top N of filmaffinity.com
|
15
|
+
- Retrieve the Top N with the given options
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
gem 'filmaffinity'
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install filmaffinity
|
13
30
|
|
14
31
|
## Documentation
|
15
32
|
|
@@ -129,7 +146,6 @@ The options hash could include:
|
|
129
146
|
|
130
147
|
movie.genres, movie.country, movie.sinopsis...
|
131
148
|
|
132
|
-
|
133
149
|
## Contributors
|
134
150
|
|
135
151
|
This gem is created and maintained by [Oriol Bellido](https://github.com/oricodes89) and [David Santos](https://github.com/davidsantosmerino)
|
data/filmaffinity.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'filmaffinity'
|
3
|
-
s.version = '0.
|
4
|
-
s.date = '2016-04-
|
3
|
+
s.version = '0.3.0'
|
4
|
+
s.date = '2016-04-18'
|
5
5
|
s.summary = "filmaffinity"
|
6
6
|
s.description = "Easily use Ruby or the command line to find information on Filmaffinity.com"
|
7
|
-
s.authors = ["David Santos, Oriol Bellido"]
|
7
|
+
s.authors = ["David Santos", "Oriol Bellido"]
|
8
8
|
s.email = 'dsantosmerino92@gmail.com'
|
9
9
|
s.files = `git ls-files`.split("\n")
|
10
10
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.license = 'MIT'
|
15
15
|
s.add_dependency 'nokogiri', ' ~> 1.6'
|
16
16
|
s.add_dependency 'json', ' ~> 1.8'
|
17
|
+
s.add_dependency 'imgur-api','~> 0'
|
17
18
|
s.add_development_dependency 'rake', '~> 10.0'
|
18
19
|
s.add_development_dependency 'rspec', '~> 3.3'
|
19
20
|
end
|
data/lib/constants/constants.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
module Constants
|
2
|
+
|
2
3
|
def self.query_params
|
3
4
|
{
|
4
5
|
:genre => "genre=%s&",
|
@@ -9,11 +10,92 @@ module Constants
|
|
9
10
|
:no_tv => "notvse&",
|
10
11
|
}
|
11
12
|
end
|
13
|
+
|
12
14
|
def self.urls
|
13
15
|
{
|
14
|
-
:top => "http://www.filmaffinity.com/
|
15
|
-
:search_by_title => "http://www.filmaffinity.com/
|
16
|
-
:movie => "http://www.filmaffinity.com/
|
16
|
+
:top => "http://www.filmaffinity.com/#{self.lang}/topgen.php%s",
|
17
|
+
:search_by_title => "http://www.filmaffinity.com/#{self.lang}/search.php?stext=%s&stype=title",
|
18
|
+
:movie => "http://www.filmaffinity.com/#{self.lang}/film%i.html"
|
17
19
|
}
|
18
20
|
end
|
21
|
+
|
22
|
+
def self.tags
|
23
|
+
{
|
24
|
+
|
25
|
+
:title => { :EN => '#main-title span',
|
26
|
+
:ES => '#main-title span'
|
27
|
+
},
|
28
|
+
|
29
|
+
:year => { :EN => 'dd[itemprop="datePublished"]',
|
30
|
+
:ES => 'dd[itemprop="datePublished"]'
|
31
|
+
},
|
32
|
+
|
33
|
+
:duration => { :EN => 'dd[itemprop="duration"]',
|
34
|
+
:ES => 'dd[itemprop="duration"]'
|
35
|
+
},
|
36
|
+
|
37
|
+
:country => { :EN => '#country-img',
|
38
|
+
:ES => '#country-img'
|
39
|
+
},
|
40
|
+
|
41
|
+
:director => { :EN => 'a[itemprop="url"]',
|
42
|
+
:ES => 'a[itemprop="url"]'
|
43
|
+
},
|
44
|
+
|
45
|
+
:music => { :EN => 'dt:contains("Music")',
|
46
|
+
:ES => 'dt:contains("Música")'
|
47
|
+
},
|
48
|
+
|
49
|
+
:company => { :EN => 'dt:contains("Producer")',
|
50
|
+
:ES => 'dt:contains("Productora")'
|
51
|
+
},
|
52
|
+
|
53
|
+
:script => {:EN => 'dt:contains("Screenwriter")',
|
54
|
+
:ES => 'dt:contains("Guión")'
|
55
|
+
},
|
56
|
+
|
57
|
+
:photography => { :EN => 'dt:contains("Cinematography")',
|
58
|
+
:ES => 'dt:contains("Fotografía")'
|
59
|
+
},
|
60
|
+
|
61
|
+
:cast => { :EN => 'span[itemprop="actor"]',
|
62
|
+
:ES => 'span[itemprop="actor"]'
|
63
|
+
},
|
64
|
+
|
65
|
+
:cast_each => { :EN => 'span[itemprop="name"]',
|
66
|
+
:ES => 'span[itemprop="name"]'
|
67
|
+
},
|
68
|
+
|
69
|
+
:genre => { :EN => 'dt:contains("Genre")',
|
70
|
+
:ES => 'dt:contains("Género")'
|
71
|
+
},
|
72
|
+
|
73
|
+
:sinopsis => { :EN => 'dd[itemprop="description"]',
|
74
|
+
:ES => 'dd[itemprop="description"]'
|
75
|
+
},
|
76
|
+
|
77
|
+
:rating => { :EN => 'div[itemprop="ratingValue"]',
|
78
|
+
:ES => 'div[itemprop="ratingValue"]'
|
79
|
+
},
|
80
|
+
|
81
|
+
:poster => { :EN => 'img[itemprop="image"]',
|
82
|
+
:ES => 'img[itemprop="image"]'
|
83
|
+
},
|
84
|
+
|
85
|
+
:poster_big => { :EN => 'a[class="lightbox"]',
|
86
|
+
:ES => 'a[class="lightbox"]'
|
87
|
+
}
|
88
|
+
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.tag(type)
|
93
|
+
lang = FilmAffinity.configuration.language.to_sym
|
94
|
+
Constants.tags[type][lang]
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.lang
|
98
|
+
FilmAffinity.configuration.language.downcase
|
99
|
+
end
|
100
|
+
|
19
101
|
end
|
data/lib/filmaffinity.rb
CHANGED
@@ -2,8 +2,24 @@ require "open-uri"
|
|
2
2
|
require "nokogiri"
|
3
3
|
|
4
4
|
require_relative "constants/constants"
|
5
|
+
require_relative "filmaffinity/configuration"
|
6
|
+
require_relative "filmaffinity/poster-manager"
|
5
7
|
require_relative "filmaffinity/json-movies-parser"
|
6
8
|
require_relative "filmaffinity/json-movie-parser"
|
7
9
|
require_relative "filmaffinity/movie"
|
8
10
|
require_relative "filmaffinity/search"
|
9
11
|
require_relative "filmaffinity/top"
|
12
|
+
|
13
|
+
module FilmAffinity
|
14
|
+
class << self
|
15
|
+
attr_accessor :configuration
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configuration
|
19
|
+
@configuration ||= Configuration.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.configure
|
23
|
+
yield(configuration)
|
24
|
+
end
|
25
|
+
end
|
data/lib/filmaffinity/movie.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
module FilmAffinity
|
2
3
|
class Movie
|
3
4
|
attr_reader :id, :title
|
@@ -5,6 +6,7 @@ module FilmAffinity
|
|
5
6
|
@id = id
|
6
7
|
@title = title if title
|
7
8
|
@json_parser = JsonMovieParser.new
|
9
|
+
@poster_manager = PosterManager.new
|
8
10
|
end
|
9
11
|
|
10
12
|
def document_html
|
@@ -16,55 +18,55 @@ module FilmAffinity
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def title
|
19
|
-
@title ||= document_html.at(
|
21
|
+
@title ||= document_html.at(Constants.tag(:title)).content.strip
|
20
22
|
end
|
21
23
|
|
22
24
|
def year
|
23
|
-
document_html.at(
|
25
|
+
document_html.at(Constants.tag(:year)).content[/\d+/].to_i
|
24
26
|
end
|
25
27
|
|
26
28
|
def duration
|
27
|
-
document_html.at(
|
29
|
+
document_html.at(Constants.tag(:duration)).content[/\d+/].to_i
|
28
30
|
end
|
29
31
|
|
30
32
|
def country
|
31
|
-
raw_country = document_html.at(
|
33
|
+
raw_country = document_html.at(Constants.tag(:country)).next_sibling.content
|
32
34
|
raw_country.gsub(/\A[[:space:]]+|[[:space:]]+\z/, '')
|
33
35
|
end
|
34
36
|
|
35
37
|
def director
|
36
|
-
raw_director = document_html.at(
|
38
|
+
raw_director = document_html.at(Constants.tag(:director)).content
|
37
39
|
raw_director.strip
|
38
40
|
end
|
39
41
|
|
40
|
-
def
|
41
|
-
document_html.at(
|
42
|
+
def music
|
43
|
+
document_html.at(Constants.tag(:music)).next_sibling.next_sibling.content
|
42
44
|
end
|
43
45
|
|
44
|
-
def
|
45
|
-
document_html.at(
|
46
|
+
def company
|
47
|
+
document_html.at(Constants.tag(:company)).next_sibling.next_sibling.content
|
48
|
+
end
|
49
|
+
|
50
|
+
def script
|
51
|
+
document_html.at(Constants.tag(:script)).next_sibling.next_sibling.content
|
46
52
|
end
|
47
53
|
|
48
54
|
def photography
|
49
|
-
document_html.at(
|
55
|
+
document_html.at((Constants.tag(:photography))).next_sibling.next_sibling.content
|
50
56
|
end
|
51
57
|
|
52
58
|
def cast
|
53
59
|
actors = []
|
54
|
-
node = document_html.search(
|
60
|
+
node = document_html.search((Constants.tag(:cast)))
|
55
61
|
node.each do |actor|
|
56
|
-
actors << actor.at(
|
62
|
+
actors << actor.at((Constants.tag(:cast_each))).content.strip
|
57
63
|
end
|
58
64
|
actors
|
59
65
|
end
|
60
66
|
|
61
|
-
def company
|
62
|
-
document_html.at('dt:contains("Productora")').next_sibling.next_sibling.content
|
63
|
-
end
|
64
|
-
|
65
67
|
def genres
|
66
68
|
genres = []
|
67
|
-
node = document_html.at(
|
69
|
+
node = document_html.at(Constants.tag(:genre)).next_sibling.next_sibling
|
68
70
|
raw_genres = node.search("a")
|
69
71
|
raw_genres.each do |raw_genre|
|
70
72
|
genres << raw_genre.content.strip
|
@@ -74,20 +76,27 @@ module FilmAffinity
|
|
74
76
|
end
|
75
77
|
|
76
78
|
def sinopsis
|
77
|
-
document_html.at(
|
79
|
+
document_html.at(Constants.tag(:sinopsis)).content
|
78
80
|
end
|
79
81
|
|
82
|
+
|
80
83
|
def prizes
|
81
84
|
|
82
85
|
end
|
83
86
|
|
84
87
|
def rating
|
85
|
-
raw_rating = document_html.at(
|
88
|
+
raw_rating = document_html.at(Constants.tag(:rating)).content.strip
|
86
89
|
raw_rating.gsub(",",".").to_f
|
87
90
|
end
|
88
91
|
|
89
92
|
def poster
|
90
|
-
poster_url = document_html.at(
|
93
|
+
poster_url = document_html.at(Constants.tag(:poster))["src"]
|
94
|
+
@poster_manager.load_poster(poster_url)
|
95
|
+
end
|
96
|
+
|
97
|
+
def poster_big
|
98
|
+
poster_url = document_html.at(Constants.tag(:poster_big))["href"]
|
99
|
+
@poster_manager.load_poster(poster_url)
|
91
100
|
end
|
92
101
|
|
93
102
|
def to_json
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "open-uri"
|
2
|
+
require "imgur"
|
3
|
+
|
4
|
+
|
5
|
+
class PosterManager
|
6
|
+
def load_poster(posterurl)
|
7
|
+
return posterurl unless FilmAffinity.configuration.imgur_id
|
8
|
+
upload(posterurl, FilmAffinity.configuration.imgur_id)
|
9
|
+
end
|
10
|
+
|
11
|
+
def upload(posterurl, api_id)
|
12
|
+
imgur = Imgur.new(api_id)
|
13
|
+
@dir = __dir__ + "/" + construct_name + ".jpg"
|
14
|
+
save_img_locally(posterurl)
|
15
|
+
local_image = Imgur::LocalImage.new(@dir)
|
16
|
+
uploaded = imgur.upload(local_image)
|
17
|
+
File.delete(@dir)
|
18
|
+
uploaded.link
|
19
|
+
end
|
20
|
+
|
21
|
+
def save_img_locally(posterurl)
|
22
|
+
open(posterurl) {|f|
|
23
|
+
File.open(@dir,"wb") do |file|
|
24
|
+
file.puts f.read
|
25
|
+
end
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def construct_name
|
30
|
+
(0...8).map { (65 + rand(26)).chr }.join
|
31
|
+
end
|
32
|
+
end
|
data/lib/filmaffinity/top.rb
CHANGED
@@ -1,20 +1,26 @@
|
|
1
|
+
|
2
|
+
require "pry"
|
1
3
|
module FilmAffinity
|
2
4
|
class Top
|
3
|
-
def initialize options
|
5
|
+
def initialize options: {}, limit: 30
|
4
6
|
@options = options
|
7
|
+
@limit = limit
|
5
8
|
@json_parser = JsonMoviesParser.new
|
6
9
|
end
|
7
10
|
|
8
11
|
def movies
|
9
|
-
@movies
|
12
|
+
@movies = movies_with_limit
|
10
13
|
end
|
11
14
|
|
12
|
-
def document_html
|
13
|
-
@document_html
|
15
|
+
def document_html from
|
16
|
+
@document_html = Nokogiri::HTML(self.generate_html(from))
|
14
17
|
end
|
15
18
|
|
16
|
-
def generate_html
|
17
|
-
|
19
|
+
def generate_html from
|
20
|
+
params = {'from' => from}
|
21
|
+
url = URI.parse(Constants.urls[:top] % query_options)
|
22
|
+
data = Net::HTTP.post_form(url, params)
|
23
|
+
data.body
|
18
24
|
end
|
19
25
|
|
20
26
|
def query_options
|
@@ -26,9 +32,23 @@ module FilmAffinity
|
|
26
32
|
query_options.gsub(/\&$/,"")
|
27
33
|
end
|
28
34
|
|
29
|
-
def
|
35
|
+
def movies_with_limit
|
36
|
+
collect_from do |from|
|
37
|
+
doc_obj = document_html from
|
38
|
+
parse_movies doc_obj
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def collect_from collection = [], from = 0, &block
|
43
|
+
response = yield(from)
|
44
|
+
collection += response
|
45
|
+
last_position = collection.size
|
46
|
+
response.empty? || last_position >= @limit ? collection.flatten[0..@limit-1] : collect_from(collection,last_position,&block)
|
47
|
+
end
|
48
|
+
|
49
|
+
def parse_movies document_html
|
30
50
|
movies = []
|
31
|
-
document_html.search(".movie-card.movie-card-1").
|
51
|
+
document_html.search(".movie-card.movie-card-1").each_with_index do |movie_card,index|
|
32
52
|
id = movie_card["data-movie-id"].to_i
|
33
53
|
title = movie_card.search(".mc-title a").first.content.strip
|
34
54
|
movie = FilmAffinity::Movie.new id, title
|
@@ -1,121 +1,243 @@
|
|
1
1
|
require_relative "../spec_helper"
|
2
2
|
|
3
3
|
describe "FilmAffinity::Movie" do
|
4
|
+
context "english version" do
|
5
|
+
describe "#title" do
|
6
|
+
subject(:movie) { FilmAffinity::Movie.new(504889) }
|
7
|
+
it "should return an valid title when initializes with no title" do
|
8
|
+
expect(movie.title).to eq("The Truman Show")
|
9
|
+
end
|
10
|
+
end
|
4
11
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
12
|
+
describe "#rating" do
|
13
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
14
|
+
it "should return an Float" do
|
15
|
+
expect(movie.rating).to be_a(Float)
|
16
|
+
end
|
9
17
|
end
|
10
|
-
end
|
11
18
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
19
|
+
describe "#year" do
|
20
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
21
|
+
it "should return an Fixnum" do
|
22
|
+
expect(movie.year).to be_an(Fixnum)
|
23
|
+
end
|
24
|
+
it "should return 1998" do
|
25
|
+
expect(movie.year).to eq(1998)
|
26
|
+
end
|
16
27
|
end
|
17
|
-
end
|
18
28
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
29
|
+
describe "#duration" do
|
30
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
31
|
+
it "should return an Fixnum" do
|
32
|
+
expect(movie.duration).to be_a(Fixnum)
|
33
|
+
end
|
34
|
+
it "should return 103" do
|
35
|
+
expect(movie.duration).to eq(103)
|
36
|
+
end
|
23
37
|
end
|
24
|
-
|
25
|
-
|
38
|
+
|
39
|
+
describe "#country" do
|
40
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
41
|
+
it "should return a String" do
|
42
|
+
expect(movie.country).to be_a(String)
|
43
|
+
end
|
44
|
+
it "should return 'United States'" do
|
45
|
+
expect(movie.country).to eq("United States")
|
46
|
+
end
|
26
47
|
end
|
27
|
-
end
|
28
48
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
49
|
+
describe "#director" do
|
50
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
51
|
+
it "should return a String" do
|
52
|
+
expect(movie.director).to be_a(String)
|
53
|
+
end
|
54
|
+
it "should return 'Peter Weir'" do
|
55
|
+
expect(movie.director).to eq("Peter Weir")
|
56
|
+
end
|
33
57
|
end
|
34
|
-
|
35
|
-
|
58
|
+
|
59
|
+
describe "#script" do
|
60
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
61
|
+
it "should return a String" do
|
62
|
+
expect(movie.script).to be_a(String)
|
63
|
+
end
|
64
|
+
it "should return 'Andrew Niccol'" do
|
65
|
+
expect(movie.script).to eq("Andrew Niccol")
|
66
|
+
end
|
36
67
|
end
|
37
|
-
end
|
38
68
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
69
|
+
describe "#cast" do
|
70
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
71
|
+
it "should return an Array" do
|
72
|
+
expect(movie.cast).to be_an(Array)
|
73
|
+
end
|
74
|
+
it "should to include the passed cast" do
|
75
|
+
expected_cast = [
|
76
|
+
"Jim Carrey",
|
77
|
+
"Laura Linney",
|
78
|
+
"Noah Emmerich",
|
79
|
+
"Ed Harris"
|
80
|
+
]
|
81
|
+
expect(movie.cast).to include(*expected_cast)
|
82
|
+
end
|
43
83
|
end
|
44
|
-
|
45
|
-
|
84
|
+
|
85
|
+
describe "#company" do
|
86
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
87
|
+
it "should return a String" do
|
88
|
+
expect(movie.company).to be_a(String)
|
89
|
+
end
|
90
|
+
it "should return 'Paramount Pictures / Scott Rudin Productions'" do
|
91
|
+
expect(movie.company).to eq("Paramount Pictures / Scott Rudin Productions")
|
92
|
+
end
|
46
93
|
end
|
47
|
-
end
|
48
94
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
95
|
+
describe "#genres" do
|
96
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
97
|
+
it "should return an Array" do
|
98
|
+
expect(movie.genres).to be_an(Array)
|
99
|
+
end
|
100
|
+
it "should to include the passed genres" do
|
101
|
+
expected_genres = [
|
102
|
+
"Drama",
|
103
|
+
"Comedy",
|
104
|
+
"Satire"
|
105
|
+
]
|
106
|
+
expect(movie.genres).to include(*expected_genres)
|
107
|
+
end
|
53
108
|
end
|
54
|
-
|
55
|
-
|
109
|
+
|
110
|
+
describe "#poster" do
|
111
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
112
|
+
it "should return a String" do
|
113
|
+
expect(movie.poster).to be_a(String)
|
114
|
+
end
|
115
|
+
it "should return a .jpg address" do
|
116
|
+
expect(movie.poster).to include(".jpg")
|
117
|
+
end
|
56
118
|
end
|
57
119
|
end
|
58
120
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
121
|
+
context "spanish version" do
|
122
|
+
before :all do
|
123
|
+
FilmAffinity.configure do |config|
|
124
|
+
config.language = "ES"
|
125
|
+
end
|
63
126
|
end
|
64
|
-
|
65
|
-
|
127
|
+
|
128
|
+
describe "#title" do
|
129
|
+
subject(:movie) { FilmAffinity::Movie.new(504889) }
|
130
|
+
it "should return an valid title when initializes with no title" do
|
131
|
+
expect(movie.title).to eq("El show de Truman (Una vida en directo)")
|
132
|
+
end
|
66
133
|
end
|
67
|
-
end
|
68
134
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
135
|
+
describe "#rating" do
|
136
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
137
|
+
it "should return an Float" do
|
138
|
+
expect(movie.rating).to be_a(Float)
|
139
|
+
end
|
73
140
|
end
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
141
|
+
|
142
|
+
describe "#year" do
|
143
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
144
|
+
it "should return an Fixnum" do
|
145
|
+
expect(movie.year).to be_an(Fixnum)
|
146
|
+
end
|
147
|
+
it "should return 1998" do
|
148
|
+
expect(movie.year).to eq(1998)
|
149
|
+
end
|
82
150
|
end
|
83
|
-
end
|
84
151
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
152
|
+
describe "#duration" do
|
153
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
154
|
+
it "should return an Fixnum" do
|
155
|
+
expect(movie.duration).to be_a(Fixnum)
|
156
|
+
end
|
157
|
+
it "should return 103" do
|
158
|
+
expect(movie.duration).to eq(103)
|
159
|
+
end
|
89
160
|
end
|
90
|
-
|
91
|
-
|
161
|
+
|
162
|
+
describe "#country" do
|
163
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
164
|
+
it "should return a String" do
|
165
|
+
expect(movie.country).to be_a(String)
|
166
|
+
end
|
167
|
+
it "should return 'Estados Unidos'" do
|
168
|
+
expect(movie.country).to eq("Estados Unidos")
|
169
|
+
end
|
92
170
|
end
|
93
|
-
end
|
94
171
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
172
|
+
describe "#director" do
|
173
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
174
|
+
it "should return a String" do
|
175
|
+
expect(movie.director).to be_a(String)
|
176
|
+
end
|
177
|
+
it "should return 'Peter Weir'" do
|
178
|
+
expect(movie.director).to eq("Peter Weir")
|
179
|
+
end
|
99
180
|
end
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
181
|
+
|
182
|
+
describe "#script" do
|
183
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
184
|
+
it "should return a String" do
|
185
|
+
expect(movie.script).to be_a(String)
|
186
|
+
end
|
187
|
+
it "should return 'Andrew Niccol'" do
|
188
|
+
expect(movie.script).to eq("Andrew Niccol")
|
189
|
+
end
|
107
190
|
end
|
108
|
-
end
|
109
191
|
|
192
|
+
describe "#cast" do
|
193
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
194
|
+
it "should return an Array" do
|
195
|
+
expect(movie.cast).to be_an(Array)
|
196
|
+
end
|
197
|
+
it "should to include the passed cast" do
|
198
|
+
expected_cast = [
|
199
|
+
"Jim Carrey",
|
200
|
+
"Laura Linney",
|
201
|
+
"Noah Emmerich",
|
202
|
+
"Ed Harris"
|
203
|
+
]
|
204
|
+
expect(movie.cast).to include(*expected_cast)
|
205
|
+
end
|
206
|
+
end
|
110
207
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
208
|
+
describe "#company" do
|
209
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
210
|
+
it "should return a String" do
|
211
|
+
expect(movie.company).to be_a(String)
|
212
|
+
end
|
213
|
+
it "should return 'Paramount Pictures / Scott Rudin Productions'" do
|
214
|
+
expect(movie.company).to eq("Paramount Pictures / Scott Rudin Productions")
|
215
|
+
end
|
115
216
|
end
|
116
|
-
|
117
|
-
|
217
|
+
|
218
|
+
describe "#genres" do
|
219
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
220
|
+
it "should return an Array" do
|
221
|
+
expect(movie.genres).to be_an(Array)
|
222
|
+
end
|
223
|
+
it "should to include the passed genres" do
|
224
|
+
expected_genres = [
|
225
|
+
"Drama",
|
226
|
+
"Comedia",
|
227
|
+
"Sátira"
|
228
|
+
]
|
229
|
+
expect(movie.genres).to include(*expected_genres)
|
230
|
+
end
|
118
231
|
end
|
119
|
-
end
|
120
232
|
|
233
|
+
describe "#poster" do
|
234
|
+
subject(:movie) { FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)") }
|
235
|
+
it "should return a String" do
|
236
|
+
expect(movie.poster).to be_a(String)
|
237
|
+
end
|
238
|
+
it "should return a .jpg address" do
|
239
|
+
expect(movie.poster).to include(".jpg")
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
121
243
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative "../spec_helper"
|
2
|
+
require "pry"
|
2
3
|
|
3
4
|
describe "FilmAffinity::Top" do
|
4
5
|
|
@@ -6,8 +7,8 @@ describe "FilmAffinity::Top" do
|
|
6
7
|
subject(:top) { FilmAffinity::Top.new }
|
7
8
|
|
8
9
|
it "#create_document_html" do
|
9
|
-
document_html = top.document_html
|
10
|
-
expect(document_html).to
|
10
|
+
document_html = top.document_html 0
|
11
|
+
expect(document_html).to respond_to(:search)
|
11
12
|
end
|
12
13
|
|
13
14
|
end
|
@@ -28,13 +29,17 @@ describe "FilmAffinity::Top" do
|
|
28
29
|
el_padrino_movie = FilmAffinity::Movie.new 809297, "El padrino"
|
29
30
|
expect(movies).to include_movie(el_padrino_movie)
|
30
31
|
end
|
32
|
+
it "should return 30 movies" do
|
33
|
+
movies = top.movies
|
34
|
+
expect(movies.size).to eq(30)
|
35
|
+
end
|
31
36
|
end
|
32
37
|
context "with options" do
|
33
38
|
options = {
|
34
39
|
:genre => "BE",
|
35
40
|
:country => "DE"
|
36
41
|
}
|
37
|
-
subject(:top) { FilmAffinity::Top.new options }
|
42
|
+
subject(:top) { FilmAffinity::Top.new options:options }
|
38
43
|
it "should return an array" do
|
39
44
|
movies = top.movies
|
40
45
|
expect(movies).to be_an(Array)
|
@@ -48,6 +53,41 @@ describe "FilmAffinity::Top" do
|
|
48
53
|
hijos_del_tercer_reich_movie = FilmAffinity::Movie.new 831118, "Hijos del Tercer Reich (TV)"
|
49
54
|
expect(movies).to include_movie(hijos_del_tercer_reich_movie)
|
50
55
|
end
|
56
|
+
|
57
|
+
end
|
58
|
+
context "with limit 60" do
|
59
|
+
limit = 60
|
60
|
+
subject(:top) { FilmAffinity::Top.new limit:limit }
|
61
|
+
it "should include 'American History X'" do
|
62
|
+
movies = top.movies
|
63
|
+
american_history_x = FilmAffinity::Movie.new 261972, "American History X"
|
64
|
+
expect(movies).to include_movie(american_history_x)
|
65
|
+
end
|
66
|
+
it "should NOT include 'Con la muerte en los talones'" do
|
67
|
+
movies = top.movies
|
68
|
+
con_la_muerte_en_los_talones = FilmAffinity::Movie.new 351704, "Con la muerte en los talones"
|
69
|
+
expect(movies).not_to include_movie(con_la_muerte_en_los_talones)
|
70
|
+
end
|
71
|
+
it "should return 60 movies" do
|
72
|
+
movies = top.movies
|
73
|
+
expect(movies.size).to eq(60)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
context "with limit 132" do
|
77
|
+
limit = 132
|
78
|
+
subject(:top) { FilmAffinity::Top.new limit:limit }
|
79
|
+
it "should return 132 movies" do
|
80
|
+
movies = top.movies
|
81
|
+
expect(movies.size).to eq(132)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
context "with limit 10" do
|
85
|
+
limit = 10
|
86
|
+
subject(:top) { FilmAffinity::Top.new limit:limit }
|
87
|
+
it "should return 10 movies" do
|
88
|
+
movies = top.movies
|
89
|
+
expect(movies.size).to eq(10)
|
90
|
+
end
|
51
91
|
end
|
52
92
|
end
|
53
93
|
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filmaffinity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- David Santos
|
7
|
+
- David Santos
|
8
|
+
- Oriol Bellido
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
12
|
+
date: 2016-04-18 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: nokogiri
|
@@ -38,6 +39,20 @@ dependencies:
|
|
38
39
|
- - "~>"
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
version: '1.8'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: imgur-api
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
41
56
|
- !ruby/object:Gem::Dependency
|
42
57
|
name: rake
|
43
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,9 +95,11 @@ files:
|
|
80
95
|
- filmaffinity.gemspec
|
81
96
|
- lib/constants/constants.rb
|
82
97
|
- lib/filmaffinity.rb
|
98
|
+
- lib/filmaffinity/configuration.rb
|
83
99
|
- lib/filmaffinity/json-movie-parser.rb
|
84
100
|
- lib/filmaffinity/json-movies-parser.rb
|
85
101
|
- lib/filmaffinity/movie.rb
|
102
|
+
- lib/filmaffinity/poster-manager.rb
|
86
103
|
- lib/filmaffinity/search.rb
|
87
104
|
- lib/filmaffinity/top.rb
|
88
105
|
- spec/filmaffinity/json-movie-parser_spec.rb
|