Class: LaunchDarkly::Impl::DataSystem::HTTPFDv1PollingRequester Private
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::DataSystem::HTTPFDv1PollingRequester
- Includes:
- Requester
- Defined in:
- lib/ldclient-rb/impl/data_system/polling.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
HTTPFDv1PollingRequester is a Requester that uses HTTP to make requests to the FDv1 polling endpoint.
Instance Method Summary collapse
- #fetch(selector) ⇒ Result private
-
#initialize(sdk_key, http_config, config) ⇒ HTTPFDv1PollingRequester
constructor
private
A new instance of HTTPFDv1PollingRequester.
-
#stop ⇒ Object
private
Closes the HTTP client and releases any persistent connections.
Constructor Details
#initialize(sdk_key, http_config, config) ⇒ HTTPFDv1PollingRequester
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of HTTPFDv1PollingRequester.
348 349 350 351 352 353 354 355 356 |
# File 'lib/ldclient-rb/impl/data_system/polling.rb', line 348 def initialize(sdk_key, http_config, config) @etag = nil @config = config @sdk_key = sdk_key @poll_uri = http_config.base_uri + FDV1_POLLING_ENDPOINT @http_client = Impl::Util.new_http_client(http_config) .use(:auto_inflate) .headers("Accept-Encoding" => "gzip") end |
Instance Method Details
#fetch(selector) ⇒ Result
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/ldclient-rb/impl/data_system/polling.rb', line 362 def fetch(selector) query_params = [] query_params << ["filter", @config.payload_filter_key] unless @config.payload_filter_key.nil? uri = @poll_uri if query_params.any? filter_query = URI.encode_www_form(query_params) uri = "#{uri}?#{filter_query}" end headers = {} Impl::Util.default_http_headers(@sdk_key, @config).each { |k, v| headers[k] = v } headers["If-None-Match"] = @etag unless @etag.nil? begin response = @http_client.request("GET", uri, headers: headers) status = response.status.code response_headers = response.headers.to_h.transform_keys(&:downcase) if status >= 400 return LaunchDarkly::Result.fail( "HTTP error #{status}", LaunchDarkly::Impl::DataSource::UnexpectedResponseError.new(status), response_headers ) end if status == 304 return LaunchDarkly::Result.success([LaunchDarkly::Interfaces::DataSystem::ChangeSetBuilder.no_changes, response_headers]) end body = response.to_s data = JSON.parse(body, symbolize_names: true) etag = response_headers["etag"] @etag = etag unless etag.nil? @config.logger.debug { "[LDClient] #{uri} response status:[#{status}] ETag:[#{etag}]" } changeset_result = LaunchDarkly::Impl::DataSystem.fdv1_polling_payload_to_changeset(data) if changeset_result.success? LaunchDarkly::Result.success([changeset_result.value, response_headers]) else LaunchDarkly::Result.fail(changeset_result.error, changeset_result.exception, response_headers) end rescue JSON::ParserError => e LaunchDarkly::Result.fail("Failed to parse JSON: #{e.}", e, response_headers) rescue => e LaunchDarkly::Result.fail("Network error: #{e.}", e) end end |
#stop ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Closes the HTTP client and releases any persistent connections.
416 417 418 419 420 421 |
# File 'lib/ldclient-rb/impl/data_system/polling.rb', line 416 def stop begin @http_client.close if @http_client rescue end end |