ibm_appconfiguration_ruby_sdk 0.1.0.pre.rc.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 (37) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/CODE_OF_CONDUCT.md +76 -0
  4. data/CONTRIBUTING.md +9 -0
  5. data/LICENSE +201 -0
  6. data/README.md +474 -0
  7. data/Rakefile +8 -0
  8. data/examples/README.md +60 -0
  9. data/examples/app.rb +104 -0
  10. data/lib/ibm_appconfiguration_ruby_sdk/app_configuration.rb +291 -0
  11. data/lib/ibm_appconfiguration_ruby_sdk/configurations/configuration_handler.rb +828 -0
  12. data/lib/ibm_appconfiguration_ruby_sdk/configurations/internal/constants.rb +89 -0
  13. data/lib/ibm_appconfiguration_ruby_sdk/configurations/internal/file_manager.rb +72 -0
  14. data/lib/ibm_appconfiguration_ruby_sdk/configurations/internal/logger.rb +98 -0
  15. data/lib/ibm_appconfiguration_ruby_sdk/configurations/internal/retry_manager/background_retry_manager.rb +284 -0
  16. data/lib/ibm_appconfiguration_ruby_sdk/configurations/internal/retry_manager/config_fetcher.rb +254 -0
  17. data/lib/ibm_appconfiguration_ruby_sdk/configurations/internal/utils.rb +240 -0
  18. data/lib/ibm_appconfiguration_ruby_sdk/configurations/internal/websocket_client/connection_manager.rb +501 -0
  19. data/lib/ibm_appconfiguration_ruby_sdk/configurations/internal/websocket_client/connectivity.rb +30 -0
  20. data/lib/ibm_appconfiguration_ruby_sdk/configurations/internal/websocket_client/driver_socket.rb +28 -0
  21. data/lib/ibm_appconfiguration_ruby_sdk/configurations/internal/websocket_client/retry_policy.rb +42 -0
  22. data/lib/ibm_appconfiguration_ruby_sdk/configurations/internal/websocket_client/state.rb +24 -0
  23. data/lib/ibm_appconfiguration_ruby_sdk/configurations/internal/websocket_client/watchdog.rb +50 -0
  24. data/lib/ibm_appconfiguration_ruby_sdk/configurations/internal/websocket_client/websocket_client.rb +43 -0
  25. data/lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb +121 -0
  26. data/lib/ibm_appconfiguration_ruby_sdk/configurations/models/property.rb +107 -0
  27. data/lib/ibm_appconfiguration_ruby_sdk/configurations/models/rule.rb +87 -0
  28. data/lib/ibm_appconfiguration_ruby_sdk/configurations/models/secret_property.rb +81 -0
  29. data/lib/ibm_appconfiguration_ruby_sdk/configurations/models/segment.rb +39 -0
  30. data/lib/ibm_appconfiguration_ruby_sdk/configurations/models/segment_rules.rb +57 -0
  31. data/lib/ibm_appconfiguration_ruby_sdk/core/api_manager.rb +269 -0
  32. data/lib/ibm_appconfiguration_ruby_sdk/core/metering.rb +400 -0
  33. data/lib/ibm_appconfiguration_ruby_sdk/core/url_builder.rb +252 -0
  34. data/lib/ibm_appconfiguration_ruby_sdk/version.rb +20 -0
  35. data/lib/ibm_appconfiguration_ruby_sdk.rb +20 -0
  36. data/sig/ibm_appconfiguration_ruby_sdk.rbs +4 -0
  37. metadata +209 -0
