api_recipes 2.8.1 → 2.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/api_recipes/api.rb +1 -1
- data/lib/api_recipes/configuration.rb +40 -4
- data/lib/api_recipes/endpoint.rb +6 -2
- data/lib/api_recipes/response.rb +1 -1
- data/lib/api_recipes/route.rb +1 -1
- data/lib/api_recipes/settings.rb +3 -1
- data/lib/api_recipes/version.rb +1 -1
- data/lib/api_recipes.rb +5 -0
- metadata +14 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c1d3c91651ea71c01c7ae5368076aa3b693422eedfd373b5206f6072b396df3
|
4
|
+
data.tar.gz: 19a3ab41ca84d22efc0bb33918665bb3a67444c6ce070f53267519ca23334616
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cc0d5bd301ba17b76b1a19b4f0a7d99edef92953117e9f6c4a3b76c245e08b638b4f01b133b7429058de9236c3bc07900e94f7bb72ab8a75ddeb5ae31171f78
|
7
|
+
data.tar.gz: 15407e45843f2e83351c8559b129b33019797b25f568364dac2dc0c5ad0c90e952f9b60132354e9d3c65a464970d5296af962c8a8f45e07f10fe727dc245d25e
|
data/lib/api_recipes/api.rb
CHANGED
@@ -4,7 +4,7 @@ module ApiRecipes
|
|
4
4
|
attr_accessor :name, :configs, :authorization, :basic_auth
|
5
5
|
attr_reader :base_configs, :object
|
6
6
|
|
7
|
-
BASE_CONFIGS_KEYS = [:protocol, :host, :port, :api_version, :timeout, :on_bad_code, :verify_with]
|
7
|
+
BASE_CONFIGS_KEYS = [:protocol, :host, :port, :api_version, :timeout, :on_bad_code, :mime_type, :verify_with]
|
8
8
|
|
9
9
|
def initialize(name, configs, object)
|
10
10
|
@name = name
|
@@ -1,12 +1,16 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'erb'
|
3
|
+
require 'logger'
|
4
|
+
|
1
5
|
module ApiRecipes
|
2
6
|
class Configuration
|
3
7
|
|
4
|
-
attr_accessor :log_to, :log_level, :print_urls
|
8
|
+
attr_accessor :log_to, :log_level, :print_urls, :apis_files_paths
|
5
9
|
|
6
10
|
def apis_configs=(configs = {})
|
7
11
|
raise ArgumentError, 'apis_configs must be an Hash' unless configs.is_a? Hash
|
12
|
+
|
8
13
|
@apis_configs = configs.deep_symbolize_keys
|
9
|
-
ApiRecipes._aprcps_define_global_apis
|
10
14
|
end
|
11
15
|
|
12
16
|
def apis_configs
|
@@ -16,13 +20,41 @@ module ApiRecipes
|
|
16
20
|
@apis_configs
|
17
21
|
end
|
18
22
|
|
23
|
+
def apis_files_paths=(paths = [])
|
24
|
+
raise ArgumentError, 'apis_files_paths must be an Array' unless paths.is_a? Array
|
25
|
+
|
26
|
+
@apis_files_paths = paths
|
27
|
+
@apis_files_paths.each do |file_path|
|
28
|
+
template = ERB.new File.read File.expand_path(file_path)
|
29
|
+
data = begin
|
30
|
+
YAML.load(template.result(binding), aliases: true)
|
31
|
+
rescue ArgumentError
|
32
|
+
YAML.load(template.result binding)
|
33
|
+
end.deep_symbolize_keys
|
34
|
+
# Merge file contents into apis_configs
|
35
|
+
data.each do |api, params|
|
36
|
+
if apis_configs[api]
|
37
|
+
logger.debug "File at #{file_path} overrides config for '#{api}' API"
|
38
|
+
end
|
39
|
+
apis_configs[api] = params
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def apis_files_paths
|
45
|
+
unless @apis_files_paths
|
46
|
+
@apis_files_paths = []
|
47
|
+
end
|
48
|
+
@apis_files_paths
|
49
|
+
end
|
50
|
+
|
19
51
|
def logger=(logger)
|
20
52
|
@logger = logger
|
21
53
|
end
|
22
54
|
|
23
55
|
def logger
|
24
56
|
unless @logger
|
25
|
-
log = ::Logger.new(log_to)
|
57
|
+
log = ::Logger.new(log_to || STDOUT)
|
26
58
|
log.level = normalize_log_level
|
27
59
|
log.progname = 'ApiRecipes'
|
28
60
|
@logger = log
|
@@ -31,6 +63,10 @@ module ApiRecipes
|
|
31
63
|
@logger
|
32
64
|
end
|
33
65
|
|
66
|
+
def setup
|
67
|
+
ApiRecipes._aprcps_define_global_apis
|
68
|
+
end
|
69
|
+
|
34
70
|
private
|
35
71
|
|
36
72
|
# @private
|
@@ -42,7 +78,7 @@ module ApiRecipes
|
|
42
78
|
when :error, ::Logger::ERROR, 'error' then ::Logger::ERROR
|
43
79
|
when :fatal, ::Logger::FATAL, 'fatal' then ::Logger::FATAL
|
44
80
|
else
|
45
|
-
Logger::
|
81
|
+
ENV['LOG_LEVEL'] || Logger::DEBUG
|
46
82
|
end
|
47
83
|
end
|
48
84
|
end
|
data/lib/api_recipes/endpoint.rb
CHANGED
@@ -32,7 +32,12 @@ module ApiRecipes
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def url
|
35
|
-
@route
|
35
|
+
if @route
|
36
|
+
@route.url
|
37
|
+
else
|
38
|
+
ApiRecipes.logger.debug "No route configured for '#{api.name}#{absolute_path}': Is option 'route: no' present?"
|
39
|
+
nil
|
40
|
+
end
|
36
41
|
end
|
37
42
|
|
38
43
|
private
|
@@ -62,7 +67,6 @@ module ApiRecipes
|
|
62
67
|
end
|
63
68
|
end
|
64
69
|
end
|
65
|
-
# Route.new(api: @api, endpoint: self, name: route_name, attributes: route_attrs, req_pars: request_params).start_request &block
|
66
70
|
end
|
67
71
|
|
68
72
|
def ensure_route_does_not_clash(route_name)
|
data/lib/api_recipes/response.rb
CHANGED
data/lib/api_recipes/route.rb
CHANGED
data/lib/api_recipes/settings.rb
CHANGED
@@ -10,7 +10,8 @@ module ApiRecipes
|
|
10
10
|
timeout: 3,
|
11
11
|
on_bad_code: 'raise',
|
12
12
|
endpoints: {},
|
13
|
-
verify_with: nil
|
13
|
+
verify_with: nil,
|
14
|
+
mime_type: nil
|
14
15
|
}
|
15
16
|
|
16
17
|
DEFAULT_ROUTE_ATTRIBUTES = {
|
@@ -20,6 +21,7 @@ module ApiRecipes
|
|
20
21
|
ok_code: nil,
|
21
22
|
timeout: DEFAULT[:timeout],
|
22
23
|
on_bad_code: DEFAULT[:on_bad_code],
|
24
|
+
mime_type: DEFAULT[:mime_type],
|
23
25
|
verify_with: DEFAULT[:verify_with]
|
24
26
|
}
|
25
27
|
|
data/lib/api_recipes/version.rb
CHANGED
data/lib/api_recipes.rb
CHANGED
@@ -65,6 +65,7 @@ module ApiRecipes
|
|
65
65
|
def self.configure
|
66
66
|
if block_given?
|
67
67
|
yield(configuration)
|
68
|
+
configuration.setup
|
68
69
|
else
|
69
70
|
configuration
|
70
71
|
end
|
@@ -145,6 +146,10 @@ module ApiRecipes
|
|
145
146
|
global_api_configs
|
146
147
|
end
|
147
148
|
end
|
149
|
+
|
150
|
+
def self.logger
|
151
|
+
configuration.logger
|
152
|
+
end
|
148
153
|
end
|
149
154
|
|
150
155
|
# Monkey-patch URI so it can accept dashed hostnames like "web-service-1"
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_recipes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Verlato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.4
|
19
|
+
version: '4.4'
|
20
|
+
- - "<="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.1'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4.4'
|
30
|
+
- - "<="
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
32
|
+
version: '5.1'
|
27
33
|
description:
|
28
34
|
email:
|
29
35
|
- averlato@gmail.com
|
@@ -55,14 +61,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
61
|
requirements:
|
56
62
|
- - ">="
|
57
63
|
- !ruby/object:Gem::Version
|
58
|
-
version: 2.
|
64
|
+
version: 2.7.0
|
59
65
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
66
|
requirements:
|
61
67
|
- - ">="
|
62
68
|
- !ruby/object:Gem::Version
|
63
69
|
version: '0'
|
64
70
|
requirements: []
|
65
|
-
rubygems_version: 3.
|
71
|
+
rubygems_version: 3.3.7
|
66
72
|
signing_key:
|
67
73
|
specification_version: 4
|
68
74
|
summary: Consume HTTP APIs with style
|