restool 0.1.6 → 1.0.4
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/logger/request_logger.rb +11 -3
- data/lib/restool/service/remote_client.rb +18 -25
- data/lib/restool/service/restool_service.rb +1 -1
- data/lib/restool/settings/loader.rb +6 -14
- data/lib/restool/settings/models.rb +1 -2
- data/lib/restool/version.rb +2 -1
- metadata +7 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbb07cae8d7353e4589d17790d5703c80bbf7279c93044602705281af6cbaafd
|
4
|
+
data.tar.gz: 61ec6541cf4cafbf66b83fa223eb1092677ae0c2b90ba10ecee3dd99bca143ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfc5f9475718070390a2f240b3187389924396e1dfce1f29b17a995bf0cc1337031dc233ba72747bf72ee6ce72502a06449802d5b23f4cd7fb86efd7e37c463c
|
7
|
+
data.tar.gz: ee162222b723ad377ed4669dcbf1f6275ba46be10d65ee6c5c6de09a54b0cd91dcc7be281fc6f132d7f823551e7fcdd29a79c69210ce9007d0c4d3810a5f23d2
|
data/lib/restool.rb
CHANGED
@@ -12,6 +12,10 @@ module Restool
|
|
12
12
|
log_response(response) if log?
|
13
13
|
|
14
14
|
response
|
15
|
+
rescue StandardError => e
|
16
|
+
log_error(e) if log?
|
17
|
+
|
18
|
+
raise
|
15
19
|
end
|
16
20
|
|
17
21
|
def logger
|
@@ -31,15 +35,19 @@ module Restool
|
|
31
35
|
def log_request(request)
|
32
36
|
logger.info { "Restool Service #{@host}" }
|
33
37
|
logger.info { "#{request.method.upcase} #{request.path}" }
|
34
|
-
logger.info { format_hash(request.headers) }
|
35
|
-
logger.debug { format_hash(request.params) }
|
38
|
+
logger.info { "Headers: { #{format_hash(request.headers)} }" }
|
39
|
+
logger.debug { "Params: { #{format_hash(request.params)} }" }
|
36
40
|
end
|
37
41
|
|
38
42
|
def log_response(response)
|
39
|
-
logger.info { "Restool response (status #{response.code})" }
|
43
|
+
logger.info { "Restool response (status #{response.code}):" }
|
40
44
|
logger.debug { response.body }
|
41
45
|
end
|
42
46
|
|
47
|
+
def log_error(error)
|
48
|
+
logger.error { "Restool error: #{error}" }
|
49
|
+
end
|
50
|
+
|
43
51
|
def format_hash(headers)
|
44
52
|
headers.map { |key, value| "#{key}: #{value}" }.join(", ")
|
45
53
|
end
|
@@ -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)
|
@@ -11,14 +11,16 @@ module Restool
|
|
11
11
|
DEFAULT_SSL_VERIFY = false
|
12
12
|
|
13
13
|
|
14
|
-
def self.load(service_name, opts)
|
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
|
20
20
|
|
21
|
-
build_service(service_config, opts)
|
21
|
+
@service ||= build_service(service_config, opts)
|
22
|
+
|
23
|
+
@service
|
22
24
|
end
|
23
25
|
|
24
26
|
private
|
@@ -30,18 +32,9 @@ module Restool
|
|
30
32
|
[]
|
31
33
|
end
|
32
34
|
|
33
|
-
basic_auth = service_config['basic_auth'] || service_config['basic_authentication']
|
35
|
+
basic_auth = opts['basic_auth'] || opts['basic_authentication'] || service_config['basic_auth'] || service_config['basic_authentication']
|
34
36
|
basic_auth = BasicAuthentication.new(basic_auth['user'], basic_auth['password']) if basic_auth
|
35
37
|
|
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
38
|
# Support host + common path in url config, e.g. api.com/v2/
|
46
39
|
paths_prefix_in_host = URI(service_config['url']).path
|
47
40
|
|
@@ -49,7 +42,6 @@ module Restool
|
|
49
42
|
service_config['name'],
|
50
43
|
service_config['url'],
|
51
44
|
service_config['operations'].map { |operation| build_operation(operation, paths_prefix_in_host) },
|
52
|
-
persistent_connection,
|
53
45
|
service_config['timeout'] || DEFAULT_TIMEOUT,
|
54
46
|
representations,
|
55
47
|
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.
|
4
|
+
version: 1.0.4
|
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: '2'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '2'
|
11
|
+
date: 2020-11-29 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
|
@@ -66,8 +52,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
52
|
- !ruby/object:Gem::Version
|
67
53
|
version: '0'
|
68
54
|
requirements: []
|
69
|
-
rubygems_version: 3.0.1
|
70
|
-
signing_key:
|
55
|
+
rubygems_version: 3.2.0.rc.1
|
56
|
+
signing_key:
|
71
57
|
specification_version: 4
|
72
58
|
summary: Turn your API and its responses into Ruby interfaces.
|
73
59
|
test_files: []
|