Class: FreightKit::SoapClient
- Inherits:
-
Object
- Object
- FreightKit::SoapClient
- Defined in:
- lib/freight_kit/api_clients/soap_client.rb
Constant Summary collapse
- API_EXCEPTIONS =
[ Savon::HTTPError, Net::ReadTimeout, Net::OpenTimeout, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, ]
Instance Method Summary collapse
- #call(handle_soap_fault_error: true) ⇒ Object
-
#initialize(carrier:, action:, client_args:, call_args:, soap_operation:) ⇒ SoapClient
constructor
A new instance of SoapClient.
Constructor Details
#initialize(carrier:, action:, client_args:, call_args:, soap_operation:) ⇒ SoapClient
Returns a new instance of SoapClient.
14 15 16 17 18 19 20 |
# File 'lib/freight_kit/api_clients/soap_client.rb', line 14 def initialize(carrier:, action:, client_args:, call_args:, soap_operation:) @carrier = carrier @action = action @client_args = client_args || {} @call_args = call_args @soap_operation = soap_operation end |
Instance Method Details
#call(handle_soap_fault_error: true) ⇒ Object
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 |
# File 'lib/freight_kit/api_clients/soap_client.rb', line 22 def call(handle_soap_fault_error: true) # http = OpenStruct.new(code: 500, body: {}) # raise Savon::HTTPError, http api_exceptions = API_EXCEPTIONS # For testing and debugging # client_args.merge!(log: true, pretty_print_xml: true) Savon.client(**client_args).call(soap_operation, **call_args).body rescue *api_exceptions => e response = build_response_class(action:) response.error = ResponseError.new("Network Error: #{e}") response rescue Savon::InvalidResponseError response = build_response_class(action:) response.error = ResponseError.new('API Error: Invalid response') response rescue Savon::SOAPFault => e raise unless handle_soap_fault_error response = build_response_class(action:) response.error = ResponseError.new("API Error: #{e}") response rescue StandardError => e response = build_response_class(action:) response.error = ResponseError.new("API Error: #{e}") response end |