togglr-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +15 -0
  3. data/LICENSE +21 -0
  4. data/README.md +297 -0
  5. data/generated/Gemfile +9 -0
  6. data/generated/README.md +121 -0
  7. data/generated/Rakefile +10 -0
  8. data/generated/docs/DefaultApi.md +282 -0
  9. data/generated/docs/Error.md +18 -0
  10. data/generated/docs/ErrorBadRequest.md +18 -0
  11. data/generated/docs/ErrorError.md +18 -0
  12. data/generated/docs/ErrorInternalServerError.md +18 -0
  13. data/generated/docs/ErrorNotFound.md +18 -0
  14. data/generated/docs/ErrorPermissionDenied.md +18 -0
  15. data/generated/docs/ErrorTooManyRequests.md +18 -0
  16. data/generated/docs/ErrorUnauthorized.md +18 -0
  17. data/generated/docs/EvaluateResponse.md +22 -0
  18. data/generated/docs/FeatureErrorReport.md +22 -0
  19. data/generated/docs/FeatureHealth.md +30 -0
  20. data/generated/docs/HealthResponse.md +20 -0
  21. data/generated/git_push.sh +57 -0
  22. data/generated/lib/togglr-client/api/default_api.rb +284 -0
  23. data/generated/lib/togglr-client/api_client.rb +437 -0
  24. data/generated/lib/togglr-client/api_error.rb +58 -0
  25. data/generated/lib/togglr-client/configuration.rb +392 -0
  26. data/generated/lib/togglr-client/models/error.rb +237 -0
  27. data/generated/lib/togglr-client/models/error_bad_request.rb +244 -0
  28. data/generated/lib/togglr-client/models/error_error.rb +220 -0
  29. data/generated/lib/togglr-client/models/error_internal_server_error.rb +244 -0
  30. data/generated/lib/togglr-client/models/error_not_found.rb +244 -0
  31. data/generated/lib/togglr-client/models/error_permission_denied.rb +244 -0
  32. data/generated/lib/togglr-client/models/error_too_many_requests.rb +244 -0
  33. data/generated/lib/togglr-client/models/error_unauthorized.rb +244 -0
  34. data/generated/lib/togglr-client/models/evaluate_response.rb +289 -0
  35. data/generated/lib/togglr-client/models/feature_error_report.rb +274 -0
  36. data/generated/lib/togglr-client/models/feature_health.rb +342 -0
  37. data/generated/lib/togglr-client/models/health_response.rb +287 -0
  38. data/generated/lib/togglr-client/version.rb +15 -0
  39. data/generated/lib/togglr-client.rb +52 -0
  40. data/generated/spec/api/default_api_spec.rb +81 -0
  41. data/generated/spec/models/error_bad_request_spec.rb +36 -0
  42. data/generated/spec/models/error_error_spec.rb +36 -0
  43. data/generated/spec/models/error_internal_server_error_spec.rb +36 -0
  44. data/generated/spec/models/error_not_found_spec.rb +36 -0
  45. data/generated/spec/models/error_permission_denied_spec.rb +36 -0
  46. data/generated/spec/models/error_spec.rb +36 -0
  47. data/generated/spec/models/error_too_many_requests_spec.rb +36 -0
  48. data/generated/spec/models/error_unauthorized_spec.rb +36 -0
  49. data/generated/spec/models/evaluate_response_spec.rb +48 -0
  50. data/generated/spec/models/feature_error_report_spec.rb +48 -0
  51. data/generated/spec/models/feature_health_spec.rb +72 -0
  52. data/generated/spec/models/health_response_spec.rb +46 -0
  53. data/generated/spec/spec_helper.rb +111 -0
  54. data/generated/togglr-client.gemspec +41 -0
  55. data/lib/togglr/cache.rb +45 -0
  56. data/lib/togglr/client.rb +267 -0
  57. data/lib/togglr/config.rb +37 -0
  58. data/lib/togglr/errors.rb +25 -0
  59. data/lib/togglr/logger.rb +38 -0
  60. data/lib/togglr/metrics.rb +44 -0
  61. data/lib/togglr/models.rb +56 -0
  62. data/lib/togglr/options.rb +57 -0
  63. data/lib/togglr/request_context.rb +147 -0
  64. data/lib/togglr/version.rb +3 -0
  65. data/lib/togglr-client/api/default_api.rb +284 -0
  66. data/lib/togglr-client/api_client.rb +437 -0
  67. data/lib/togglr-client/api_error.rb +58 -0
  68. data/lib/togglr-client/configuration.rb +392 -0
  69. data/lib/togglr-client/models/error.rb +237 -0
  70. data/lib/togglr-client/models/error_bad_request.rb +244 -0
  71. data/lib/togglr-client/models/error_error.rb +220 -0
  72. data/lib/togglr-client/models/error_internal_server_error.rb +244 -0
  73. data/lib/togglr-client/models/error_not_found.rb +244 -0
  74. data/lib/togglr-client/models/error_permission_denied.rb +244 -0
  75. data/lib/togglr-client/models/error_too_many_requests.rb +244 -0
  76. data/lib/togglr-client/models/error_unauthorized.rb +244 -0
  77. data/lib/togglr-client/models/evaluate_response.rb +289 -0
  78. data/lib/togglr-client/models/feature_error_report.rb +274 -0
  79. data/lib/togglr-client/models/feature_health.rb +342 -0
  80. data/lib/togglr-client/models/health_response.rb +287 -0
  81. data/lib/togglr-client/version.rb +15 -0
  82. data/lib/togglr-client.rb +52 -0
  83. data/lib/togglr.rb +14 -0
  84. data/spec/examples.txt +11 -0
  85. data/spec/spec_helper.rb +29 -0
  86. data/spec/togglr_spec.rb +98 -0
  87. metadata +199 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 542035bde9fcea69f8665c1fff0487e77d49c0961e5d51abf5c93f653217f997
