Class: UrlBuilder
- Inherits:
-
Object
- Object
- UrlBuilder
- Includes:
- Singleton
- Defined in:
- lib/ibm_appconfiguration_ruby_sdk/core/url_builder.rb
Overview
This module provides methods to construct headers & different URLs used by the SDK.
The UrlBuilder class implements a Singleton pattern to ensure consistent URL configuration across the SDK. It handles:
-
HTTP/HTTPS endpoints for App Configuration service
-
WebSocket (WSS) connections for real-time updates
-
IAM authentication URLs
-
Support for both public and private endpoints
-
Environment-specific URL overrides for dev/staging/testing
Constant Summary collapse
- HTTPS_PROTOCOL =
Constants for URL construction
"https://"- WEBSOCKET_PROTOCOL =
"wss://"- BASE_URL =
".apprapp.cloud.ibm.com"- WEBSOCKET_PATH =
"/wsfeature"- SERVICE_PATH =
"/apprapp"- PRIVATE_ENDPOINT_PREFIX =
"private."- IAM_TEST_URL =
IAM URLs
"iam.test.cloud.ibm.com/identity/token"- IAM_PROD_URL =
"iam.cloud.ibm.com/identity/token"
Instance Attribute Summary collapse
-
#apikey ⇒ String
Get the API key.
-
#region ⇒ String
Get the region value.
-
#use_private_endpoint ⇒ Boolean
writeonly
Enable or disable private endpoint usage.
Instance Method Summary collapse
-
#base_service_url ⇒ String
Get the base URL for the App Configuration service instance.
-
#base_service_url=(value) ⇒ String
Set the overridden base service URL.
-
#guid ⇒ String
Get the service instance GUID.
-
#guid=(value) ⇒ String
Set the service instance GUID.
-
#iam_url ⇒ String
Get the IAM (Identity and Access Management) URL for authentication.
-
#initialize ⇒ UrlBuilder
constructor
Initialize the UrlBuilder with default values.
-
#set_base_service_url(value) ⇒ Object
Alias for base_service_url= to match AppConfiguration usage.
-
#set_websocket_url(collection_id, environment_id) ⇒ String
Set the WebSocket URL with collection and environment IDs.
-
#use_private_endpoint? ⇒ Boolean
Check if private endpoint is enabled.
-
#websocket_url ⇒ String?
Get the WebSocket URL.
Constructor Details
#initialize ⇒ UrlBuilder
Initialize the UrlBuilder with default values
48 49 50 51 52 53 54 55 |
# File 'lib/ibm_appconfiguration_ruby_sdk/core/url_builder.rb', line 48 def initialize @region = "" @instance_guid = nil @apikey = nil @override_service_url = nil @use_private_endpoint = false @websocket_full_url = nil end |
Instance Attribute Details
#apikey ⇒ String
Get the API key
96 97 98 |
# File 'lib/ibm_appconfiguration_ruby_sdk/core/url_builder.rb', line 96 def apikey @apikey end |
#region ⇒ String
Get the region value
67 68 69 |
# File 'lib/ibm_appconfiguration_ruby_sdk/core/url_builder.rb', line 67 def region @region end |
#use_private_endpoint=(value) ⇒ Boolean (writeonly)
Enable or disable private endpoint usage. When enabled, all URLs will use IBM Cloud private network routing.
224 225 226 |
# File 'lib/ibm_appconfiguration_ruby_sdk/core/url_builder.rb', line 224 def use_private_endpoint=(value) @use_private_endpoint = value end |
Instance Method Details
#base_service_url ⇒ String
Get the base URL for the App Configuration service instance. Returns the appropriate URL based on environment and endpoint type.
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/ibm_appconfiguration_ruby_sdk/core/url_builder.rb', line 129 def base_service_url # For dev & stage environments if @override_service_url return add_private_prefix_to_url(@override_service_url) if @use_private_endpoint return @override_service_url end # For production return "#{HTTPS_PROTOCOL}#{PRIVATE_ENDPOINT_PREFIX}#{@region}#{BASE_URL}" if @use_private_endpoint "#{HTTPS_PROTOCOL}#{@region}#{BASE_URL}" end |
#base_service_url=(value) ⇒ String
Set the overridden base service URL. Used for testing, development, or staging environments.
104 105 106 |
# File 'lib/ibm_appconfiguration_ruby_sdk/core/url_builder.rb', line 104 def base_service_url=(value) @override_service_url = value end |
#guid ⇒ String
Get the service instance GUID
82 83 84 |
# File 'lib/ibm_appconfiguration_ruby_sdk/core/url_builder.rb', line 82 def guid @instance_guid end |
#guid=(value) ⇒ String
Set the service instance GUID
74 75 76 |
# File 'lib/ibm_appconfiguration_ruby_sdk/core/url_builder.rb', line 74 def guid=(value) @instance_guid = value end |
#iam_url ⇒ String
Get the IAM (Identity and Access Management) URL for authentication.
157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/ibm_appconfiguration_ruby_sdk/core/url_builder.rb', line 157 def iam_url # For dev & stage environments if @override_service_url return "#{HTTPS_PROTOCOL}#{PRIVATE_ENDPOINT_PREFIX}#{IAM_TEST_URL}" if @use_private_endpoint return "#{HTTPS_PROTOCOL}#{IAM_TEST_URL}" end # For production return "#{HTTPS_PROTOCOL}#{PRIVATE_ENDPOINT_PREFIX}#{IAM_PROD_URL}" if @use_private_endpoint "#{HTTPS_PROTOCOL}#{IAM_PROD_URL}" end |
#set_base_service_url(value) ⇒ Object
Alias for base_service_url= to match AppConfiguration usage
110 111 112 |
# File 'lib/ibm_appconfiguration_ruby_sdk/core/url_builder.rb', line 110 def set_base_service_url(value) self.base_service_url = value end |
#set_websocket_url(collection_id, environment_id) ⇒ String
Set the WebSocket URL with collection and environment IDs. Constructs the complete WebSocket URL with query parameters.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/ibm_appconfiguration_ruby_sdk/core/url_builder.rb', line 183 def set_websocket_url(collection_id, environment_id) ws = WEBSOCKET_PROTOCOL.dup if @override_service_url # For dev & stage environments temp = @override_service_url.gsub(%r{https?://}, "") ws += PRIVATE_ENDPOINT_PREFIX if @use_private_endpoint ws += temp else # For production ws += PRIVATE_ENDPOINT_PREFIX if @use_private_endpoint ws += @region ws += BASE_URL end @websocket_full_url = "#{ws}#{SERVICE_PATH}#{WEBSOCKET_PATH}?" \ "instance_id=#{@instance_guid}&" \ "collection_id=#{collection_id}&" \ "environment_id=#{environment_id}" end |
#use_private_endpoint? ⇒ Boolean
Check if private endpoint is enabled
230 231 232 |
# File 'lib/ibm_appconfiguration_ruby_sdk/core/url_builder.rb', line 230 def use_private_endpoint? @use_private_endpoint end |
#websocket_url ⇒ String?
Get the WebSocket URL. Must call set_websocket_url first to construct the URL.
209 210 211 |
# File 'lib/ibm_appconfiguration_ruby_sdk/core/url_builder.rb', line 209 def websocket_url @websocket_full_url end |