omdb-api 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +1 -2
- data/README.md +11 -1
- data/Rakefile +2 -4
- data/lib/omdb/api.rb +2 -0
- data/lib/omdb/api/error.rb +5 -15
- data/lib/omdb/api/movie.rb +23 -33
- data/lib/omdb/api/public_api.rb +29 -12
- data/lib/omdb/api/request.rb +5 -5
- data/lib/omdb/api/version.rb +1 -1
- data/omdb-api.gemspec +2 -0
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 62bb6e258bb5205766ccb941ac9d91137698295b
|
4
|
+
data.tar.gz: 03b575568253ace39829ebc50f18098ff81cd876
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0ab3602c4603c6139d2a588775cd6edc7004ef2208064480933f509e4dde26f6962aac643bbb9f584e40402faa40111699d568689b67ca1882da7d8d6a5858e
|
7
|
+
data.tar.gz: fe2ced8a302a4574e0ff4397915d2fae8fcaea7852d2abf096af825015b8d79ffeb0902b9048b6c3e9ef3d5b17e57d2f92a75a6027a940f3c1f7cf19f7272cb8
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -26,11 +26,21 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
+
### Configuration
|
30
|
+
|
29
31
|
First you have to create a client object with your API key
|
30
32
|
|
31
33
|
`client = Omdb::Api::Client.new(api_key: [your API key])`
|
32
34
|
|
33
|
-
|
35
|
+
You can also set the API key with a block
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
client = Omdb::Api::Client.new do |config|
|
39
|
+
config.api_key = api_key
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
### API
|
34
44
|
|
35
45
|
```ruby
|
36
46
|
require 'omdb/api'
|
data/Rakefile
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require 'bundler/gem_tasks'
|
4
2
|
require 'rspec/core/rake_task'
|
5
3
|
require 'rubocop/rake_task'
|
6
4
|
|
7
|
-
RuboCop::RakeTask.new
|
8
5
|
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
RuboCop::RakeTask.new
|
9
7
|
|
10
|
-
task default: %i[rubocop
|
8
|
+
task default: %i[spec rubocop]
|
data/lib/omdb/api.rb
CHANGED
data/lib/omdb/api/error.rb
CHANGED
@@ -1,24 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'klass_param'
|
4
|
+
|
3
5
|
module Omdb
|
4
6
|
module Api
|
5
7
|
class Error
|
6
|
-
|
7
|
-
response
|
8
|
-
error
|
9
|
-
].freeze
|
10
|
-
|
11
|
-
attr_reader(*ERROR_ATTRIBUTES)
|
12
|
-
|
13
|
-
def initialize(response)
|
14
|
-
attrs(response)
|
15
|
-
end
|
8
|
+
include KlassParam
|
16
9
|
|
17
|
-
|
18
|
-
|
19
|
-
instance_variable_set("@#{key.downcase}".to_sym, response[key])
|
20
|
-
end
|
21
|
-
end
|
10
|
+
param :response
|
11
|
+
param :error
|
22
12
|
end
|
23
13
|
end
|
24
14
|
end
|
data/lib/omdb/api/movie.rb
CHANGED
@@ -1,42 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'klass_param'
|
4
|
+
|
3
5
|
module Omdb
|
4
6
|
module Api
|
5
7
|
class Movie
|
6
|
-
|
7
|
-
actors
|
8
|
-
awards
|
9
|
-
country
|
10
|
-
director
|
11
|
-
genre
|
12
|
-
imdbid
|
13
|
-
imdbrating
|
14
|
-
imdbvotes
|
15
|
-
language
|
16
|
-
metascore
|
17
|
-
plot
|
18
|
-
poster
|
19
|
-
rated
|
20
|
-
released
|
21
|
-
runtime
|
22
|
-
title
|
23
|
-
type
|
24
|
-
writer
|
25
|
-
year
|
26
|
-
error
|
27
|
-
].freeze
|
28
|
-
|
29
|
-
attr_reader(*MOVIE_ATTRIBUTES)
|
30
|
-
|
31
|
-
def initialize(response)
|
32
|
-
attrs(response)
|
33
|
-
end
|
8
|
+
include KlassParam
|
34
9
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
10
|
+
param :actors
|
11
|
+
param :awards
|
12
|
+
param :country
|
13
|
+
param :director
|
14
|
+
param :genre
|
15
|
+
param :imdb_id
|
16
|
+
param :imdb_rating
|
17
|
+
param :imdb_votes
|
18
|
+
param :language
|
19
|
+
param :metascore
|
20
|
+
param :plot
|
21
|
+
param :poster
|
22
|
+
param :rated
|
23
|
+
param :released
|
24
|
+
param :runtime
|
25
|
+
param :title
|
26
|
+
param :type
|
27
|
+
param :writer
|
28
|
+
param :year
|
29
|
+
param :error
|
40
30
|
end
|
41
31
|
end
|
42
32
|
end
|
data/lib/omdb/api/public_api.rb
CHANGED
@@ -3,24 +3,41 @@
|
|
3
3
|
module Omdb
|
4
4
|
module Api
|
5
5
|
module PublicApi
|
6
|
-
%i[find_by_id find_by_title
|
6
|
+
%i[find_by_id find_by_title].each do |method|
|
7
7
|
define_method(method) do |value, **options|
|
8
|
-
request = Omdb::Api::Request.new(
|
8
|
+
request = Omdb::Api::Request.new(self, method, value, options)
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
Omdb::Api::Collection.new(movies)
|
17
|
-
elsif request.success?
|
18
|
-
Omdb::Api::Movie.new(request.response)
|
10
|
+
data = request.response
|
11
|
+
movie = __format_data(data)
|
12
|
+
|
13
|
+
if request.success?
|
14
|
+
Omdb::Api::Movie.new(params: movie)
|
19
15
|
else
|
20
|
-
Omdb::Api::Error.new(
|
16
|
+
Omdb::Api::Error.new(params: movie)
|
21
17
|
end
|
22
18
|
end
|
23
19
|
end
|
20
|
+
|
21
|
+
def search(value, options = {})
|
22
|
+
request = Omdb::Api::Request.new(self, 'search', value, options)
|
23
|
+
|
24
|
+
if request.success?
|
25
|
+
Omdb::Api::Collection.new(
|
26
|
+
request.response.fetch('Search').map do |movie|
|
27
|
+
movie = __format_data(movie)
|
28
|
+
|
29
|
+
Omdb::Api::Movie.new(params: movie)
|
30
|
+
end
|
31
|
+
)
|
32
|
+
else
|
33
|
+
Omdb::Api::Error.new(params: request.response)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def __format_data(data)
|
38
|
+
keys = data.keys.map(&:underscore)
|
39
|
+
keys.zip(data.values).to_h
|
40
|
+
end
|
24
41
|
end
|
25
42
|
end
|
26
43
|
end
|
data/lib/omdb/api/request.rb
CHANGED
@@ -3,12 +3,14 @@
|
|
3
3
|
module Omdb
|
4
4
|
module Api
|
5
5
|
class Request
|
6
|
-
BASE_URI = 'https://www.omdbapi.com'
|
6
|
+
BASE_URI = 'https://www.omdbapi.com'.freeze
|
7
7
|
|
8
8
|
attr_reader :api_key, :field, :value, :options
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
@api_key = api_key
|
10
|
+
def initialize(client, method, value, options)
|
11
|
+
@api_key = client.api_key
|
12
|
+
@value = CGI.escape(value)
|
13
|
+
@options = options
|
12
14
|
@field = if /id/.match?(method)
|
13
15
|
'i'
|
14
16
|
elsif /title/.match?(method)
|
@@ -16,8 +18,6 @@ module Omdb
|
|
16
18
|
else
|
17
19
|
's'
|
18
20
|
end
|
19
|
-
@value = CGI.escape(value)
|
20
|
-
@options = options
|
21
21
|
end
|
22
22
|
|
23
23
|
def query_params
|
data/lib/omdb/api/version.rb
CHANGED
data/omdb-api.gemspec
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omdb-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
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: 2019-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: httparty
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -24,6 +38,20 @@ dependencies:
|
|
24
38
|
- - ">="
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: klass_param
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: bundler
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
110
|
version: '0'
|
83
111
|
requirements: []
|
84
112
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.6.13
|
86
114
|
signing_key:
|
87
115
|
specification_version: 4
|
88
116
|
summary: Ruby interface for the OMDB API
|