togglr-sdk 1.0.4 → 1.0.5
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/README.md +0 -1
- data/lib/togglr/client.rb +11 -0
- data/lib/togglr/config.rb +6 -3
- data/lib/togglr/options.rb +23 -0
- data/lib/togglr/version.rb +1 -1
- data/lib/togglr-client/api/default_api.rb +79 -79
- data/lib/togglr-client/api_client.rb +77 -73
- data/lib/togglr-client/api_error.rb +1 -1
- data/lib/togglr-client/configuration.rb +1 -1
- data/lib/togglr-client/models/error.rb +1 -1
- data/lib/togglr-client/models/error_bad_request.rb +1 -1
- data/lib/togglr-client/models/error_error.rb +1 -1
- data/lib/togglr-client/models/error_internal_server_error.rb +1 -1
- data/lib/togglr-client/models/error_not_found.rb +1 -1
- data/lib/togglr-client/models/error_permission_denied.rb +1 -1
- data/lib/togglr-client/models/error_too_many_requests.rb +1 -1
- data/lib/togglr-client/models/error_unauthorized.rb +1 -1
- data/lib/togglr-client/models/evaluate_response.rb +1 -1
- data/lib/togglr-client/models/feature_error_report.rb +1 -1
- data/lib/togglr-client/models/feature_health.rb +1 -1
- data/lib/togglr-client/models/health_response.rb +1 -1
- data/lib/togglr-client/version.rb +1 -1
- data/spec/examples.txt +9 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff652d531c0ed02ec75cf399743544e157fdd142a9ce2000847b0d1ba4d855cc
|
4
|
+
data.tar.gz: f90b18e8a8be739e557e6d21b6d2dda227dadcd417828374ba33e26b1ea9f5c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d802ffa645e880e88d67c69c08346f9ce27a2547a0ed5ba8ec717ea9c29e58f034906ea5e29c73b41ba50e3fcc73d1e220f9525464dbb6b491b56412a1aa8397
|
7
|
+
data.tar.gz: f0b93fc6b700bc6b26a42b6295bb4daf8bf2138b08af990ea0ae4142d6cdcaf6b7b22ef384e9ac7642475fe9b39d43b20222cab489dd14f7c471c90e334425a1
|
data/README.md
CHANGED
@@ -93,7 +93,6 @@ client = Togglr::Client.new_with_defaults('api-key') do |config|
|
|
93
93
|
config.cache_enabled = true
|
94
94
|
config.cache_size = 1000
|
95
95
|
config.cache_ttl = 10
|
96
|
-
config.use_circuit_breaker = true
|
97
96
|
config.max_connections = 100
|
98
97
|
config.insecure = true # Skip SSL verification for self-signed certificates
|
99
98
|
end
|
data/lib/togglr/client.rb
CHANGED
@@ -15,6 +15,17 @@ module Togglr
|
|
15
15
|
api_config = TogglrClient::Configuration.new
|
16
16
|
api_config.api_key['Authorization'] = config.api_key
|
17
17
|
api_config.ssl_verify = !config.insecure
|
18
|
+
|
19
|
+
# Configure TLS certificates if provided
|
20
|
+
if config.client_cert && config.client_key
|
21
|
+
api_config.ssl_client_cert = config.client_cert
|
22
|
+
api_config.ssl_client_key = config.client_key
|
23
|
+
end
|
24
|
+
|
25
|
+
if config.ca_cert
|
26
|
+
api_config.ssl_ca_file = config.ca_cert
|
27
|
+
end
|
28
|
+
|
18
29
|
@api_client = TogglrClient::DefaultApi.new(TogglrClient::ApiClient.new(api_config))
|
19
30
|
end
|
20
31
|
|
data/lib/togglr/config.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
module Togglr
|
2
2
|
class Config
|
3
3
|
attr_accessor :base_url, :api_key, :timeout, :retries, :backoff,
|
4
|
-
:cache_enabled, :cache_size, :cache_ttl,
|
5
|
-
:logger, :metrics, :max_connections, :insecure
|
4
|
+
:cache_enabled, :cache_size, :cache_ttl,
|
5
|
+
:logger, :metrics, :max_connections, :insecure,
|
6
|
+
:client_cert, :client_key, :ca_cert
|
6
7
|
|
7
8
|
def initialize(api_key)
|
8
9
|
@base_url = 'http://localhost:8090'
|
@@ -13,11 +14,13 @@ module Togglr
|
|
13
14
|
@cache_enabled = false
|
14
15
|
@cache_size = 100
|
15
16
|
@cache_ttl = 5 # seconds
|
16
|
-
@use_circuit_breaker = false
|
17
17
|
@logger = NoOpLogger.new
|
18
18
|
@metrics = NoOpMetrics.new
|
19
19
|
@max_connections = 100
|
20
20
|
@insecure = false
|
21
|
+
@client_cert = nil
|
22
|
+
@client_key = nil
|
23
|
+
@ca_cert = nil
|
21
24
|
end
|
22
25
|
|
23
26
|
def self.default(api_key)
|
data/lib/togglr/options.rb
CHANGED
@@ -53,5 +53,28 @@ module Togglr
|
|
53
53
|
def self.with_max_connections(max_connections)
|
54
54
|
->(config) { config.max_connections = max_connections }
|
55
55
|
end
|
56
|
+
|
57
|
+
# Set client certificate for TLS authentication
|
58
|
+
def self.with_client_cert(cert_path)
|
59
|
+
->(config) { config.client_cert = cert_path }
|
60
|
+
end
|
61
|
+
|
62
|
+
# Set client private key for TLS authentication
|
63
|
+
def self.with_client_key(key_path)
|
64
|
+
->(config) { config.client_key = key_path }
|
65
|
+
end
|
66
|
+
|
67
|
+
# Set CA certificate for TLS verification
|
68
|
+
def self.with_ca_cert(ca_path)
|
69
|
+
->(config) { config.ca_cert = ca_path }
|
70
|
+
end
|
71
|
+
|
72
|
+
# Set both client certificate and key at once
|
73
|
+
def self.with_client_cert_and_key(cert_path, key_path)
|
74
|
+
lambda do |config|
|
75
|
+
config.client_cert = cert_path
|
76
|
+
config.client_key = key_path
|
77
|
+
end
|
78
|
+
end
|
56
79
|
end
|
57
80
|
end
|
data/lib/togglr/version.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
=begin
|
2
|
+
#SDK API
|
3
|
+
|
4
|
+
#No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.0.0
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
Generator version: 7.16.0
|
10
|
+
|
11
|
+
=end
|
10
12
|
|
11
13
|
require 'cgi'
|
12
14
|
|
@@ -17,9 +19,8 @@ module TogglrClient
|
|
17
19
|
def initialize(api_client = ApiClient.default)
|
18
20
|
@api_client = api_client
|
19
21
|
end
|
20
|
-
|
21
22
|
# Get health status of feature (including auto-disable state)
|
22
|
-
# @param feature_key [String]
|
23
|
+
# @param feature_key [String]
|
23
24
|
# @param [Hash] opts the optional parameters
|
24
25
|
# @return [FeatureHealth]
|
25
26
|
def get_feature_health(feature_key, opts = {})
|
@@ -28,19 +29,19 @@ module TogglrClient
|
|
28
29
|
end
|
29
30
|
|
30
31
|
# Get health status of feature (including auto-disable state)
|
31
|
-
# @param feature_key [String]
|
32
|
+
# @param feature_key [String]
|
32
33
|
# @param [Hash] opts the optional parameters
|
33
34
|
# @return [Array<(FeatureHealth, Integer, Hash)>] FeatureHealth data, response status code and response headers
|
34
35
|
def get_feature_health_with_http_info(feature_key, opts = {})
|
35
|
-
|
36
|
+
if @api_client.config.debugging
|
37
|
+
@api_client.config.logger.debug 'Calling API: DefaultApi.get_feature_health ...'
|
38
|
+
end
|
36
39
|
# verify the required parameter 'feature_key' is set
|
37
40
|
if @api_client.config.client_side_validation && feature_key.nil?
|
38
|
-
|
41
|
+
fail ArgumentError, "Missing the required parameter 'feature_key' when calling DefaultApi.get_feature_health"
|
39
42
|
end
|
40
|
-
|
41
43
|
# resource path
|
42
|
-
local_var_path = '/sdk/v1/features/{feature_key}/health'.sub('{' + 'feature_key' + '}',
|
43
|
-
CGI.escape(feature_key.to_s))
|
44
|
+
local_var_path = '/sdk/v1/features/{feature_key}/health'.sub('{' + 'feature_key' + '}', CGI.escape(feature_key.to_s))
|
44
45
|
|
45
46
|
# query parameters
|
46
47
|
query_params = opts[:query_params] || {}
|
@@ -63,25 +64,25 @@ module TogglrClient
|
|
63
64
|
auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']
|
64
65
|
|
65
66
|
new_options = opts.merge(
|
66
|
-
operation
|
67
|
-
header_params
|
68
|
-
query_params
|
69
|
-
form_params
|
70
|
-
body
|
71
|
-
auth_names
|
72
|
-
return_type
|
67
|
+
:operation => :"DefaultApi.get_feature_health",
|
68
|
+
:header_params => header_params,
|
69
|
+
:query_params => query_params,
|
70
|
+
:form_params => form_params,
|
71
|
+
:body => post_body,
|
72
|
+
:auth_names => auth_names,
|
73
|
+
:return_type => return_type
|
73
74
|
)
|
74
75
|
|
75
76
|
data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
|
76
77
|
if @api_client.config.debugging
|
77
78
|
@api_client.config.logger.debug "API called: DefaultApi#get_feature_health\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
78
79
|
end
|
79
|
-
|
80
|
+
return data, status_code, headers
|
80
81
|
end
|
81
82
|
|
82
83
|
# Report feature execution error (for auto-disable)
|
83
|
-
# @param feature_key [String]
|
84
|
-
# @param feature_error_report [FeatureErrorReport]
|
84
|
+
# @param feature_key [String]
|
85
|
+
# @param feature_error_report [FeatureErrorReport]
|
85
86
|
# @param [Hash] opts the optional parameters
|
86
87
|
# @return [nil]
|
87
88
|
def report_feature_error(feature_key, feature_error_report, opts = {})
|
@@ -90,26 +91,24 @@ module TogglrClient
|
|
90
91
|
end
|
91
92
|
|
92
93
|
# Report feature execution error (for auto-disable)
|
93
|
-
# @param feature_key [String]
|
94
|
-
# @param feature_error_report [FeatureErrorReport]
|
94
|
+
# @param feature_key [String]
|
95
|
+
# @param feature_error_report [FeatureErrorReport]
|
95
96
|
# @param [Hash] opts the optional parameters
|
96
97
|
# @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
|
97
98
|
def report_feature_error_with_http_info(feature_key, feature_error_report, opts = {})
|
98
|
-
|
99
|
+
if @api_client.config.debugging
|
100
|
+
@api_client.config.logger.debug 'Calling API: DefaultApi.report_feature_error ...'
|
101
|
+
end
|
99
102
|
# verify the required parameter 'feature_key' is set
|
100
103
|
if @api_client.config.client_side_validation && feature_key.nil?
|
101
|
-
|
104
|
+
fail ArgumentError, "Missing the required parameter 'feature_key' when calling DefaultApi.report_feature_error"
|
102
105
|
end
|
103
|
-
|
104
106
|
# verify the required parameter 'feature_error_report' is set
|
105
107
|
if @api_client.config.client_side_validation && feature_error_report.nil?
|
106
|
-
|
107
|
-
"Missing the required parameter 'feature_error_report' when calling DefaultApi.report_feature_error"
|
108
|
+
fail ArgumentError, "Missing the required parameter 'feature_error_report' when calling DefaultApi.report_feature_error"
|
108
109
|
end
|
109
|
-
|
110
110
|
# resource path
|
111
|
-
local_var_path = '/sdk/v1/features/{feature_key}/report-error'.sub('{' + 'feature_key' + '}',
|
112
|
-
CGI.escape(feature_key.to_s))
|
111
|
+
local_var_path = '/sdk/v1/features/{feature_key}/report-error'.sub('{' + 'feature_key' + '}', CGI.escape(feature_key.to_s))
|
113
112
|
|
114
113
|
# query parameters
|
115
114
|
query_params = opts[:query_params] || {}
|
@@ -120,7 +119,9 @@ module TogglrClient
|
|
120
119
|
header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
|
121
120
|
# HTTP header 'Content-Type'
|
122
121
|
content_type = @api_client.select_header_content_type(['application/json'])
|
123
|
-
|
122
|
+
if !content_type.nil?
|
123
|
+
header_params['Content-Type'] = content_type
|
124
|
+
end
|
124
125
|
|
125
126
|
# form parameters
|
126
127
|
form_params = opts[:form_params] || {}
|
@@ -135,38 +136,37 @@ module TogglrClient
|
|
135
136
|
auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']
|
136
137
|
|
137
138
|
new_options = opts.merge(
|
138
|
-
operation
|
139
|
-
header_params
|
140
|
-
query_params
|
141
|
-
form_params
|
142
|
-
body
|
143
|
-
auth_names
|
144
|
-
return_type
|
139
|
+
:operation => :"DefaultApi.report_feature_error",
|
140
|
+
:header_params => header_params,
|
141
|
+
:query_params => query_params,
|
142
|
+
:form_params => form_params,
|
143
|
+
:body => post_body,
|
144
|
+
:auth_names => auth_names,
|
145
|
+
:return_type => return_type
|
145
146
|
)
|
146
147
|
|
147
148
|
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
148
149
|
if @api_client.config.debugging
|
149
150
|
@api_client.config.logger.debug "API called: DefaultApi#report_feature_error\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
150
151
|
end
|
151
|
-
|
152
|
+
return data, status_code, headers
|
152
153
|
end
|
153
154
|
|
154
155
|
# Evaluate feature for given context
|
155
|
-
# Returns feature evaluation result for given project and context. The project is derived from the API key.
|
156
|
-
# @param feature_key [String]
|
157
|
-
# @param request_body [Hash<String, Object>]
|
156
|
+
# Returns feature evaluation result for given project and context. The project is derived from the API key.
|
157
|
+
# @param feature_key [String]
|
158
|
+
# @param request_body [Hash<String, Object>]
|
158
159
|
# @param [Hash] opts the optional parameters
|
159
160
|
# @return [EvaluateResponse]
|
160
161
|
def sdk_v1_features_feature_key_evaluate_post(feature_key, request_body, opts = {})
|
161
|
-
data, _status_code, _headers = sdk_v1_features_feature_key_evaluate_post_with_http_info(feature_key,
|
162
|
-
request_body, opts)
|
162
|
+
data, _status_code, _headers = sdk_v1_features_feature_key_evaluate_post_with_http_info(feature_key, request_body, opts)
|
163
163
|
data
|
164
164
|
end
|
165
165
|
|
166
166
|
# Evaluate feature for given context
|
167
|
-
# Returns feature evaluation result for given project and context. The project is derived from the API key.
|
168
|
-
# @param feature_key [String]
|
169
|
-
# @param request_body [Hash<String, Object>]
|
167
|
+
# Returns feature evaluation result for given project and context. The project is derived from the API key.
|
168
|
+
# @param feature_key [String]
|
169
|
+
# @param request_body [Hash<String, Object>]
|
170
170
|
# @param [Hash] opts the optional parameters
|
171
171
|
# @return [Array<(EvaluateResponse, Integer, Hash)>] EvaluateResponse data, response status code and response headers
|
172
172
|
def sdk_v1_features_feature_key_evaluate_post_with_http_info(feature_key, request_body, opts = {})
|
@@ -175,18 +175,14 @@ module TogglrClient
|
|
175
175
|
end
|
176
176
|
# verify the required parameter 'feature_key' is set
|
177
177
|
if @api_client.config.client_side_validation && feature_key.nil?
|
178
|
-
|
179
|
-
"Missing the required parameter 'feature_key' when calling DefaultApi.sdk_v1_features_feature_key_evaluate_post"
|
178
|
+
fail ArgumentError, "Missing the required parameter 'feature_key' when calling DefaultApi.sdk_v1_features_feature_key_evaluate_post"
|
180
179
|
end
|
181
180
|
# verify the required parameter 'request_body' is set
|
182
181
|
if @api_client.config.client_side_validation && request_body.nil?
|
183
|
-
|
184
|
-
"Missing the required parameter 'request_body' when calling DefaultApi.sdk_v1_features_feature_key_evaluate_post"
|
182
|
+
fail ArgumentError, "Missing the required parameter 'request_body' when calling DefaultApi.sdk_v1_features_feature_key_evaluate_post"
|
185
183
|
end
|
186
|
-
|
187
184
|
# resource path
|
188
|
-
local_var_path = '/sdk/v1/features/{feature_key}/evaluate'.sub('{' + 'feature_key' + '}',
|
189
|
-
CGI.escape(feature_key.to_s))
|
185
|
+
local_var_path = '/sdk/v1/features/{feature_key}/evaluate'.sub('{' + 'feature_key' + '}', CGI.escape(feature_key.to_s))
|
190
186
|
|
191
187
|
# query parameters
|
192
188
|
query_params = opts[:query_params] || {}
|
@@ -197,7 +193,9 @@ module TogglrClient
|
|
197
193
|
header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
|
198
194
|
# HTTP header 'Content-Type'
|
199
195
|
content_type = @api_client.select_header_content_type(['application/json'])
|
200
|
-
|
196
|
+
if !content_type.nil?
|
197
|
+
header_params['Content-Type'] = content_type
|
198
|
+
end
|
201
199
|
|
202
200
|
# form parameters
|
203
201
|
form_params = opts[:form_params] || {}
|
@@ -212,20 +210,20 @@ module TogglrClient
|
|
212
210
|
auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']
|
213
211
|
|
214
212
|
new_options = opts.merge(
|
215
|
-
operation
|
216
|
-
header_params
|
217
|
-
query_params
|
218
|
-
form_params
|
219
|
-
body
|
220
|
-
auth_names
|
221
|
-
return_type
|
213
|
+
:operation => :"DefaultApi.sdk_v1_features_feature_key_evaluate_post",
|
214
|
+
:header_params => header_params,
|
215
|
+
:query_params => query_params,
|
216
|
+
:form_params => form_params,
|
217
|
+
:body => post_body,
|
218
|
+
:auth_names => auth_names,
|
219
|
+
:return_type => return_type
|
222
220
|
)
|
223
221
|
|
224
222
|
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
225
223
|
if @api_client.config.debugging
|
226
224
|
@api_client.config.logger.debug "API called: DefaultApi#sdk_v1_features_feature_key_evaluate_post\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
227
225
|
end
|
228
|
-
|
226
|
+
return data, status_code, headers
|
229
227
|
end
|
230
228
|
|
231
229
|
# Health check for SDK server
|
@@ -240,7 +238,9 @@ module TogglrClient
|
|
240
238
|
# @param [Hash] opts the optional parameters
|
241
239
|
# @return [Array<(HealthResponse, Integer, Hash)>] HealthResponse data, response status code and response headers
|
242
240
|
def sdk_v1_health_get_with_http_info(opts = {})
|
243
|
-
|
241
|
+
if @api_client.config.debugging
|
242
|
+
@api_client.config.logger.debug 'Calling API: DefaultApi.sdk_v1_health_get ...'
|
243
|
+
end
|
244
244
|
# resource path
|
245
245
|
local_var_path = '/sdk/v1/health'
|
246
246
|
|
@@ -265,20 +265,20 @@ module TogglrClient
|
|
265
265
|
auth_names = opts[:debug_auth_names] || []
|
266
266
|
|
267
267
|
new_options = opts.merge(
|
268
|
-
operation
|
269
|
-
header_params
|
270
|
-
query_params
|
271
|
-
form_params
|
272
|
-
body
|
273
|
-
auth_names
|
274
|
-
return_type
|
268
|
+
:operation => :"DefaultApi.sdk_v1_health_get",
|
269
|
+
:header_params => header_params,
|
270
|
+
:query_params => query_params,
|
271
|
+
:form_params => form_params,
|
272
|
+
:body => post_body,
|
273
|
+
:auth_names => auth_names,
|
274
|
+
:return_type => return_type
|
275
275
|
)
|
276
276
|
|
277
277
|
data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
|
278
278
|
if @api_client.config.debugging
|
279
279
|
@api_client.config.logger.debug "API called: DefaultApi#sdk_v1_health_get\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
280
280
|
end
|
281
|
-
|
281
|
+
return data, status_code, headers
|
282
282
|
end
|
283
283
|
end
|
284
284
|
end
|
@@ -1,12 +1,14 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
=begin
|
2
|
+
#SDK API
|
3
|
+
|
4
|
+
#No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.0.0
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
Generator version: 7.16.0
|
10
|
+
|
11
|
+
=end
|
10
12
|
|
11
13
|
require 'date'
|
12
14
|
require 'json'
|
@@ -17,6 +19,7 @@ require 'faraday'
|
|
17
19
|
require 'faraday/multipart' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
|
18
20
|
require 'marcel'
|
19
21
|
|
22
|
+
|
20
23
|
module TogglrClient
|
21
24
|
class ApiClient
|
22
25
|
# The Configuration object holding settings to be used in the API client.
|
@@ -51,37 +54,39 @@ module TogglrClient
|
|
51
54
|
begin
|
52
55
|
response = connection(opts).public_send(http_method.to_sym.downcase) do |req|
|
53
56
|
request = build_request(http_method, path, req, opts)
|
54
|
-
stream = download_file(request) if
|
57
|
+
stream = download_file(request) if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
|
55
58
|
end
|
56
59
|
|
57
|
-
|
60
|
+
if config.debugging
|
61
|
+
config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
62
|
+
end
|
58
63
|
|
59
64
|
unless response.success?
|
60
65
|
if response.status == 0 && response.respond_to?(:return_message)
|
61
66
|
# Errors from libcurl will be made visible here
|
62
|
-
|
63
|
-
|
67
|
+
fail ApiError.new(code: 0,
|
68
|
+
message: response.return_message)
|
64
69
|
else
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
70
|
+
fail ApiError.new(code: response.status,
|
71
|
+
response_headers: response.headers,
|
72
|
+
response_body: response.body),
|
73
|
+
response.reason_phrase
|
69
74
|
end
|
70
75
|
end
|
71
76
|
rescue Faraday::TimeoutError
|
72
|
-
|
77
|
+
fail ApiError.new('Connection timed out')
|
73
78
|
rescue Faraday::ConnectionFailed
|
74
|
-
|
79
|
+
fail ApiError.new('Connection failed')
|
75
80
|
end
|
76
81
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
|
83
|
+
data = deserialize_file(response, stream)
|
84
|
+
elsif opts[:return_type]
|
85
|
+
data = deserialize(response, opts[:return_type])
|
86
|
+
else
|
87
|
+
data = nil
|
88
|
+
end
|
89
|
+
return data, response.status, response.headers
|
85
90
|
end
|
86
91
|
|
87
92
|
# Builds the HTTP request
|
@@ -103,9 +108,11 @@ module TogglrClient
|
|
103
108
|
|
104
109
|
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
105
110
|
|
106
|
-
if
|
111
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
107
112
|
req_body = build_request_body(header_params, form_params, opts[:body])
|
108
|
-
|
113
|
+
if config.debugging
|
114
|
+
config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
115
|
+
end
|
109
116
|
end
|
110
117
|
request.headers = header_params
|
111
118
|
request.body = req_body
|
@@ -132,15 +139,15 @@ module TogglrClient
|
|
132
139
|
elsif header_params['Content-Type'] == 'multipart/form-data'
|
133
140
|
data = {}
|
134
141
|
form_params.each do |key, value|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
142
|
+
case value
|
143
|
+
when ::File, ::Tempfile
|
144
|
+
data[key] = Faraday::FilePart.new(value.path, Marcel::MimeType.for(Pathname.new(value.path)))
|
145
|
+
when ::Array, nil
|
146
|
+
# let Faraday handle Array and nil parameters
|
147
|
+
data[key] = value
|
148
|
+
else
|
149
|
+
data[key] = value.to_s
|
150
|
+
end
|
144
151
|
end
|
145
152
|
elsif body
|
146
153
|
data = body.is_a?(String) ? body : body.to_json
|
@@ -154,7 +161,7 @@ module TogglrClient
|
|
154
161
|
stream = []
|
155
162
|
|
156
163
|
# handle streaming Responses
|
157
|
-
request.options.on_data =
|
164
|
+
request.options.on_data = Proc.new do |chunk, overall_received_bytes|
|
158
165
|
stream << chunk
|
159
166
|
end
|
160
167
|
|
@@ -181,16 +188,16 @@ module TogglrClient
|
|
181
188
|
else
|
182
189
|
prefix = 'download-'
|
183
190
|
end
|
184
|
-
prefix
|
191
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
185
192
|
|
186
193
|
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
187
194
|
tempfile.write(content)
|
188
195
|
tempfile.close
|
189
196
|
|
190
|
-
config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "
|
191
|
-
|
192
|
-
|
193
|
-
|
197
|
+
config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
198
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
199
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
200
|
+
"explicitly with `tempfile.delete`"
|
194
201
|
tempfile
|
195
202
|
end
|
196
203
|
|
@@ -230,12 +237,12 @@ module TogglrClient
|
|
230
237
|
end
|
231
238
|
|
232
239
|
def basic_auth(conn)
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
240
|
+
if config.username && config.password
|
241
|
+
if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
|
242
|
+
conn.request(:authorization, :basic, config.username, config.password)
|
243
|
+
else
|
244
|
+
conn.request(:basic_auth, config.username, config.password)
|
245
|
+
end
|
239
246
|
end
|
240
247
|
end
|
241
248
|
|
@@ -248,7 +255,7 @@ module TogglrClient
|
|
248
255
|
# @param [String] mime MIME
|
249
256
|
# @return [Boolean] True if the MIME is application/json
|
250
257
|
def json_mime?(mime)
|
251
|
-
(mime == '*/*') || !(mime =~
|
258
|
+
(mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
|
252
259
|
end
|
253
260
|
|
254
261
|
# Deserialize the response to the given return type.
|
@@ -265,14 +272,16 @@ module TogglrClient
|
|
265
272
|
# ensuring a default content type
|
266
273
|
content_type = response.headers['Content-Type'] || 'application/json'
|
267
274
|
|
268
|
-
|
275
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
269
276
|
|
270
277
|
begin
|
271
|
-
data = JSON.parse("[#{body}]", symbolize_names
|
278
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
272
279
|
rescue JSON::ParserError => e
|
273
|
-
|
274
|
-
|
275
|
-
|
280
|
+
if %w(String Date Time).include?(return_type)
|
281
|
+
data = body
|
282
|
+
else
|
283
|
+
raise e
|
284
|
+
end
|
276
285
|
end
|
277
286
|
|
278
287
|
convert_to_type data, return_type
|
@@ -284,7 +293,6 @@ module TogglrClient
|
|
284
293
|
# @return [Mixed] Data in a particular type
|
285
294
|
def convert_to_type(data, return_type)
|
286
295
|
return nil if data.nil?
|
287
|
-
|
288
296
|
case return_type
|
289
297
|
when 'String'
|
290
298
|
data.to_s
|
@@ -305,11 +313,11 @@ module TogglrClient
|
|
305
313
|
data
|
306
314
|
when /\AArray<(.+)>\z/
|
307
315
|
# e.g. Array<Pet>
|
308
|
-
sub_type =
|
316
|
+
sub_type = $1
|
309
317
|
data.map { |item| convert_to_type(item, sub_type) }
|
310
|
-
when /\AHash
|
318
|
+
when /\AHash\<String, (.+)\>\z/
|
311
319
|
# e.g. Hash<String, Integer>
|
312
|
-
sub_type =
|
320
|
+
sub_type = $1
|
313
321
|
{}.tap do |hash|
|
314
322
|
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
315
323
|
end
|
@@ -326,12 +334,12 @@ module TogglrClient
|
|
326
334
|
# @param [String] filename the filename to be sanitized
|
327
335
|
# @return [String] the sanitized filename
|
328
336
|
def sanitize_filename(filename)
|
329
|
-
filename.split(
|
337
|
+
filename.split(/[\/\\]/).last
|
330
338
|
end
|
331
339
|
|
332
340
|
def build_request_url(path, opts = {})
|
333
341
|
# Add leading and trailing slashes to path
|
334
|
-
path = "/#{path}".gsub(
|
342
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
335
343
|
@config.base_url(opts[:operation]) + path
|
336
344
|
end
|
337
345
|
|
@@ -344,11 +352,10 @@ module TogglrClient
|
|
344
352
|
Array(auth_names).each do |auth_name|
|
345
353
|
auth_setting = @config.auth_settings[auth_name]
|
346
354
|
next unless auth_setting
|
347
|
-
|
348
355
|
case auth_setting[:in]
|
349
356
|
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
350
357
|
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
351
|
-
else
|
358
|
+
else fail ArgumentError, 'Authentication token must be in `query` or `header`'
|
352
359
|
end
|
353
360
|
end
|
354
361
|
end
|
@@ -366,7 +373,6 @@ module TogglrClient
|
|
366
373
|
# @return [String] the Accept header (e.g. application/json)
|
367
374
|
def select_header_accept(accepts)
|
368
375
|
return nil if accepts.nil? || accepts.empty?
|
369
|
-
|
370
376
|
# use JSON when present, otherwise use all of the provided
|
371
377
|
json_accept = accepts.find { |s| json_mime?(s) }
|
372
378
|
json_accept || accepts.join(',')
|
@@ -378,7 +384,6 @@ module TogglrClient
|
|
378
384
|
def select_header_content_type(content_types)
|
379
385
|
# return nil by default
|
380
386
|
return if content_types.nil? || content_types.empty?
|
381
|
-
|
382
387
|
# use JSON when present, otherwise use the first one
|
383
388
|
json_content_type = content_types.find { |s| json_mime?(s) }
|
384
389
|
json_content_type || content_types.first
|
@@ -389,13 +394,12 @@ module TogglrClient
|
|
389
394
|
# @return [String] JSON string representation of the object
|
390
395
|
def object_to_http_body(model)
|
391
396
|
return model if model.nil? || model.is_a?(String)
|
392
|
-
|
393
397
|
local_body = nil
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
398
|
+
if model.is_a?(Array)
|
399
|
+
local_body = model.map { |m| object_to_hash(m) }
|
400
|
+
else
|
401
|
+
local_body = object_to_hash(model)
|
402
|
+
end
|
399
403
|
local_body.to_json
|
400
404
|
end
|
401
405
|
|
@@ -426,7 +430,7 @@ module TogglrClient
|
|
426
430
|
# return the array directly as typhoeus will handle it as expected
|
427
431
|
param
|
428
432
|
else
|
429
|
-
|
433
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
430
434
|
end
|
431
435
|
end
|
432
436
|
end
|
data/spec/examples.txt
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
example_id | status | run_time |
|
2
2
|
-------------------------- | ------ | --------------- |
|
3
|
-
./spec/togglr_spec.rb[1:1] | passed | 0.
|
4
|
-
./spec/togglr_spec.rb[2:1] | passed | 0.
|
5
|
-
./spec/togglr_spec.rb[2:2] | passed | 0.
|
6
|
-
./spec/togglr_spec.rb[2:3] | passed | 0.
|
7
|
-
./spec/togglr_spec.rb[3:1] | passed | 0.
|
8
|
-
./spec/togglr_spec.rb[3:2] | passed | 0.
|
9
|
-
./spec/togglr_spec.rb[4:1] | passed | 0.
|
10
|
-
./spec/togglr_spec.rb[4:2] | passed | 0.
|
11
|
-
./spec/togglr_spec.rb[4:3] | passed | 0.
|
3
|
+
./spec/togglr_spec.rb[1:1] | passed | 0.00005 seconds |
|
4
|
+
./spec/togglr_spec.rb[2:1] | passed | 0.00006 seconds |
|
5
|
+
./spec/togglr_spec.rb[2:2] | passed | 0.00009 seconds |
|
6
|
+
./spec/togglr_spec.rb[2:3] | passed | 0.00122 seconds |
|
7
|
+
./spec/togglr_spec.rb[3:1] | passed | 0.00005 seconds |
|
8
|
+
./spec/togglr_spec.rb[3:2] | passed | 0.00065 seconds |
|
9
|
+
./spec/togglr_spec.rb[4:1] | passed | 0.0001 seconds |
|
10
|
+
./spec/togglr_spec.rb[4:2] | passed | 0.15119 seconds |
|
11
|
+
./spec/togglr_spec.rb[4:3] | passed | 0.00082 seconds |
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: togglr-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-10-
|
11
|
+
date: 2025-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|