the_whos 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/the_whos/actor.rb +31 -0
- data/lib/the_whos/title.rb +42 -0
- data/lib/the_whos.rb +103 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63d8e0a82d506323c21e392b3235e3edb376643af66fddb5082db0c7ce0530ae
|
4
|
+
data.tar.gz: bfccf963c024532de1b0d357efb1344590d601fec6709687760e07109b198df3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1785bb18ee55419c9a44174da9cfff830282c5aa6ead5fb1c682ba35d7ddf2e5f0d48022d5870e9168ecd4f2595fc7c9f7b5c5794b4d0c00ffae822a0b80aedb
|
7
|
+
data.tar.gz: ffea712f8144ba7d0c150cccc13d9ba0db8ab8dd8a86a885688f8f8a6ff6c83152777f9e97f7b4d067c4eae39f6eaf5a6c1076457039edc8d815376e687e6458
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
class Actor
|
5
|
+
attr_reader :id, :name, :cast, :known
|
6
|
+
|
7
|
+
def initialize(id)
|
8
|
+
@key_imdb = ARGV[0]
|
9
|
+
@id = id
|
10
|
+
|
11
|
+
url = "https://imdb-api.com/en/API/Name/#{@key_imdb}/#{id}"
|
12
|
+
response = RestClient.get url
|
13
|
+
r_json = JSON.parse response.to_str
|
14
|
+
|
15
|
+
@name = r_json['name']
|
16
|
+
|
17
|
+
@cast, @known = [],[]
|
18
|
+
arr_cast = r_json['castMovies'].to_a
|
19
|
+
arr_cast.size.times do |i|
|
20
|
+
if arr_cast[i]['role'] == 'Actor'
|
21
|
+
@cast << {id: "#{arr_cast[i]['id']}", title: "#{arr_cast[i]['title']}", character: "#{arr_cast[i]['description']}"}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
arr_known = r_json['knownFor'].to_a
|
25
|
+
arr_known.size.times do |i|
|
26
|
+
@known << {id: "#{arr_known[i]['id']}", title: "#{arr_known[i]['title']}", character: "#{arr_known[i]['role']}"}
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
class Title
|
5
|
+
attr_reader :id, :title, :cast, :fullcast
|
6
|
+
|
7
|
+
def initialize(id)
|
8
|
+
@key_imdb = ARGV[0]
|
9
|
+
@id = id
|
10
|
+
|
11
|
+
url = "https://imdb-api.com/en/API/Title/#{@key_imdb}/#{id}/FullActor"
|
12
|
+
response = RestClient.get url
|
13
|
+
r_json = JSON.parse response.to_str
|
14
|
+
|
15
|
+
@title = r_json['title']
|
16
|
+
|
17
|
+
@fullcast, @cast = [],[]
|
18
|
+
arr_cast = r_json['actorList'].to_a
|
19
|
+
arr_cast.size.times do |i|
|
20
|
+
@fullcast << {id: "#{arr_cast[i]['id']}",
|
21
|
+
actor: "#{arr_cast[i]['name']}",
|
22
|
+
character: "#{arr_cast[i]['asCharacter']}"}
|
23
|
+
end
|
24
|
+
10.times do |i|
|
25
|
+
@cast << {id: "#{arr_cast[i]['id']}",
|
26
|
+
actor: "#{arr_cast[i]['name']}",
|
27
|
+
character: "#{arr_cast[i]['asCharacter']}"}
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def plot(lang = 'en')
|
33
|
+
url = "https://imdb-api.com/#{lang}/API/Title/#{@key_imdb}/#{@id}"
|
34
|
+
response = RestClient.get url
|
35
|
+
r_json = JSON.parse response.to_str
|
36
|
+
if lang != 'en'
|
37
|
+
@plot = r_json['plotLocal']
|
38
|
+
else
|
39
|
+
@plot = r_json['plot']
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/the_whos.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require_relative 'the_whos/title'
|
2
|
+
require_relative 'the_whos/actor'
|
3
|
+
|
4
|
+
class TheWhos
|
5
|
+
@key_imdb = ARGV[0]
|
6
|
+
|
7
|
+
def self.create(id)
|
8
|
+
if id.chr == 't'
|
9
|
+
return Title.new(id)
|
10
|
+
elsif id.chr == 'n'
|
11
|
+
return Actor.new(id)
|
12
|
+
else
|
13
|
+
return 'Error'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.search_title(expression)
|
18
|
+
expression = expression.gsub(' ', '@')
|
19
|
+
url = "https://imdb-api.com/en/API/SearchTitle/#{@key_imdb}/#{expression}"
|
20
|
+
response = RestClient.get url
|
21
|
+
r_json = JSON.parse response.to_str
|
22
|
+
arr_search = r_json['results'].to_a
|
23
|
+
results = Array.new
|
24
|
+
arr_search.size.times do |i|
|
25
|
+
results << {id: "#{arr_search[i]['id']}", title: "#{arr_search[i]['title']}"}
|
26
|
+
end
|
27
|
+
return results
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.search_actor(expression)
|
31
|
+
expression = expression.gsub(' ', '@')
|
32
|
+
url = "https://imdb-api.com/en/API/SearchName/#{@key_imdb}/#{expression}"
|
33
|
+
response = RestClient.get url
|
34
|
+
r_json = JSON.parse response.to_str
|
35
|
+
arr_search = r_json['results'].to_a
|
36
|
+
results = Array.new
|
37
|
+
arr_search.size.times do |i|
|
38
|
+
results << {id: "#{arr_search[i]['id']}", title: "#{arr_search[i]['title']}"}
|
39
|
+
end
|
40
|
+
return results
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.match_actor(title_a, title_b)
|
44
|
+
if title_a.class == String
|
45
|
+
title_a = Title.new(title_a)
|
46
|
+
end
|
47
|
+
if title_b.class == String
|
48
|
+
title_b = Title.new(title_b)
|
49
|
+
end
|
50
|
+
match = Array.new
|
51
|
+
title_a.fullcast.each do |actor_a|
|
52
|
+
title_b.fullcast.each do |actor_b|
|
53
|
+
if actor_a[:id] == actor_b[:id]
|
54
|
+
match << "#{actor_a[:actor].to_s} (#{actor_a[:id]})"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
if match.empty? == true
|
59
|
+
return 'Not Match'
|
60
|
+
else
|
61
|
+
return match
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.match_title(actor_a, actor_b)
|
66
|
+
if actor_a.class == String
|
67
|
+
actor_a = Actor.new(actor_a)
|
68
|
+
end
|
69
|
+
if actor_b.class == String
|
70
|
+
actor_b = Actor.new(actor_b)
|
71
|
+
end
|
72
|
+
match = Array.new
|
73
|
+
actor_a.cast.each do |title_a|
|
74
|
+
actor_b.cast.each do |title_b|
|
75
|
+
if title_a[:id] == title_b[:id]
|
76
|
+
match << "#{title_a[:title]} (#{title_a[:id]})"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
if match.empty? == true
|
81
|
+
return 'Not Match'
|
82
|
+
else
|
83
|
+
return match
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.who(title, actor)
|
88
|
+
if title.class == String
|
89
|
+
title = Title.new(title)
|
90
|
+
end
|
91
|
+
if actor.class == String
|
92
|
+
actor = Actor.new(actor)
|
93
|
+
end
|
94
|
+
title.fullcast.each do |cast|
|
95
|
+
if cast[:id] == actor.id
|
96
|
+
return cast[:character]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
return 'not appear'
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the_whos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ramiro Eloisa
|
@@ -21,6 +21,9 @@ extensions: []
|
|
21
21
|
extra_rdoc_files: []
|
22
22
|
files:
|
23
23
|
- README.md
|
24
|
+
- lib/the_whos.rb
|
25
|
+
- lib/the_whos/actor.rb
|
26
|
+
- lib/the_whos/title.rb
|
24
27
|
homepage: https://github.com/RamEloisa/the_whos.git
|
25
28
|
licenses:
|
26
29
|
- MIT
|