Class: DefraRubyGovpay::API

Inherits:
Object
  • Object
show all
Defined in:
lib/defra_ruby_govpay/api.rb

Overview

The API class is responsible for making requests to the Govpay API. It handles the construction of request URLs, headers, and payload, and also deals with any errors that occur during the API request.

Instance Method Summary collapse

Constructor Details

#initialize(host_is_back_office:) ⇒ API

Returns a new instance of API.



20
21
22
# File 'lib/defra_ruby_govpay/api.rb', line 20

def initialize(host_is_back_office:)
  @host_is_back_office = host_is_back_office
end

Instance Method Details

#send_request(method:, path:, params: nil, is_moto: false) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/defra_ruby_govpay/api.rb', line 24

def send_request(method:, path:, params: nil, is_moto: false)
  @is_moto = is_moto
  DefraRubyGovpay.logger.debug build_log_message(method, path, params)

  begin
    response = execute_request(method, path, params)
    DefraRubyGovpay.logger.debug "Received response from Govpay: #{response}"
    response
  rescue StandardError => e
    handle_error(e, method, path, params)
  end
end