filmaffinity 0.1.3 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/filmaffinity.gemspec +2 -1
- data/lib/filmaffinity.rb +2 -0
- data/lib/filmaffinity/json-movie-parser.rb +22 -0
- data/lib/filmaffinity/json-movies-parser.rb +19 -0
- data/lib/filmaffinity/movie.rb +5 -0
- data/lib/filmaffinity/search.rb +5 -0
- data/lib/filmaffinity/top.rb +6 -3
- data/spec/filmaffinity/json-movie-parser_spec.rb +15 -0
- data/spec/filmaffinity/json-movies-parser_spec.rb +15 -0
- metadata +21 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99b7c4d40a9e6593e9acfdee78840caf2bc05315
|
4
|
+
data.tar.gz: 18eecf30e69c72d50e2aaf0545d0314861f4bea5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4d840368e62a73569e87d9a8fc6dda2a8bb47cd3f51b10348cf2d7e65ec2725927397dd434aa7f54c2fb870344e9581ee194bc7693e4782fbf599631bdce408
|
7
|
+
data.tar.gz: f2656e1c31454ff8ef4bccf7b4b19bcb8483373891882219c8307f99f5e9a1e4952a1d83b6c59bb89cb3b68f87b25bd127ef209e9bbba948f75aa278b88b990c
|
data/filmaffinity.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'filmaffinity'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.2.3'
|
4
4
|
s.date = '2016-04-05'
|
5
5
|
s.summary = "filmaffinity"
|
6
6
|
s.description = "Easily use Ruby or the command line to find information on Filmaffinity.com"
|
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.homepage = 'https://github.com/davidsantosmerino/filmaffinity-gem'
|
14
14
|
s.license = 'MIT'
|
15
15
|
s.add_dependency 'nokogiri', ' ~> 1.6'
|
16
|
+
s.add_dependency 'json', ' ~> 1.8'
|
16
17
|
s.add_development_dependency 'rake', '~> 10.0'
|
17
18
|
s.add_development_dependency 'rspec', '~> 3.3'
|
18
19
|
end
|
data/lib/filmaffinity.rb
CHANGED
@@ -2,6 +2,8 @@ require "open-uri"
|
|
2
2
|
require "nokogiri"
|
3
3
|
|
4
4
|
require_relative "constants/constants"
|
5
|
+
require_relative "filmaffinity/json-movies-parser"
|
6
|
+
require_relative "filmaffinity/json-movie-parser"
|
5
7
|
require_relative "filmaffinity/movie"
|
6
8
|
require_relative "filmaffinity/search"
|
7
9
|
require_relative "filmaffinity/top"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
class JsonMovieParser
|
4
|
+
|
5
|
+
def to_hash movie
|
6
|
+
{
|
7
|
+
"title" => movie.title,
|
8
|
+
"rating" => movie.rating,
|
9
|
+
"director" => movie.director,
|
10
|
+
"year" => movie.year,
|
11
|
+
"duration" => movie.duration,
|
12
|
+
"country" => movie.country,
|
13
|
+
"script" => movie.script,
|
14
|
+
"cast" => movie.cast,
|
15
|
+
"sinopsis" => movie.sinopsis
|
16
|
+
}
|
17
|
+
end
|
18
|
+
def to_json movie
|
19
|
+
hash = to_hash movie
|
20
|
+
hash.to_json
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class JsonMoviesParser
|
2
|
+
|
3
|
+
def to_hashes movies
|
4
|
+
hashes = []
|
5
|
+
movies.each do |movie|
|
6
|
+
hash = {
|
7
|
+
"id" => movie.id,
|
8
|
+
"title" => movie.title
|
9
|
+
}
|
10
|
+
hashes << hash
|
11
|
+
end
|
12
|
+
hashes
|
13
|
+
end
|
14
|
+
def to_json movies
|
15
|
+
hashes = to_hashes movies
|
16
|
+
hashes.to_json
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/lib/filmaffinity/movie.rb
CHANGED
@@ -4,6 +4,7 @@ module FilmAffinity
|
|
4
4
|
def initialize id,title
|
5
5
|
@id = id
|
6
6
|
@title = title
|
7
|
+
@json_parser = JsonMovieParser.new
|
7
8
|
end
|
8
9
|
|
9
10
|
def document_html
|
@@ -84,5 +85,9 @@ module FilmAffinity
|
|
84
85
|
def poster
|
85
86
|
poster_url = document_html.at('img[itemprop="image"]')["src"]
|
86
87
|
end
|
88
|
+
|
89
|
+
def to_json
|
90
|
+
@json_parser.to_json self
|
91
|
+
end
|
87
92
|
end
|
88
93
|
end
|
data/lib/filmaffinity/search.rb
CHANGED
@@ -4,6 +4,7 @@ module FilmAffinity
|
|
4
4
|
class Search
|
5
5
|
def initialize query
|
6
6
|
@query = query
|
7
|
+
@json_parser = JsonMoviesParser.new
|
7
8
|
end
|
8
9
|
|
9
10
|
def movies
|
@@ -39,5 +40,9 @@ module FilmAffinity
|
|
39
40
|
movies
|
40
41
|
end
|
41
42
|
|
43
|
+
def to_json
|
44
|
+
@json_parser.to_json movies
|
45
|
+
end
|
46
|
+
|
42
47
|
end
|
43
48
|
end
|
data/lib/filmaffinity/top.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module FilmAffinity
|
2
2
|
class Top
|
3
|
-
def initialize options =
|
3
|
+
def initialize options = {}
|
4
4
|
@options = options
|
5
|
+
@json_parser = JsonMoviesParser.new
|
5
6
|
end
|
6
7
|
|
7
8
|
def movies
|
@@ -18,12 +19,10 @@ module FilmAffinity
|
|
18
19
|
|
19
20
|
def query_options
|
20
21
|
query_options = String.new
|
21
|
-
if @options
|
22
22
|
query_options += "?"
|
23
23
|
@options.each do |key,value|
|
24
24
|
query_options += Constants.query_params[key] % value
|
25
25
|
end
|
26
|
-
end
|
27
26
|
query_options.gsub(/\&$/,"")
|
28
27
|
end
|
29
28
|
|
@@ -38,5 +37,9 @@ module FilmAffinity
|
|
38
37
|
movies
|
39
38
|
end
|
40
39
|
|
40
|
+
def to_json
|
41
|
+
@json_parser.to_json movies
|
42
|
+
end
|
43
|
+
|
41
44
|
end
|
42
45
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative "../spec_helper"
|
2
|
+
|
3
|
+
describe "JsonMovieParser" do
|
4
|
+
|
5
|
+
describe "#to_hash" do
|
6
|
+
subject { JsonMovieParser.new }
|
7
|
+
|
8
|
+
it "return the right director for the given movie" do
|
9
|
+
hash = subject.to_hash FilmAffinity::Movie.new(504889, "El show de Truman (Una vida en directo)")
|
10
|
+
expect(hash["director"]).to eq("Peter Weir")
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative "../spec_helper"
|
2
|
+
|
3
|
+
describe "JsonMoviesParser" do
|
4
|
+
|
5
|
+
describe "#to_hashes" do
|
6
|
+
subject { JsonMoviesParser.new }
|
7
|
+
|
8
|
+
it "return some valid ids for a given search" do
|
9
|
+
hashes = subject.to_hashes FilmAffinity::Search.new("truman").movies
|
10
|
+
expect(hashes.map {|hash| hash["id"]}).to include(193232, 504889)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filmaffinity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Santos, Oriol Bellido
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,9 +80,13 @@ files:
|
|
66
80
|
- filmaffinity.gemspec
|
67
81
|
- lib/constants/constants.rb
|
68
82
|
- lib/filmaffinity.rb
|
83
|
+
- lib/filmaffinity/json-movie-parser.rb
|
84
|
+
- lib/filmaffinity/json-movies-parser.rb
|
69
85
|
- lib/filmaffinity/movie.rb
|
70
86
|
- lib/filmaffinity/search.rb
|
71
87
|
- lib/filmaffinity/top.rb
|
88
|
+
- spec/filmaffinity/json-movie-parser_spec.rb
|
89
|
+
- spec/filmaffinity/json-movies-parser_spec.rb
|
72
90
|
- spec/filmaffinity/matchers/include-movie.rb
|
73
91
|
- spec/filmaffinity/movie_spec.rb
|
74
92
|
- spec/filmaffinity/search_spec.rb
|
@@ -99,6 +117,8 @@ signing_key:
|
|
99
117
|
specification_version: 4
|
100
118
|
summary: filmaffinity
|
101
119
|
test_files:
|
120
|
+
- spec/filmaffinity/json-movie-parser_spec.rb
|
121
|
+
- spec/filmaffinity/json-movies-parser_spec.rb
|
102
122
|
- spec/filmaffinity/matchers/include-movie.rb
|
103
123
|
- spec/filmaffinity/movie_spec.rb
|
104
124
|
- spec/filmaffinity/search_spec.rb
|