omdb-api 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/lib/omdb/api/public_api.rb +22 -23
- data/lib/omdb/api/request.rb +14 -11
- data/lib/omdb/api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b434f90503d4999be549f1e24e40bccfb83c2e0d568838c9f6840e97ed60a80f
|
4
|
+
data.tar.gz: 6ebabe3d1e8048ca976d92a90d2733cf266bc4d6c83405ffaac0255f8807a053
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bc3aa06e4c30f98ab3659ed1e701134e063e8d713fb40c3c4e1e7e5e70626f6b3a6ba2343b1d74fe49044d2674772feab1c21e457ba43ba1f067d80fbf9bd6d
|
7
|
+
data.tar.gz: b3dfb55d02b3ec34adfd18fbb62878afa89fee38771a892e90eb1e89e4f09f24d088dc27316304c328cca2c6015ecc0cb6eb8488a2ab31d963d01e02d957f0de
|
data/.rubocop.yml
CHANGED
data/lib/omdb/api/public_api.rb
CHANGED
@@ -5,38 +5,37 @@ module Omdb
|
|
5
5
|
module PublicApi
|
6
6
|
%i[find_by_id find_by_title].each do |method|
|
7
7
|
define_method(method) do |value, **options|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
else
|
16
|
-
Omdb::Api::Error.new(movie)
|
8
|
+
Omdb::Api::Request.call(self, method, value, options) do |response|
|
9
|
+
response = format_response(response)
|
10
|
+
if response.dig('response') == 'False'
|
11
|
+
Omdb::Api::Error.new(response)
|
12
|
+
else
|
13
|
+
Omdb::Api::Movie.new(response)
|
14
|
+
end
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
21
19
|
def search(value, options = {})
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
movie = __format_data(movie)
|
20
|
+
Omdb::Api::Request.call(self, 'search', value, options) do |response|
|
21
|
+
begin
|
22
|
+
Omdb::Api::Collection.new(
|
23
|
+
response.fetch('Search').map do |movie_data|
|
24
|
+
response = format_response(movie_data)
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
Omdb::Api::Movie.new(response)
|
27
|
+
end
|
28
|
+
)
|
29
|
+
rescue StandardError
|
30
|
+
Omdb::Api::Error.new(response)
|
31
|
+
end
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
private
|
36
|
+
|
37
|
+
def format_response(response)
|
38
|
+
response.keys.map(&:underscore).zip(response.values).to_h
|
40
39
|
end
|
41
40
|
end
|
42
41
|
end
|
data/lib/omdb/api/request.rb
CHANGED
@@ -5,10 +5,14 @@ module Omdb
|
|
5
5
|
class Request
|
6
6
|
BASE_URI = 'https://www.omdbapi.com'
|
7
7
|
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :client, :field, :value, :options
|
9
|
+
|
10
|
+
def self.call(client, method, value, options, &block)
|
11
|
+
new(client, method, value, options).make_get_to_imdb_api(&block)
|
12
|
+
end
|
9
13
|
|
10
14
|
def initialize(client, method, value, options)
|
11
|
-
@
|
15
|
+
@client = client
|
12
16
|
@value = CGI.escape(value)
|
13
17
|
@options = options
|
14
18
|
@field = if /id/.match?(method)
|
@@ -20,16 +24,15 @@ module Omdb
|
|
20
24
|
end
|
21
25
|
end
|
22
26
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
def make_get_to_imdb_api
|
28
|
+
params = {
|
29
|
+
query: {
|
30
|
+
apikey: client.api_key,
|
31
|
+
field.to_s => value.to_s
|
32
|
+
}.merge(options)
|
33
|
+
}
|
30
34
|
|
31
|
-
|
32
|
-
(response['Response'] || response['root']['response']) == 'True'
|
35
|
+
yield HTTParty.get(BASE_URI, params)
|
33
36
|
end
|
34
37
|
end
|
35
38
|
end
|
data/lib/omdb/api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omdb-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Palaniuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|