@@ -0,0 +1,252 @@
1
+ # Copyright 2026 IBM Corp. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # frozen_string_literal: true
16
+
17
+ require "singleton"
18
+
19
+ ##
20
+ # This module provides methods to construct headers & different URLs used by the SDK.
21
+ #
22
+ # The UrlBuilder class implements a Singleton pattern to ensure consistent URL
23
+ # configuration across the SDK. It handles:
24
+ # - HTTP/HTTPS endpoints for App Configuration service
25
+ # - WebSocket (WSS) connections for real-time updates
26
+ # - IAM authentication URLs
27
+ # - Support for both public and private endpoints
28
+ # - Environment-specific URL overrides for dev/staging/testing
29
+ #
30
+ ##
31
+ class UrlBuilder
32
+ include Singleton
33
+
34
+ # Constants for URL construction
35
+ HTTPS_PROTOCOL = "https://"
36
+ WEBSOCKET_PROTOCOL = "wss://"
37
+ BASE_URL = ".apprapp.cloud.ibm.com"
38
+ WEBSOCKET_PATH = "/wsfeature"
39
+ SERVICE_PATH = "/apprapp"
40
+ PRIVATE_ENDPOINT_PREFIX = "private."
41
+
42
+ # IAM URLs
43
+ IAM_TEST_URL = "iam.test.cloud.ibm.com/identity/token"
44
+ IAM_PROD_URL = "iam.cloud.ibm.com/identity/token"
45
+
46
+ ##
47
+ # Initialize the UrlBuilder with default values
48
+ def initialize
49
+ @region = ""
50
+ @instance_guid = nil
51
+ @apikey = nil
52
+ @override_service_url = nil
53
+ @use_private_endpoint = false
54
+ @websocket_full_url = nil
55
+ end
56
+
57
+ ##
58
+ # Set the region value
59
+ #
60
+ # @param value [String] Region name (e.g., 'us-south', 'eu-gb', 'au-syd')
61
+ # @return [String] the region value
62
+
63
+ ##
64
+ # Get the region value
65
+ #
66
+ # @return [String] the region value
67
+ attr_accessor :region
68
+
69
+ ##
70
+ # Set the service instance GUID
71
+ #
72
+ # @param value [String] GUID of the service instance
73
+ # @return [String] the GUID value
74
+ def guid=(value)
75
+ @instance_guid = value
76
+ end
77
+
78
+ ##
79
+ # Get the service instance GUID
80
+ #
81
+ # @return [String] the GUID value
82
+ def guid
83
+ @instance_guid
84
+ end
85
+
86
+ ##
87
+ # Set the API key
88
+ #
89
+ # @param value [String] API key of the service instance
90
+ # @return [String] the API key value
91
+
92
+ ##
93
+ # Get the API key
94
+ #
95
+ # @return [String] the API key value
96
+ attr_accessor :apikey
97
+
98
+ ##
99
+ # Set the overridden base service URL.
100
+ # Used for testing, development, or staging environments.
101
+ #
102
+ # @param value [String] The base service URL
103
+ # @return [String] the override URL value
104
+ def base_service_url=(value)
105
+ @override_service_url = value
106
+ end
107
+
108
+ ##
109
+ # Alias for base_service_url= to match AppConfiguration usage
110
+ def set_base_service_url(value)
111
+ self.base_service_url = value
112
+ end
113
+
114
+ ##
115
+ # Get the base URL for the App Configuration service instance.
116
+ # Returns the appropriate URL based on environment and endpoint type.
117
+ #
118
+ # @return [String] The base service URL
119
+ #
120
+ # @example Production public endpoint
121
+ # # Returns: https://us-south.apprapp.cloud.ibm.com
122
+ # builder.base_service_url
123
+ #
124
+ # @example Production private endpoint
125
+ # # Returns: https://private.us-south.apprapp.cloud.ibm.com
126
+ # builder.use_private_endpoint = true
127
+ # builder.base_service_url
128
+ #
129
+ def base_service_url
130
+ # For dev & stage environments
131
+ if @override_service_url
132
+ return add_private_prefix_to_url(@override_service_url) if @use_private_endpoint
133
+
134
+ return @override_service_url
135
+ end
136
+
137
+ # For production
138
+ return "#{HTTPS_PROTOCOL}#{PRIVATE_ENDPOINT_PREFIX}#{@region}#{BASE_URL}" if @use_private_endpoint
139
+
140
+ "#{HTTPS_PROTOCOL}#{@region}#{BASE_URL}"
141
+ end
142
+
143
+ ##
144
+ # Get the IAM (Identity and Access Management) URL for authentication.
145
+ #
146
+ # @return [String] The IAM URL
147
+ #
148
+ # @example Production IAM URL
149
+ # # Returns: https://iam.cloud.ibm.com
150
+ # builder.iam_url
151
+ #
152
+ # @example Test environment IAM URL
153
+ # # Returns: https://iam.test.cloud.ibm.com
154
+ # builder.base_service_url = 'https://test.example.com'
155
+ # builder.iam_url
156
+ #
157
+ def iam_url
158
+ # For dev & stage environments
159
+ if @override_service_url
160
+ return "#{HTTPS_PROTOCOL}#{PRIVATE_ENDPOINT_PREFIX}#{IAM_TEST_URL}" if @use_private_endpoint
161
+
162
+ return "#{HTTPS_PROTOCOL}#{IAM_TEST_URL}"
163
+ end
164
+
165
+ # For production
166
+ return "#{HTTPS_PROTOCOL}#{PRIVATE_ENDPOINT_PREFIX}#{IAM_PROD_URL}" if @use_private_endpoint
167
+
168
+ "#{HTTPS_PROTOCOL}#{IAM_PROD_URL}"
169
+ end
170
+
171
+ ##
172
+ # Set the WebSocket URL with collection and environment IDs.
173
+ # Constructs the complete WebSocket URL with query parameters.
174
+ #
175
+ # @param collection_id [String] The collection ID
176
+ # @param environment_id [String] The environment ID
177
+ # @return [String] The constructed WebSocket URL
178
+ #
179
+ # @example
180
+ # builder.set_websocket_url('collection-1', 'env-prod')
181
+ # # Sets: wss://us-south.apprapp.cloud.ibm.com/apprapp/wsfeature?instance_id=...&collection_id=collection-1&environment_id=env-prod
182
+ #
183
+ def set_websocket_url(collection_id, environment_id)
184
+ ws = WEBSOCKET_PROTOCOL.dup
185
+
186
+ if @override_service_url
187
+ # For dev & stage environments
188
+ temp = @override_service_url.gsub(%r{https?://}, "")
189
+ ws += PRIVATE_ENDPOINT_PREFIX if @use_private_endpoint
190
+ ws += temp
191
+ else
192
+ # For production
193
+ ws += PRIVATE_ENDPOINT_PREFIX if @use_private_endpoint
194
+ ws += @region
195
+ ws += BASE_URL
196
+ end
197
+
198
+ @websocket_full_url = "#{ws}#{SERVICE_PATH}#{WEBSOCKET_PATH}?" \
199
+ "instance_id=#{@instance_guid}&" \
200
+ "collection_id=#{collection_id}&" \
201
+ "environment_id=#{environment_id}"
202
+ end
203
+
204
+ ##
205
+ # Get the WebSocket URL.
206
+ # Must call set_websocket_url first to construct the URL.
207
+ #
208
+ # @return [String, nil] The WebSocket URL or nil if not set
209
+ def websocket_url
210
+ @websocket_full_url
211
+ end
212
+
213
+ ##
214
+ # Enable or disable private endpoint usage.
215
+ # When enabled, all URLs will use IBM Cloud private network routing.
216
+ #
217
+ # @param value [Boolean] Set to true to use private endpoints
218
+ # @return [Boolean] the private endpoint setting
219
+ #
220
+ # @example Enable private endpoint
221
+ # builder.use_private_endpoint = true
222
+ # # All URLs will now include 'private.' prefix
223
+ #
224
+ attr_writer :use_private_endpoint
225
+
226
+ ##
227
+ # Check if private endpoint is enabled
228
+ #
229
+ # @return [Boolean] true if private endpoint is enabled
230
+ def use_private_endpoint?
231
+ @use_private_endpoint
232
+ end
233
+
234
+ private
235
+
236
+ ##
237
+ # Add private endpoint prefix to a URL
238
+ #
239
+ # @param url [String] The URL to modify
240
+ # @return [String] The URL with private prefix added
241
+ #
242
+ # @example
243
+ # add_private_prefix_to_url('https://example.com')
244
+ # # Returns: https://private.example.com
245
+ #
246
+ def add_private_prefix_to_url(url)
247
+ parts = url.split("://")
248
+ return url if parts.length != 2
249
+
250
+ "#{parts[0]}://#{PRIVATE_ENDPOINT_PREFIX}#{parts[1]}"
251
+ end
252
+ end
@@ -0,0 +1,20 @@
1
+ # Copyright 2026 IBM Corp. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # frozen_string_literal: true
16
+
17
+ module IbmAppconfigurationRubySdk
18
+ # Version of the IBM Cloud App Configuration Ruby SDK
19
+ VERSION = "0.1.0-rc.0"
20
+ end
@@ -0,0 +1,20 @@
1
+ # Copyright 2026 IBM Corp. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # frozen_string_literal: true
16
+
17
+ require_relative "./ibm_appconfiguration_ruby_sdk/app_configuration"
18
+
19
+ module IbmAppconfigurationRubySdk
20
+ end
@@ -0,0 +1,4 @@
1
+ module IbmAppconfigurationRubySdk
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,209 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ibm_appconfiguration_ruby_sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre.rc.0
5
+ platform: ruby
6
+ authors:
7
+ - IBM Cloud App Configuration
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: ibm_cloud_sdk_core
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.1'
26
+ - !ruby/object:Gem::Dependency
27
+ name: json
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: murmurhash3
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.1'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.1'
54
+ - !ruby/object:Gem::Dependency
55
+ name: websocket-driver
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.7'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.7'
68
+ - !ruby/object:Gem::Dependency
69
+ name: irb
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: rake
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '13.0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '13.0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: rspec
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '3.0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '3.0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rubocop
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '1.21'
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '1.21'
124
+ - !ruby/object:Gem::Dependency
125
+ name: yard
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '0.9'
131
+ type: :development
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '0.9'
138
+ description: IBM Cloud App Configuration SDK is used to perform feature evaluation
139
+ based on the configuration on IBM Cloud App Configuration service.
140
+ email:
141
+ - mdevsrvs@in.ibm.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - CHANGELOG.md
147
+ - CODE_OF_CONDUCT.md
148
+ - CONTRIBUTING.md
149
+ - LICENSE
150
+ - README.md
151
+ - Rakefile
152
+ - examples/README.md
153
+ - examples/app.rb
154
+ - lib/ibm_appconfiguration_ruby_sdk.rb
155
+ - lib/ibm_appconfiguration_ruby_sdk/app_configuration.rb
156
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/configuration_handler.rb
157
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/internal/constants.rb
158
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/internal/file_manager.rb
159
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/internal/logger.rb
160
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/internal/retry_manager/background_retry_manager.rb
161
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/internal/retry_manager/config_fetcher.rb
162
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/internal/utils.rb
163
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/internal/websocket_client/connection_manager.rb
164
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/internal/websocket_client/connectivity.rb
165
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/internal/websocket_client/driver_socket.rb
166
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/internal/websocket_client/retry_policy.rb
167
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/internal/websocket_client/state.rb
168
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/internal/websocket_client/watchdog.rb
169
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/internal/websocket_client/websocket_client.rb
170
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/models/feature.rb
171
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/models/property.rb
172
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/models/rule.rb
173
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/models/secret_property.rb
174
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/models/segment.rb
175
+ - lib/ibm_appconfiguration_ruby_sdk/configurations/models/segment_rules.rb
176
+ - lib/ibm_appconfiguration_ruby_sdk/core/api_manager.rb
177
+ - lib/ibm_appconfiguration_ruby_sdk/core/metering.rb
178
+ - lib/ibm_appconfiguration_ruby_sdk/core/url_builder.rb
179
+ - lib/ibm_appconfiguration_ruby_sdk/version.rb
180
+ - sig/ibm_appconfiguration_ruby_sdk.rbs
181
+ homepage: https://github.com/IBM/appconfiguration-ruby-sdk
182
+ licenses:
183
+ - Apache-2.0
184
+ metadata:
185
+ allowed_push_host: https://rubygems.org
186
+ homepage_uri: https://github.com/IBM/appconfiguration-ruby-sdk
187
+ source_code_uri: https://github.com/IBM/appconfiguration-ruby-sdk
188
+ changelog_uri: https://github.com/IBM/appconfiguration-ruby-sdk/blob/main/CHANGELOG.md
189
+ bug_tracker_uri: https://github.com/IBM/appconfiguration-ruby-sdk/issues
190
+ documentation_uri: https://github.com/IBM/appconfiguration-ruby-sdk
191
+ rubygems_mfa_required: 'true'
192
+ rdoc_options: []
193
+ require_paths:
194
+ - lib
195
+ required_ruby_version: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: 3.2.0
200
+ required_rubygems_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ requirements: []
206
+ rubygems_version: 4.0.11
207
+ specification_version: 4
208
+ summary: IBM Cloud App Configuration Ruby SDK
209
+ test_files: []