api_recipes 2.8.0 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/api_recipes/api.rb +1 -1
- data/lib/api_recipes/configuration.rb +37 -2
- data/lib/api_recipes/endpoint.rb +0 -1
- 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/utils.rb +31 -0
- data/lib/api_recipes/version.rb +1 -1
- data/lib/api_recipes.rb +5 -5
- 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: c808d9077305dc07cd888f517b57f1522490866a548dc769a3c96c083d24ce27
|
4
|
+
data.tar.gz: 205b4aaaa135b8682f7d7f0d44f471263852e997f2b1791fe60eea4efc0a2ee3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89acbd66ece24f8cd88100eb447c45e3b73c30c9f894b51a5995aa7697f6a76b92bae0b41c117dbc0b38f993876ca8b4efd17f64eaf7ca1ae31e0d04b5544120
|
7
|
+
data.tar.gz: a831d53f7a337cc65ec28d09eb74ca8efa69123cf34ae835776c5414dd58725cc0223e7ee7aa70d0c1dbbebfff924f8d3d8340227ade47f42d7be4e3ffd877dd
|
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,15 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'erb'
|
3
|
+
|
1
4
|
module ApiRecipes
|
2
5
|
class Configuration
|
3
6
|
|
4
|
-
attr_accessor :log_to, :log_level, :print_urls
|
7
|
+
attr_accessor :log_to, :log_level, :print_urls, :apis_files_paths
|
5
8
|
|
6
9
|
def apis_configs=(configs = {})
|
7
10
|
raise ArgumentError, 'apis_configs must be an Hash' unless configs.is_a? Hash
|
11
|
+
|
8
12
|
@apis_configs = configs.deep_symbolize_keys
|
9
|
-
ApiRecipes._aprcps_define_global_apis
|
10
13
|
end
|
11
14
|
|
12
15
|
def apis_configs
|
@@ -16,6 +19,34 @@ module ApiRecipes
|
|
16
19
|
@apis_configs
|
17
20
|
end
|
18
21
|
|
22
|
+
def apis_files_paths=(paths = [])
|
23
|
+
raise ArgumentError, 'apis_files_paths must be an Array' unless paths.is_a? Array
|
24
|
+
|
25
|
+
@apis_files_paths = paths
|
26
|
+
@apis_files_paths.each do |file_path|
|
27
|
+
template = ERB.new File.read File.expand_path(file_path)
|
28
|
+
data = begin
|
29
|
+
YAML.load(template.result(binding), aliases: true)
|
30
|
+
rescue ArgumentError
|
31
|
+
YAML.load(template.result binding)
|
32
|
+
end.deep_symbolize_keys
|
33
|
+
# Merge file contents into apis_configs
|
34
|
+
data.each do |api, params|
|
35
|
+
if apis_configs[api]
|
36
|
+
logger.warn "File at #{file_path} overrides config for '#{api}' API"
|
37
|
+
end
|
38
|
+
apis_configs[api] = params
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def apis_files_paths
|
44
|
+
unless @apis_files_paths
|
45
|
+
@apis_files_paths = []
|
46
|
+
end
|
47
|
+
@apis_files_paths
|
48
|
+
end
|
49
|
+
|
19
50
|
def logger=(logger)
|
20
51
|
@logger = logger
|
21
52
|
end
|
@@ -31,6 +62,10 @@ module ApiRecipes
|
|
31
62
|
@logger
|
32
63
|
end
|
33
64
|
|
65
|
+
def setup
|
66
|
+
ApiRecipes._aprcps_define_global_apis
|
67
|
+
end
|
68
|
+
|
34
69
|
private
|
35
70
|
|
36
71
|
# @private
|
data/lib/api_recipes/endpoint.rb
CHANGED
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/utils.rb
CHANGED
@@ -77,6 +77,37 @@ class Hash
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
# Returns a new hash with +self+ and +other_hash+ merged recursively.
|
81
|
+
#
|
82
|
+
# h1 = { a: true, b: { c: [1, 2, 3] } }
|
83
|
+
# h2 = { a: false, b: { x: [3, 4, 5] } }
|
84
|
+
#
|
85
|
+
# h1.deep_merge(h2) # => { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
|
86
|
+
#
|
87
|
+
# Like with Hash#merge in the standard library, a block can be provided
|
88
|
+
# to merge values:
|
89
|
+
#
|
90
|
+
# h1 = { a: 100, b: 200, c: { c1: 100 } }
|
91
|
+
# h2 = { b: 250, c: { c1: 200 } }
|
92
|
+
# h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val }
|
93
|
+
# # => { a: 100, b: 450, c: { c1: 300 } }
|
94
|
+
def deep_merge(other_hash, &block)
|
95
|
+
dup.deep_merge!(other_hash, &block)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Same as +deep_merge+, but modifies +self+.
|
99
|
+
def deep_merge!(other_hash, &block)
|
100
|
+
merge!(other_hash) do |key, this_val, other_val|
|
101
|
+
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
|
102
|
+
this_val.deep_merge(other_val, &block)
|
103
|
+
elsif block_given?
|
104
|
+
block.call(key, this_val, other_val)
|
105
|
+
else
|
106
|
+
other_val
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
80
111
|
# Returns a new hash with all keys converted by the block operation.
|
81
112
|
# This includes the keys from the root hash and from all
|
82
113
|
# nested hashes and arrays.
|
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
|
@@ -117,6 +118,7 @@ module ApiRecipes
|
|
117
118
|
unless @storage
|
118
119
|
@storage = {}
|
119
120
|
end
|
121
|
+
|
120
122
|
@storage
|
121
123
|
end
|
122
124
|
|
@@ -131,11 +133,9 @@ module ApiRecipes
|
|
131
133
|
unless api_name.is_a?(String) || api_name.is_a?(Symbol)
|
132
134
|
raise ArgumentError, "no api_name provided. Given: #{api_name.inspect}"
|
133
135
|
end
|
134
|
-
|
135
|
-
ApiRecipes.configuration.apis_configs[api_name] = {}
|
136
|
-
end
|
136
|
+
global_api_configs = _aprcps_global_storage[api_name]&.configs || {}
|
137
137
|
if configs
|
138
|
-
|
138
|
+
global_api_configs.deep_merge(configs) do |_, old_val, new_val|
|
139
139
|
if new_val.nil?
|
140
140
|
old_val
|
141
141
|
else
|
@@ -143,7 +143,7 @@ module ApiRecipes
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
else
|
146
|
-
|
146
|
+
global_api_configs
|
147
147
|
end
|
148
148
|
end
|
149
149
|
end
|
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.0
|
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
|