Class: DebtManagementCenter::VBS::Request

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Common::Client::Concerns::Monitoring
Defined in:
lib/debt_management_center/vbs/request.rb

Overview

An object responsible for making HTTP calls to the VBS service that relate to DMC

Constant Summary collapse

STATSD_KEY_PREFIX =
'api.vbs.financial_status_report.request'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common::Client::Concerns::Monitoring

#increment, #increment_failure, #increment_total, #with_monitoring

Constructor Details

#initializeRequest

Returns a new instance of Request.



34
35
36
# File 'lib/debt_management_center/vbs/request.rb', line 34

def initialize
  @settings = Settings.mcp.vbs_v2
end

Instance Attribute Details

#hostObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/debt_management_center/vbs/request.rb', line 16

class Request
  extend Forwardable
  include Common::Client::Concerns::Monitoring

  STATSD_KEY_PREFIX = 'api.vbs.financial_status_report.request'

  attr_reader :settings

  def_delegators :settings, :base_path, :host, :service_name, :url

  ##
  # Builds a DebtManagementCenter::VBS::Request instance
  #
  # @return [DebtManagementCenter::VBS::Request] an instance of this class
  def self.build
    new
  end

  def initialize
    @settings = Settings.mcp.vbs_v2
  end

  ##
  # Make a HTTP POST call to the VBS service in order to submit VHA FSR
  #
  # @param path [String]
  # @param params [Hash]
  #
  # @return [Faraday::Response]
  #
  def post(path, params)
    with_monitoring do
      connection.post(path) do |req|
        req.body = params
      end
    end
  end

  ##
  # Create a connection object that managers the attributes
  # and the middleware stack for making our HTTP requests to VBS
  #
  # @return [Faraday::Connection]
  #
  def connection
    Faraday.new(url:, headers:) do |conn|
      conn.request :json
      conn.use :breakers
      conn.use Faraday::Response::RaiseError
      conn.response :raise_custom_error, error_prefix: service_name
      conn.response :json
      conn.response :betamocks if mock_enabled?
      conn.adapter Faraday.default_adapter
    end
  end

  ##
  # HTTP request headers for the VBS API
  #
  # @return [Hash]
  #
  def headers
    {
      'Host' => host,
      'Content-Type' => 'application/json',
      'apiKey' => settings.api_key
    }
  end

  ##
  # Betamocks enabled status from settings
  #
  # @return [Boolean]
  #
  def mock_enabled?
    settings.mock || false
  end
end

#service_nameObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/debt_management_center/vbs/request.rb', line 16

class Request
  extend Forwardable
  include Common::Client::Concerns::Monitoring

  STATSD_KEY_PREFIX = 'api.vbs.financial_status_report.request'

  attr_reader :settings

  def_delegators :settings, :base_path, :host, :service_name, :url

  ##
  # Builds a DebtManagementCenter::VBS::Request instance
  #
  # @return [DebtManagementCenter::VBS::Request] an instance of this class
  def self.build
    new
  end

  def initialize
    @settings = Settings.mcp.vbs_v2
  end

  ##
  # Make a HTTP POST call to the VBS service in order to submit VHA FSR
  #
  # @param path [String]
  # @param params [Hash]
  #
  # @return [Faraday::Response]
  #
  def post(path, params)
    with_monitoring do
      connection.post(path) do |req|
        req.body = params
      end
    end
  end

  ##
  # Create a connection object that managers the attributes
  # and the middleware stack for making our HTTP requests to VBS
  #
  # @return [Faraday::Connection]
  #
  def connection
    Faraday.new(url:, headers:) do |conn|
      conn.request :json
      conn.use :breakers
      conn.use Faraday::Response::RaiseError
      conn.response :raise_custom_error, error_prefix: service_name
      conn.response :json
      conn.response :betamocks if mock_enabled?
      conn.adapter Faraday.default_adapter
    end
  end

  ##
  # HTTP request headers for the VBS API
  #
  # @return [Hash]
  #
  def headers
    {
      'Host' => host,
      'Content-Type' => 'application/json',
      'apiKey' => settings.api_key
    }
  end

  ##
  # Betamocks enabled status from settings
  #
  # @return [Boolean]
  #
  def mock_enabled?
    settings.mock || false
  end
end

#settingsConfig::Options

Returns:

  • (Config::Options)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/debt_management_center/vbs/request.rb', line 16

