Class: Rox::Core::ConfigurationFetcher

Inherits:
ConfigurationFetcherBase show all
Defined in:
lib/rox/core/network/configuration_fetcher.rb

Instance Method Summary collapse

Methods inherited from ConfigurationFetcherBase

#initialize, #write_fetch_error_to_log_and_invoke_fetch_handler, #write_fetch_exception_to_log_and_invoke_fetch_handler

Constructor Details

This class inherits a constructor from Rox::Core::ConfigurationFetcherBase

Instance Method Details

#fetchObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rox/core/network/configuration_fetcher.rb', line 8

def fetch
  source = ConfigurationSource::CDN
  begin
    fetch_result = fetch_from_cdn
    if fetch_result.success?
      return ConfigurationFetchResult.new(fetch_result.text, source)
    else
      write_fetch_error_to_log_and_invoke_fetch_handler(source, fetch_result, false, ConfigurationSource::API)
      source = ConfigurationSource::API
      fetch_result = fetch_from_api
      return ConfigurationFetchResult.new(fetch_result.text, source) if fetch_result.success?
    end

    write_fetch_error_to_log_and_invoke_fetch_handler(source, fetch_result)
  rescue StandardError => e
    write_fetch_exception_to_log_and_invoke_fetch_handler(source, e)
  end

  nil
end

#fetch_from_apiObject



33
34
35
36
# File 'lib/rox/core/network/configuration_fetcher.rb', line 33

def fetch_from_api
  api_request = @request_configuration_builder.build_for_api
  @request.send_post(api_request.url, api_request.query_params)
end

#fetch_from_cdnObject



29
30
31
# File 'lib/rox/core/network/configuration_fetcher.rb', line 29

def fetch_from_cdn
  @request.send_get(@request_configuration_builder.build_for_cdn)
end