Class: Forms::Configuration

Inherits:
Common::Client::Configuration::REST show all
Defined in:
lib/forms/configuration.rb

Overview

HTTP client configuration for the Client, sets the base path, the base request headers, and a service name for breakers and metrics.

Instance Attribute Summary

Attributes inherited from Common::Client::Configuration::Base

#base_request_headers, #open_timeout, #read_timeout, #request_types, #user_agent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Common::Client::Configuration::Base

#breakers_error_threshold, #breakers_exception_handler, #breakers_matcher, #breakers_service, #create_new_breakers_service, #request_options, #service_exception

Class Method Details

.base_request_headersHash

Returns The basic headers required for any Forms API call.

Returns:

  • (Hash)

    The basic headers required for any Forms API call.



35
36
37
# File 'lib/forms/configuration.rb', line 35

def self.base_request_headers
  super.merge('apiKey' => Settings.lighthouse.api_key)
end

Instance Method Details

#base_pathString

Returns Base path for forms URLs.

Returns:

  • (String)

    Base path for forms URLs.



42
43
44
# File 'lib/forms/configuration.rb', line 42

def base_path
  Settings.forms.url
end

#connectionObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/forms/configuration.rb', line 13

def connection
  @conn ||= Faraday.new(base_path, headers: base_request_headers, request: request_options) do |faraday|
    faraday.use      :breakers
    faraday.use      Faraday::Response::RaiseError

    faraday.response :betamocks if mock_enabled?
    faraday.response :snakecase, symbolize: false
    faraday.response :json, content_type: /\bjson/ # ensures only json content types parsed
    faraday.adapter Faraday.default_adapter
  end
end

#mock_enabled?Boolean

Returns Should the service use mock data in lower environments.

Returns:

  • (Boolean)

    Should the service use mock data in lower environments.



28
29
30
# File 'lib/forms/configuration.rb', line 28

def mock_enabled?
  Settings.forms.mock || false
end

#service_nameString

Returns Service name to use in breakers and metrics.

Returns:

  • (String)

    Service name to use in breakers and metrics.



49
50
51
# File 'lib/forms/configuration.rb', line 49

def service_name
  'Forms'
end