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