Class: BB::Configuration

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

Overview

HTTP client configuration for Client, sets the token, base path 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

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

Instance Method Details

#app_tokenString

Returns Client token set in ‘settings.yml` via credstash.

Returns:

  • (String)

    Client token set in ‘settings.yml` via credstash



20
21
22
# File 'lib/bb/configuration.rb', line 20

def app_token
  Settings.mhv.rx.app_token
end

#base_pathString

Returns Base path for dependent URLs.

Returns:

  • (String)

    Base path for dependent URLs



27
28
29
# File 'lib/bb/configuration.rb', line 27

def base_path
  "#{Settings.mhv.rx.host}/mhv-api/patient/v1/"
end

#caching_enabled?Boolean

Returns if the MHV BB collections should be cached.

Returns:

  • (Boolean)

    if the MHV BB collections should be cached



34
35
36
# File 'lib/bb/configuration.rb', line 34

def caching_enabled?
  Settings.mhv.bb.collection_caching_enabled || false
end

#connectionFaraday::Connection

Creates a connection with middleware for mapping errors, parsing XML, and adding breakers functionality

Returns:

  • (Faraday::Connection)

    a Faraday connection instance

See Also:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/bb/configuration.rb', line 52

def connection
  Faraday.new(base_path, headers: base_request_headers, request: request_options) do |conn|
    conn.use :breakers
    conn.request :camelcase
    conn.request :json

    # Uncomment this if you want curl command equivalent or response output to log
    # conn.request(:curl, ::Logger.new(STDOUT), :warn) unless Rails.env.production?
    # conn.response(:logger, ::Logger.new(STDOUT), bodies: true) unless Rails.env.production?

    conn.response :betamocks if Settings.mhv.bb.mock
    conn.response :bb_parser
    conn.response :snakecase
    conn.response :raise_error, error_prefix: service_name
    conn.response :mhv_errors
    conn.response :mhv_xml_html_errors
    conn.response :json_parser

    conn.adapter Faraday.default_adapter
  end
end

#service_nameString

Returns Service name to use in breakers and metrics.

Returns:

  • (String)

    Service name to use in breakers and metrics



41
42
43
# File 'lib/bb/configuration.rb', line 41

def service_name
  'BB'
end