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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 542035bde9fcea69f8665c1fff0487e77d49c0961e5d51abf5c93f653217f997
4
- data.tar.gz: e0ee9e0f7f72759fab507139d0b94e6468aceb439ea1dd38e45a624dcdf4aa06
3
+ metadata.gz: e1bb46f30a582926c8f1944f977def1d77b7bb31fb5de9ea6e6bdb6f6ef56ef4
4
+ data.tar.gz: 85babd1c686f8ebebcd2204fb7e90ae74a4e14f46a5766a3506fabded0e1a055
5
5
  SHA512:
6
- metadata.gz: 8ac966a7faf9911269391ce637ecf880eaf28b348279ef1cb18a915be482c4ca338a7971e8603af1521f951cbadb72cf760b2d38c113f8d7f7c51eaa0fdd7bdd
7
- data.tar.gz: 1bf501fa269bc33ca8a60fb8d1599a14083ef55e271377814616c8d55377daab54f387a1588a48347b3950dacddb029db4c985f56e76262b79e28cb771b65083
6
+ metadata.gz: 6703102fa6b7613b4a0c969f4b2ae83130147371ec0632cca607a68307008ee44019b686e33dd8898bd7a9094c6db1f5975b08b2d41a997844499c1351d8d6bf
7
+ data.tar.gz: 291d3df7395d3a16702a82bce7856b14207c685413a4432e410769fb246d0671960fa6fe76a9036cbc391fd0edb915e8d17442976099cd6f88302a7f2ffe9807
data/lib/togglr/cache.rb CHANGED
@@ -42,4 +42,3 @@ module Togglr
42
42
  end
43
43
  end
44
44
  end
45
-
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
- begin
99
- @api_client.health_check
100
- rescue TogglrClient::ApiError => e
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
- begin
138
- # Create evaluate request using generated client
139
- evaluate_request = TogglrClient::EvaluateRequest.new(context.to_h)
140
- response = @api_client.evaluate_feature(feature_key, evaluate_request)
141
-
142
- [response.value, response.enabled, true, nil]
143
- rescue TogglrClient::ApiError => e
144
- case e.code
145
- when 404
146
- ['', false, false, nil] # Feature not found, not an error
147
- when 401
148
- [nil, nil, nil, UnauthorizedError.new('Authentication required')]
149
- when 400
150
- [nil, nil, nil, BadRequestError.new('Bad request')]
151
- when 500
152
- [nil, nil, nil, InternalServerError.new('Internal server error')]
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
- begin
201
- error_report = TogglrClient::FeatureErrorReport.new(
202
- error_type: error_type,
203
- error_message: error_message,
204
- context: context
205
- )
206
-
207
- @api_client.report_feature_error(feature_key, error_report)
208
- # Success - error queued for processing
209
- nil
210
- rescue TogglrClient::ApiError => e
211
- case e.code
212
- when 401
213
- UnauthorizedError.new('Authentication required')
214
- when 400
215
- BadRequestError.new('Bad request')
216
- when 404
217
- FeatureNotFoundError.new("Feature #{feature_key} not found")
218
- when 500
219
- InternalServerError.new('Internal server error')
220
- else
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
- begin
234
- api_health = @api_client.get_feature_health(feature_key)
235
- health = convert_feature_health(api_health)
236
- [health, nil] # health, error
237
- rescue TogglrClient::ApiError => e
238
- case e.code
239
- when 401
240
- [nil, UnauthorizedError.new('Authentication required')]
241
- when 400
242
- [nil, BadRequestError.new('Bad request')]
243
- when 404
244
- [nil, FeatureNotFoundError.new("Feature #{feature_key} not found")]
245
- when 500
246
- [nil, InternalServerError.new('Internal server error')]
247
- else
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 = {})
@@ -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
- ->(config) do
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
- ->(config) do
35
+ lambda do |config|
36
36
  config.cache_enabled = true
37
37
  config.cache_size = size
38
38
  config.cache_ttl = ttl
@@ -1,3 +1,3 @@
1
1
  module Togglr
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.0.2'.freeze
3
3
  end
@@ -1,14 +1,12 @@
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.15.0
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
- fail ArgumentError, "Missing the required parameter 'feature_key' when calling DefaultApi.get_feature_health"
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' + '}', CGI.escape(feature_key.to_s))
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
- :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
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
- return data, status_code, headers
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
- fail ArgumentError, "Missing the required parameter 'feature_key' when calling DefaultApi.report_feature_error"
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
- fail ArgumentError, "Missing the required parameter 'feature_error_report' when calling DefaultApi.report_feature_error"
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' + '}', CGI.escape(feature_key.to_s))
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
- if !content_type.nil?
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
- :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
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
- return data, status_code, headers
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, request_body, opts)
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
- fail ArgumentError, "Missing the required parameter 'feature_key' when calling DefaultApi.sdk_v1_features_feature_key_evaluate_post"
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
- fail ArgumentError, "Missing the required parameter 'request_body' when calling DefaultApi.sdk_v1_features_feature_key_evaluate_post"
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' + '}', CGI.escape(feature_key.to_s))
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
- if !content_type.nil?
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
- :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
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
- return data, status_code, headers
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
- :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
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
- return data, status_code, headers
281
+ [data, status_code, headers]
282
282
  end
283
283
  end
284
284
  end
@@ -1,14 +1,12 @@
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.15.0
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 opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
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
- fail ApiError.new(code: 0,
68
- message: response.return_message)
62
+ raise ApiError.new(code: 0,
63
+ message: response.return_message)
69
64
  else
70
- fail ApiError.new(code: response.status,
71
- response_headers: response.headers,
72
- response_body: response.body),
73
- response.reason_phrase
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
- fail ApiError.new('Connection timed out')
72
+ raise ApiError.new('Connection timed out')
78
73
  rescue Faraday::ConnectionFailed
79
- fail ApiError.new('Connection failed')
74
+ raise ApiError.new('Connection failed')
80
75
  end
81
76
 
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
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 [:post, :patch, :put, :delete].include?(http_method)
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
- 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
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 = Proc.new do |chunk, overall_received_bytes|
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 = prefix + '-' unless prefix.end_with?('-')
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
- "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`"
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
- 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
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 =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
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
- fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
268
+ raise "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
276
269
 
277
270
  begin
278
- data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
271
+ data = JSON.parse("[#{body}]", symbolize_names: true)[0]
279
272
  rescue JSON::ParserError => e
280
- if %w(String Date Time).include?(return_type)
281
- data = body
282
- else
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 = $1
308
+ sub_type = ::Regexp.last_match(1)
317
309
  data.map { |item| convert_to_type(item, sub_type) }
318
- when /\AHash\<String, (.+)\>\z/
310
+ when /\AHash<String, (.+)>\z/
319
311
  # e.g. Hash<String, Integer>
320
- sub_type = $1
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(/[\/\\]/).last
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 fail ArgumentError, 'Authentication token must be in `query` or `header`'
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
- local_body = model.map { |m| object_to_hash(m) }
400
- else
401
- local_body = object_to_hash(model)
402
- end
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
- fail "unknown collection format: #{collection_format.inspect}"
429
+ raise "unknown collection format: #{collection_format.inspect}"
434
430
  end
435
431
  end
436
432
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: togglr-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman