restool 0.1.7 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/restool.rb +0 -2
- data/lib/restool/service/remote_client.rb +18 -25
- data/lib/restool/service/restool_service.rb +1 -1
- data/lib/restool/settings/loader.rb +2 -12
- data/lib/restool/settings/models.rb +1 -2
- data/lib/restool/version.rb +1 -1
- metadata +6 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b50f0e2b71d71c4cc51b17cca04939e16bbae2aa1c8ad30332d9ec93bfe8d2a3
|
4
|
+
data.tar.gz: f854bbe253e0b519df1d4fbc8354bef2a1905bb8ef2410f16fcb3d783cc65079
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac1c66d272cb7bd3c76f9697f0d8f8b1d5095e29202275b625b0e811155e1d24f2f411ff2d419008fb894e3b005377a5d9e000b75d32618c55636887f5888bd4
|
7
|
+
data.tar.gz: 53cffe026ac8a0134b5e6e3d46c5d2f3a3ec99c50d1583d6af4b79bbcbc3701f1778d4a94a6a079cd61f0981704a21b26bf59d925c65096d08fe3ba54085b83f
|
data/lib/restool.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require "net/http"
|
2
|
+
require "net/https"
|
3
3
|
require_relative 'request_utils'
|
4
4
|
require_relative '../logger/request_logger'
|
5
5
|
|
@@ -7,30 +7,9 @@ module Restool
|
|
7
7
|
module Service
|
8
8
|
class RemoteClient
|
9
9
|
|
10
|
-
def initialize(host, verify_ssl,
|
10
|
+
def initialize(host, verify_ssl, timeout, opts)
|
11
11
|
@request_logger = Restool::RequestLogger.new(host, opts)
|
12
|
-
|
13
|
-
@connection = if persistent_connection
|
14
|
-
PersistentHTTP.new(
|
15
|
-
pool_size: persistent_connection.pool_size,
|
16
|
-
pool_timeout: timeout,
|
17
|
-
warn_timeout: persistent_connection.warn_timeout,
|
18
|
-
force_retry: persistent_connection.force_retry,
|
19
|
-
url: host,
|
20
|
-
read_timeout: timeout,
|
21
|
-
open_timeout: timeout,
|
22
|
-
verify_mode: verify_ssl?(verify_ssl)
|
23
|
-
)
|
24
|
-
else
|
25
|
-
uri = URI.parse(host)
|
26
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
27
|
-
http.use_ssl = uri.is_a?(URI::HTTPS)
|
28
|
-
http.verify_mode = verify_ssl?(verify_ssl)
|
29
|
-
http.read_timeout = timeout
|
30
|
-
http.open_timeout = timeout
|
31
|
-
http.set_debug_output($stdout) if opts[:debug]
|
32
|
-
http
|
33
|
-
end
|
12
|
+
@connection = build_connection(host, verify_ssl, timeout, opts)
|
34
13
|
end
|
35
14
|
|
36
15
|
def make_request(path, method, request_params, headers, basic_auth)
|
@@ -43,6 +22,20 @@ module Restool
|
|
43
22
|
|
44
23
|
private
|
45
24
|
|
25
|
+
def build_connection(host, verify_ssl, timeout, opts)
|
26
|
+
uri = URI.parse(host)
|
27
|
+
|
28
|
+
connection = Net::HTTP.new(uri.host, uri.port)
|
29
|
+
|
30
|
+
connection.use_ssl = uri.is_a?(URI::HTTPS)
|
31
|
+
connection.verify_mode = verify_ssl?(verify_ssl)
|
32
|
+
connection.read_timeout = timeout
|
33
|
+
connection.open_timeout = timeout
|
34
|
+
connection.set_debug_output($stdout) if opts[:debug]
|
35
|
+
|
36
|
+
connection
|
37
|
+
end
|
38
|
+
|
46
39
|
def verify_ssl?(verify_ssl_setting)
|
47
40
|
verify_ssl_setting ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
|
48
41
|
end
|
@@ -11,7 +11,7 @@ module Restool
|
|
11
11
|
@service_config = service_config
|
12
12
|
@response_handler = response_handler
|
13
13
|
@remote_client = Restool::Service::RemoteClient.new(service_config.host, service_config.verify_ssl,
|
14
|
-
service_config.
|
14
|
+
service_config.timeout, service_config.opts)
|
15
15
|
|
16
16
|
define_operations(
|
17
17
|
@service_config, method(:make_request), method(:make_request_with_uri_params)
|
@@ -13,7 +13,7 @@ module Restool
|
|
13
13
|
|
14
14
|
def self.load(service_name, opts)
|
15
15
|
service_config = config['services'].detect do |service|
|
16
|
-
service['name'] == service_name
|
16
|
+
service['name'] == service_name.to_s
|
17
17
|
end
|
18
18
|
|
19
19
|
raise "Service #{service_name} not found in configuration" unless service_config
|
@@ -30,18 +30,9 @@ module Restool
|
|
30
30
|
[]
|
31
31
|
end
|
32
32
|
|
33
|
-
basic_auth = service_config['basic_auth'] || service_config['basic_authentication']
|
33
|
+
basic_auth = opts['basic_auth'] || opts['basic_authentication'] || service_config['basic_auth'] || service_config['basic_authentication']
|
34
34
|
basic_auth = BasicAuthentication.new(basic_auth['user'], basic_auth['password']) if basic_auth
|
35
35
|
|
36
|
-
persistent_connection = service_config['persistent']
|
37
|
-
persistent_connection = if persistent_connection
|
38
|
-
PersistentConnection.new(
|
39
|
-
persistent_connection['pool_size'],
|
40
|
-
persistent_connection['warn_timeout'],
|
41
|
-
persistent_connection['force_retry'],
|
42
|
-
)
|
43
|
-
end
|
44
|
-
|
45
36
|
# Support host + common path in url config, e.g. api.com/v2/
|
46
37
|
paths_prefix_in_host = URI(service_config['url']).path
|
47
38
|
|
@@ -49,7 +40,6 @@ module Restool
|
|
49
40
|
service_config['name'],
|
50
41
|
service_config['url'],
|
51
42
|
service_config['operations'].map { |operation| build_operation(operation, paths_prefix_in_host) },
|
52
|
-
persistent_connection,
|
53
43
|
service_config['timeout'] || DEFAULT_TIMEOUT,
|
54
44
|
representations,
|
55
45
|
basic_auth,
|
@@ -4,11 +4,10 @@ module Restool
|
|
4
4
|
|
5
5
|
Operation = Struct.new(:name, :path, :method, :uri_params, :response)
|
6
6
|
OperationResponse = Struct.new(:fields)
|
7
|
-
Service = Struct.new(:name, :host, :operations, :
|
7
|
+
Service = Struct.new(:name, :host, :operations, :timeout, :representations, :basic_auth, :verify_ssl, :opts)
|
8
8
|
Representation = Struct.new(:name, :fields)
|
9
9
|
RepresentationField = Struct.new(:key, :metonym, :type)
|
10
10
|
BasicAuthentication = Struct.new(:user, :password)
|
11
|
-
PersistentConnection = Struct.new(:respool_size, :want_timeout, :force_retry)
|
12
11
|
OperationResponsField = RepresentationField
|
13
12
|
|
14
13
|
end
|
data/lib/restool/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Andres Zeni
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: persistent_http
|
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'
|
11
|
+
date: 2020-09-13 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description: Make HTTP requests and handle its responses using simple method calls.
|
28
14
|
Restool turns your HTTP API and its responses into Ruby interfaces.
|
29
15
|
email:
|
@@ -51,7 +37,7 @@ homepage: https://github.com/jzeni/restool
|
|
51
37
|
licenses:
|
52
38
|
- MIT
|
53
39
|
metadata: {}
|
54
|
-
post_install_message:
|
40
|
+
post_install_message:
|
55
41
|
rdoc_options: []
|
56
42
|
require_paths:
|
57
43
|
- lib
|
@@ -67,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
53
|
version: '0'
|
68
54
|
requirements: []
|
69
55
|
rubygems_version: 3.0.1
|
70
|
-
signing_key:
|
56
|
+
signing_key:
|
71
57
|
specification_version: 4
|
72
58
|
summary: Turn your API and its responses into Ruby interfaces.
|
73
59
|
test_files: []
|