4
+ data.tar.gz: e0ee9e0f7f72759fab507139d0b94e6468aceb439ea1dd38e45a624dcdf4aa06
5
+ SHA512:
6
+ metadata.gz: 8ac966a7faf9911269391ce637ecf880eaf28b348279ef1cb18a915be482c4ca338a7971e8603af1521f951cbadb72cf760b2d38c113f8d7f7c51eaa0fdd7bdd
7
+ data.tar.gz: 1bf501fa269bc33ca8a60fb8d1599a14083ef55e271377814616c8d55377daab54f387a1588a48347b3950dacddb029db4c985f56e76262b79e28cb771b65083
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem 'rspec', '~> 3.12'
7
+ gem 'rubocop', '~> 1.57'
8
+ gem 'rubocop-rspec', '~> 2.25'
9
+ gem 'simplecov', '~> 0.22'
10
+ end
11
+
12
+ group :development do
13
+ gem 'rake', '~> 13.0'
14
+ gem 'yard', '~> 0.9'
15
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Togglr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,297 @@
1
+ # Togglr Ruby SDK
2
+
3
+ Ruby SDK for working with Togglr - feature flag management system.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'togglr-sdk'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ gem install togglr-sdk
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ```ruby
28
+ require 'togglr'
29
+
30
+ # Create client with default configuration
31
+ client = Togglr::Client.new_with_defaults('your-api-key-here') do |config|
32
+ config.base_url = 'http://localhost:8090'
33
+ config.timeout = 1.0
34
+ config.cache_enabled = true
35
+ config.cache_size = 1000
36
+ config.cache_ttl = 10
37
+ end
38
+
39
+ # Create request context
40
+ context = Togglr::RequestContext.new
41
+ .with_user_id('user123')
42
+ .with_country('US')
43
+ .with_device_type('mobile')
44
+
45
+ # Evaluate feature flag
46
+ value, enabled, found = client.evaluate('new_ui', context)
47
+
48
+ if found
49
+ puts "Feature enabled: #{enabled}, value: #{value}"
50
+ end
51
+
52
+ client.close
53
+ ```
54
+
55
+ ## Configuration
56
+
57
+ ### Creating a client
58
+
59
+ ```ruby
60
+ # With default settings
61
+ client = Togglr::Client.new_with_defaults('api-key')
62
+
63
+ # With custom configuration
64
+ config = Togglr::Config.default('api-key')
65
+ config.base_url = 'https://api.togglr.com'
66
+ config.timeout = 2.0
67
+ config.retries = 3
68
+
69
+ client = Togglr::Client.new(config)
70
+ ```
71
+
72
+ ### Configuration options
73
+
74
+ #### Using functional options (recommended)
75
+
76
+ ```ruby
77
+ client = Togglr::Client.new_with_defaults('api-key',
78
+ Togglr::Options.with_base_url('https://api.togglr.com'),
79
+ Togglr::Options.with_timeout(2.0),
80
+ Togglr::Options.with_retries(3),
81
+ Togglr::Options.with_cache(1000, 10),
82
+ Togglr::Options.with_insecure # Skip SSL verification for self-signed certificates
83
+ )
84
+ ```
85
+
86
+ #### Using configuration block
87
+
88
+ ```ruby
89
+ client = Togglr::Client.new_with_defaults('api-key') do |config|
90
+ config.base_url = 'https://api.togglr.com'
91
+ config.timeout = 2.0
92
+ config.retries = 3
93
+ config.cache_enabled = true
94
+ config.cache_size = 1000
95
+ config.cache_ttl = 10
96
+ config.use_circuit_breaker = true
97
+ config.max_connections = 100
98
+ config.insecure = true # Skip SSL verification for self-signed certificates
99
+ end
100
+ ```
101
+
102
+ ## Usage
103
+
104
+ ### Creating request context
105
+
106
+ ```ruby
107
+ context = Togglr::RequestContext.new
108
+ .with_user_id('user123')
109
+ .with_user_email('user@example.com')
110
+ .with_country('US')
111
+ .with_device_type('mobile')
112
+ .with_os('iOS')
113
+ .with_os_version('15.0')
114
+ .with_browser('Safari')
115
+ .with_language('en-US')
116
+ ```
117
+
118
+ ### Evaluating feature flags
119
+
120
+ ```ruby
121
+ # Full evaluation
122
+ value, enabled, found = client.evaluate('feature_key', context)
123
+
124
+ # Simple enabled check
125
+ is_enabled = client.is_enabled('feature_key', context)
126
+
127
+ # With default value
128
+ default_value = client.is_enabled_or_default('feature_key', context, false)
129
+ ```
130
+
131
+ ### Working with context
132
+
133
+ ```ruby
134
+ # Custom attributes
135
+ context.set('custom_key', 'custom_value')
136
+
137
+ # Convert to hash
138
+ hash = context.to_h
139
+ ```
140
+
141
+ ## Error Reporting and Auto-Disable
142
+
143
+ The SDK supports reporting errors for features, which can trigger automatic disabling based on error rates:
144
+
145
+ ```ruby
146
+ # Report an error for a feature
147
+ client.report_error(
148
+ 'feature_key',
149
+ 'timeout',
150
+ 'Service did not respond in 5s',
151
+ { service: 'payment-gateway', timeout_ms: 5000 }
152
+ )
153
+
154
+ puts "Error reported successfully - queued for processing"
155
+ ```
156
+
157
+ ### Error Types
158
+
159
+ Supported error types:
160
+ - `timeout` - Service timeout
161
+ - `validation` - Data validation error
162
+ - `service_unavailable` - External service unavailable
163
+ - `rate_limit` - Rate limit exceeded
164
+ - `network` - Network connectivity issue
165
+ - `internal` - Internal application error
166
+
167
+ ### Context Data
168
+
169
+ You can provide additional context with error reports:
170
+
171
+ ```ruby
172
+ context = {
173
+ service: 'payment-gateway',
174
+ timeout_ms: 5000,
175
+ user_id: 'user123',
176
+ region: 'us-east-1'
177
+ }
178
+
179
+ client.report_error('feature_key', 'timeout', 'Service timeout', context)
180
+ ```
181
+
182
+ ## Feature Health Monitoring
183
+
184
+ Monitor the health status of features:
185
+
186
+ ```ruby
187
+ # Get detailed health information
188
+ health = client.get_feature_health('feature_key')
189
+
190
+ puts "Feature: #{health.feature_key}"
191
+ puts "Enabled: #{health.enabled}"
192
+ puts "Auto Disabled: #{health.auto_disabled}"
193
+ puts "Error Rate: #{health.error_rate}"
194
+ puts "Threshold: #{health.threshold}"
195
+ puts "Last Error At: #{health.last_error_at}"
196
+
197
+ # Simple health check
198
+ is_healthy = client.is_feature_healthy('feature_key')
199
+ puts "Feature is healthy: #{is_healthy}"
200
+ ```
201
+
202
+ ### FeatureHealth Model
203
+
204
+ The `FeatureHealth` model provides:
205
+
206
+ - `feature_key` - The feature identifier
207
+ - `environment_key` - The environment identifier
208
+ - `enabled` - Whether the feature is enabled
209
+ - `auto_disabled` - Whether the feature was auto-disabled due to errors
210
+ - `error_rate` - Current error rate (0.0 to 1.0)
211
+ - `threshold` - Error rate threshold for auto-disable
212
+ - `last_error_at` - Timestamp of the last error
213
+ - `healthy?` - Boolean method to check if feature is healthy
214
+
215
+ ## Caching
216
+
217
+ The SDK supports optional caching of evaluation results using LRU cache:
218
+
219
+ ```ruby
220
+ client = Togglr::Client.new_with_defaults('api-key') do |config|
221
+ config.cache_enabled = true
222
+ config.cache_size = 1000 # number of items
223
+ config.cache_ttl = 10 # TTL in seconds
224
+ end
225
+ ```
226
+
227
+ ## Retries
228
+
229
+ The SDK automatically retries requests on temporary errors:
230
+
231
+ ```ruby
232
+ client = Togglr::Client.new_with_defaults('api-key') do |config|
233
+ config.retries = 3
234
+ config.backoff.base_delay = 0.1
235
+ config.backoff.max_delay = 2.0
236
+ config.backoff.factor = 2.0
237
+ end
238
+ ```
239
+
240
+ ## Logging and Metrics
241
+
242
+ ```ruby
243
+ # Custom logger
244
+ logger = Togglr::StdoutLogger.new
245
+ client = Togglr::Client.new_with_defaults('api-key') do |config|
246
+ config.logger = logger
247
+ end
248
+
249
+ # Custom metrics
250
+ metrics = Togglr::StdoutMetrics.new
251
+ client = Togglr::Client.new_with_defaults('api-key') do |config|
252
+ config.metrics = metrics
253
+ end
254
+ ```
255
+
256
+ ## Error Handling
257
+
258
+ ```ruby
259
+ begin
260
+ value, enabled, found = client.evaluate('feature_key', context)
261
+ rescue Togglr::UnauthorizedError
262
+ # Handle authorization error
263
+ rescue Togglr::BadRequestError
264
+ # Handle bad request
265
+ rescue Togglr::NetworkError
266
+ # Handle network error
267
+ rescue => e
268
+ # Handle other errors
269
+ puts "Error: #{e.message}"
270
+ end
271
+ ```
272
+
273
+ ## Development
274
+
275
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bundle exec console` for an interactive prompt that will allow you to experiment.
276
+
277
+ To install this gem onto your local machine, run `bundle exec rake install`.
278
+
279
+ ## Testing
280
+
281
+ ```bash
282
+ # Run tests
283
+ bundle exec rspec
284
+
285
+ # Run with coverage
286
+ bundle exec rspec
287
+
288
+ # Run RuboCop
289
+ bundle exec rubocop
290
+
291
+ # Run all checks
292
+ bundle exec rake check
293
+ ```
294
+
295
+ ## Contributing
296
+
297
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rom8726/togglr-sdk-ruby.
data/generated/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem 'rake', '~> 13.0.1'
7
+ gem 'pry-byebug'
8
+ gem 'rubocop', '~> 0.66.0'
9
+ end
@@ -0,0 +1,121 @@
1
+ # togglr-client
2
+
3
+ TogglrClient - the Ruby gem for the SDK API
4
+
5
+ No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6
+
7
+ This SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
8
+
9
+ - API version: 1.0.0
10
+ - Package version: 1.0.0
11
+ - Generator version: 7.15.0
12
+ - Build package: org.openapitools.codegen.languages.RubyClientCodegen
13
+
14
+ ## Installation
15
+
16
+ ### Build a gem
17
+
18
+ To build the Ruby code into a gem:
19
+
20
+ ```shell
21
+ gem build togglr-client.gemspec
22
+ ```
23
+
24
+ Then either install the gem locally:
25
+
26
+ ```shell
27
+ gem install ./togglr-client-1.0.0.gem
28
+ ```
29
+
30
+ (for development, run `gem install --dev ./togglr-client-1.0.0.gem` to install the development dependencies)
31
+
32
+ or publish the gem to a gem hosting service, e.g. [RubyGems](https://rubygems.org/).
33
+
34
+ Finally add this to the Gemfile:
35
+
36
+ gem 'togglr-client', '~> 1.0.0'
37
+
38
+ ### Install from Git
39
+
40
+ If the Ruby gem is hosted at a git repository: https://github.com/GIT_USER_ID/GIT_REPO_ID, then add the following in the Gemfile:
41
+
42
+ gem 'togglr-client', :git => 'https://github.com/GIT_USER_ID/GIT_REPO_ID.git'
43
+
44
+ ### Include the Ruby code directly
45
+
46
+ Include the Ruby code directly using `-I` as follows:
47
+
48
+ ```shell
49
+ ruby -Ilib script.rb
50
+ ```
51
+
52
+ ## Getting Started
53
+
54
+ Please follow the [installation](#installation) procedure and then run the following code:
55
+
56
+ ```ruby
57
+ # Load the gem
58
+ require 'togglr-client'
59
+
60
+ # Setup authorization
61
+ TogglrClient.configure do |config|
62
+ # Configure API key authorization: ApiKeyAuth
63
+ config.api_key['Authorization'] = 'YOUR API KEY'
64
+ # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
65
+ # config.api_key_prefix['Authorization'] = 'Bearer'
66
+ # Configure faraday connection
67
+ config.configure_faraday_connection { |connection| 'YOUR CONNECTION CONFIG PROC' }
68
+ end
69
+
70
+ api_instance = TogglrClient::DefaultApi.new
71
+ feature_key = 'feature_key_example' # String |
72
+
73
+ begin
74
+ #Get health status of feature (including auto-disable state)
75
+ result = api_instance.get_feature_health(feature_key)
76
+ p result
77
+ rescue TogglrClient::ApiError => e
78
+ puts "Exception when calling DefaultApi->get_feature_health: #{e}"
79
+ end
80
+
81
+ ```
82
+
83
+ ## Documentation for API Endpoints
84
+
85
+ All URIs are relative to *http://localhost:8090*
86
+
87
+ Class | Method | HTTP request | Description
88
+ ------------ | ------------- | ------------- | -------------
89
+ *TogglrClient::DefaultApi* | [**get_feature_health**](docs/DefaultApi.md#get_feature_health) | **GET** /sdk/v1/features/{feature_key}/health | Get health status of feature (including auto-disable state)
90
+ *TogglrClient::DefaultApi* | [**report_feature_error**](docs/DefaultApi.md#report_feature_error) | **POST** /sdk/v1/features/{feature_key}/report-error | Report feature execution error (for auto-disable)
91
+ *TogglrClient::DefaultApi* | [**sdk_v1_features_feature_key_evaluate_post**](docs/DefaultApi.md#sdk_v1_features_feature_key_evaluate_post) | **POST** /sdk/v1/features/{feature_key}/evaluate | Evaluate feature for given context
92
+ *TogglrClient::DefaultApi* | [**sdk_v1_health_get**](docs/DefaultApi.md#sdk_v1_health_get) | **GET** /sdk/v1/health | Health check for SDK server
93
+
94
+
95
+ ## Documentation for Models
96
+
97
+ - [TogglrClient::Error](docs/Error.md)
98
+ - [TogglrClient::ErrorBadRequest](docs/ErrorBadRequest.md)
99
+ - [TogglrClient::ErrorError](docs/ErrorError.md)
100
+ - [TogglrClient::ErrorInternalServerError](docs/ErrorInternalServerError.md)
101
+ - [TogglrClient::ErrorNotFound](docs/ErrorNotFound.md)
102
+ - [TogglrClient::ErrorPermissionDenied](docs/ErrorPermissionDenied.md)
103
+ - [TogglrClient::ErrorTooManyRequests](docs/ErrorTooManyRequests.md)
104
+ - [TogglrClient::ErrorUnauthorized](docs/ErrorUnauthorized.md)
105
+ - [TogglrClient::EvaluateResponse](docs/EvaluateResponse.md)
106
+ - [TogglrClient::FeatureErrorReport](docs/FeatureErrorReport.md)
107
+ - [TogglrClient::FeatureHealth](docs/FeatureHealth.md)
108
+ - [TogglrClient::HealthResponse](docs/HealthResponse.md)
109
+
110
+
111
+ ## Documentation for Authorization
112
+
113
+
114
+ Authentication schemes defined for the API:
115
+ ### ApiKeyAuth
116
+
117
+
118
+ - **Type**: API key
119
+ - **API key parameter name**: Authorization
120
+ - **Location**: HTTP header
121
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task default: :spec
8
+ rescue LoadError
9
+ # no rspec available
10
+ end