Class: SpreePacketa::Soap::Client
- Inherits:
-
Object
- Object
- SpreePacketa::Soap::Client
- Defined in:
- lib/spree_packeta/soap/client.rb
Constant Summary collapse
- MAX_RETRIES =
3- RETRY_DELAY =
second
1
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#call(operation, message = {}) ⇒ Savon::Response
Call a SOAP operation with automatic error handling and retries.
-
#initialize ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
13 14 15 |
# File 'lib/spree_packeta/soap/client.rb', line 13 def initialize @client = build_client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
11 12 13 |
# File 'lib/spree_packeta/soap/client.rb', line 11 def client @client end |
Instance Method Details
#call(operation, message = {}) ⇒ Savon::Response
Call a SOAP operation with automatic error handling and retries
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/spree_packeta/soap/client.rb', line 26 def call(operation, = {}) retries = 0 begin # Always include API password in the message = .merge(api_password: api_password) response = client.call(operation, message: ) handle_response(response) rescue Savon::SOAPFault => e handle_soap_fault(e) rescue Savon::HTTPError, Savon::InvalidResponseError => e retries += 1 if retries <= MAX_RETRIES sleep(RETRY_DELAY * retries) retry else raise NetworkError, "Network error after #{MAX_RETRIES} retries: #{e.}" end rescue StandardError => e raise ApiError, "Unexpected error: #{e.}" end end |