Class: IbmAppconfigurationRubySdk::UrlBuilder

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/ibm_appconfiguration_ruby_sdk/url_builder.rb

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

Instance Method Summary collapse

Constructor Details

#initializeUrlBuilder

Initialize the UrlBuilder with default values



49
50
51
52
53
54
55
56
57
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 49

def initialize
  @region = ""
  @instance_guid = nil
  @apikey = nil
  @override_service_url = nil
  @override_websocket_url = nil
  @use_private_endpoint = false
  @websocket_full_url = nil
end

Instance Attribute Details

#apikeyString

Get the API key

Returns:

  • (String)

    the API key value



98
99
100
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 98

def apikey
  @apikey
end

#regionString

Get the region value

Returns:

  • (String)

    the region value



69
70
71
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 69

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.

Examples:

Enable private endpoint

builder.use_private_endpoint = true
# All URLs will now include 'private.' prefix

Parameters:

  • value (Boolean)

    Set to true to use private endpoints

Returns:

  • (Boolean)

    the private endpoint setting



243
244
245
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 243

def use_private_endpoint=(value)
  @use_private_endpoint = value
end

Instance Method Details

#base_service_urlString

Get the base URL for the App Configuration service instance. Returns the appropriate URL based on environment and endpoint type.

Examples:

Production public endpoint

# Returns: https://us-south.apprapp.cloud.ibm.com
builder.base_service_url

Production private endpoint

# Returns: https://private.us-south.apprapp.cloud.ibm.com
builder.use_private_endpoint = true
builder.base_service_url

Returns:

  • (String)

    The base service URL



147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 147

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.

Parameters:

  • value (String)

    The base service URL

Returns:

  • (String)

    the override URL value



106
107
108
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 106

def base_service_url=(value)
  @override_service_url = value
end

#guidString

Get the service instance GUID

Returns:

  • (String)

    the GUID value



84
85
86
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 84

def guid
  @instance_guid
end

#guid=(value) ⇒ String

Set the service instance GUID

Parameters:

  • value (String)

    GUID of the service instance

Returns:

  • (String)

    the GUID value



76
77
78
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 76

def guid=(value)
  @instance_guid = value
end

#iam_urlString

Get the IAM (Identity and Access Management) URL for authentication.

Examples:

Production IAM URL

# Returns: https://iam.cloud.ibm.com
builder.iam_url

Test environment IAM URL

# Returns: https://iam.test.cloud.ibm.com
builder.base_service_url = 'https://test.example.com'
builder.iam_url

Returns:

  • (String)

    The IAM URL



175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 175

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

#inspectString

Returns a developer-friendly string that masks the API key to prevent accidental credential exposure in logs and test output.

Returns:

  • (String)


258
259
260
261
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 258

def inspect
  masked = @apikey ? "#{@apikey[0..3]}#{'*' * [@apikey.length - 4, 0].max}" : "nil"
  "#<#{self.class} region=#{@region.inspect} apikey=#{masked}>"
end

#override_websocket_url=(value) ⇒ Object

Override the WebSocket URL directly. Used for local dev/testing when the WebSocket server runs on a different port or host than the HTTP service URL (e.g. ws://127.0.0.1:5000).

Parameters:

  • value (String)

    Full WebSocket URL (ws:// or wss://)



122
123
124
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 122

def override_websocket_url=(value)
  @override_websocket_url = value
end

#set_base_service_url(value) ⇒ Object

Alias for base_service_url= to match AppConfiguration usage



112
113
114
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 112

def set_base_service_url(value)
  self.base_service_url = value
end

#set_override_websocket_url(value) ⇒ Object

Alias for override_websocket_url=



128
129
130
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 128

def set_override_websocket_url(value)
  self.override_websocket_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.

Examples:

builder.set_websocket_url('collection-1', 'env-prod')
# Sets: wss://us-south.apprapp.cloud.ibm.com/apprapp/wsfeature?instance_id=...&collection_id=collection-1&environment_id=env-prod

Parameters:

  • collection_id (String)

    The collection ID

  • environment_id (String)

    The environment ID

Returns:

  • (String)

    The constructed WebSocket URL



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 201

def set_websocket_url(collection_id, environment_id)
  if @override_service_url
    # For dev & stage environments — mirror http->ws, https->wss
    ws_scheme = @override_service_url.start_with?("https") ? "wss://" : "ws://"
    temp = @override_service_url.gsub(%r{https?://}, "")
    ws = ws_scheme.dup
    ws += PRIVATE_ENDPOINT_PREFIX if @use_private_endpoint
    ws += temp
  else
    # For production — always wss://
    ws = WEBSOCKET_PROTOCOL.dup
    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

Returns:

  • (Boolean)

    true if private endpoint is enabled



249
250
251
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 249

def use_private_endpoint?
  @use_private_endpoint
end

#websocket_urlString?

Get the WebSocket URL. Returns the manually overridden URL if set, otherwise the constructed one.

Returns:

  • (String, nil)

    The WebSocket URL or nil if not set



228
229
230
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 228

def websocket_url
  @override_websocket_url || @websocket_full_url
end