the_whos 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/actor.rb +31 -0
  3. data/lib/the_whos.rb +103 -0
  4. data/lib/title.rb +42 -0
  5. metadata +6 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd95eec1c0a3845af7bcf884e9022693a701a9a97688205947c847c9f84cdeba
4
- data.tar.gz: 6b8ae647c2f6c993a03b349a62e33eaf137c83b7850ae40bfdf9f964b834dad6
3
+ metadata.gz: 2757400666285928526c47ef20e9b0983fe057d63ccebb62f5b9910bb8359927
4
+ data.tar.gz: 5a0ed60aea6d27f942ba6938b4a0b7617d23b40cb41665c1a610c92dbc3e986e
5
5
  SHA512:
6
- metadata.gz: fbadc47b16fde1f47b6cb4a149069f553015d12e65cc6346c831d322555addfa7bfd94c12e313dc9625dd7a5579ee9acf9626a627495fb282e370b6bbfd390c9
7
- data.tar.gz: 433e92edccc3f1a68e76089be90bfd7746c59a88c0a19b7610fe3a0124470bf77a19f0fbc1619a186261aed008ecae2b51e41b7d5fa4979dc17d439672ce5834
6
+ metadata.gz: 472bb15773e6e7390ce9a26f8796e56e83e219aad9a7ad4412f62a890b53bc38946b502362074de69d7195534607771b6ceb5a3dc9eba255198e3a79fa8490ac
7
+ data.tar.gz: abd498d00fec17ade1038ad895988930d3dd0cc5ac870047679a18e36b7dd0a6a9070ebbc2ec203d9d14f0599c652487f5a76ba51f61eecfe64fda31079d61ce
data/lib/actor.rb ADDED
@@ -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
data/lib/the_whos.rb ADDED
@@ -0,0 +1,103 @@
1
+ require_relative 'title'
2
+ require_relative '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_title(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_actor(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
data/lib/title.rb ADDED
@@ -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
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramiro Eloisa
@@ -19,8 +19,11 @@ email: ram.eloisalg@egmail.com
19
19
  executables: []
20
20
  extensions: []
21
21
  extra_rdoc_files: []
22
- files: []
23
- homepage:
22
+ files:
23
+ - lib/actor.rb
24
+ - lib/the_whos.rb
25
+ - lib/title.rb
26
+ homepage: https://github.com/RamEloisa/the_whos.git
24
27
  licenses:
25
28
  - MIT
26
29
  metadata: {}