class Request
  extend Forwardable
  include Common::Client::Concerns::Monitoring

  STATSD_KEY_PREFIX = 'api.vbs.financial_status_report.request'

  attr_reader :settings

  def_delegators :settings, :base_path, :host, :service_name, :url

  ##
  # Builds a DebtManagementCenter::VBS::Request instance
  #
  # @return [DebtManagementCenter::VBS::Request] an instance of this class
  def self.build
    new
  end

  def initialize
    @settings = Settings.mcp.vbs_v2
  end

  ##
  # Make a HTTP POST call to the VBS service in order to submit VHA FSR
  #
  # @param path [String]
  # @param params [Hash]
  #
  # @return [Faraday::Response]
  #
  def post(path, params)
    with_monitoring do
      connection.post(path) do |req|
        req.body = params
      end
    end
  end

  ##
  # Create a connection object that managers the attributes
  # and the middleware stack for making our HTTP requests to VBS
  #
  # @return [Faraday::Connection]
  #
  def connection
    Faraday.new(url:, headers:) do |conn|
      conn.request :json
      conn.use :breakers
      conn.use Faraday::Response::RaiseError
      conn.response :raise_custom_error, error_prefix: service_name
      conn.response :json
      conn.response :betamocks if mock_enabled?
      conn.adapter Faraday.default_adapter
    end
  end

  ##
  # HTTP request headers for the VBS API
  #
  # @return [Hash]
  #
  def headers
    {
      'Host' => host,
      'Content-Type' => 'application/json',
      'apiKey' => settings.api_key
    }
  end

  ##
  # Betamocks enabled status from settings
  #
  # @return [Boolean]
  #
  def mock_enabled?
    settings.mock || false
  end
end

#urlObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/debt_management_center/vbs/request.rb', line 16

class Request
  extend Forwardable
  include Common::Client::Concerns::Monitoring

  STATSD_KEY_PREFIX = 'api.vbs.financial_status_report.request'

  attr_reader :settings

  def_delegators :settings, :base_path, :host, :service_name, :url

  ##
  # Builds a DebtManagementCenter::VBS::Request instance
  #
  # @return [DebtManagementCenter::VBS::Request] an instance of this class
  def self.build
    new
  end

  def initialize
    @settings = Settings.mcp.vbs_v2
  end

  ##
  # Make a HTTP POST call to the VBS service in order to submit VHA FSR
  #
  # @param path [String]
  # @param params [Hash]
  #
  # @return [Faraday::Response]
  #
  def post(path, params)
    with_monitoring do
      connection.post(path) do |req|
        req.body = params
      end
    end
  end

  ##
  # Create a connection object that managers the attributes
  # and the middleware stack for making our HTTP requests to VBS
  #
  # @return [Faraday::Connection]
  #
  def connection
    Faraday.new(url:, headers:) do |conn|
      conn.request :json
      conn.use :breakers
      conn.use Faraday::Response::RaiseError
      conn.response :raise_custom_error, error_prefix: service_name
      conn.response :json
      conn.response :betamocks if mock_enabled?
      conn.adapter Faraday.default_adapter
    end
  end

  ##
  # HTTP request headers for the VBS API
  #
  # @return [Hash]
  #
  def headers
    {
      'Host' => host,
      'Content-Type' => 'application/json',
      'apiKey' => settings.api_key
    }
  end

  ##
  # Betamocks enabled status from settings
  #
  # @return [Boolean]
  #
  def mock_enabled?
    settings.mock || false
  end
end

Class Method Details

.buildDebtManagementCenter::VBS::Request

Builds a DebtManagementCenter::VBS::Request instance

Returns:



30
31
32
# File 'lib/debt_management_center/vbs/request.rb', line 30

def self.build
  new
end

Instance Method Details

#connectionFaraday::Connection

Create a connection object that managers the attributes and the middleware stack for making our HTTP requests to VBS

Returns:

  • (Faraday::Connection)


60
61
62
63
64
65
66
67
68
69
70
# File 'lib/debt_management_center/vbs/request.rb', line 60

def connection
  Faraday.new(url:, headers:) do |conn|
    conn.request :json
    conn.use :breakers
    conn.use Faraday::Response::RaiseError
    conn.response :raise_custom_error, error_prefix: service_name
    conn.response :json
    conn.response :betamocks if mock_enabled?
    conn.adapter Faraday.default_adapter
  end
end

#headersHash

HTTP request headers for the VBS API

Returns:

  • (Hash)


77
78
79
80
81
82
83
# File 'lib/debt_management_center/vbs/request.rb', line 77

def headers
  {
    'Host' => host,
    'Content-Type' => 'application/json',
    'apiKey' => settings.api_key
  }
end

#mock_enabled?Boolean

Betamocks enabled status from settings

Returns:

  • (Boolean)


90
91
92
# File 'lib/debt_management_center/vbs/request.rb', line 90

def mock_enabled?
  settings.mock || false
end

#post(path, params) ⇒ Faraday::Response

Make a HTTP POST call to the VBS service in order to submit VHA FSR

Parameters:

  • path (String)
  • params (Hash)

Returns:

  • (Faraday::Response)


46
47
48
49
50
51
52
# File 'lib/debt_management_center/vbs/request.rb', line 46

def post(path, params)
  with_monitoring do
    connection.post(path) do |req|
      req.body = params
    end
  end
end