Class: Economic::Endpoint
- Inherits:
-
Object
- Object
- Economic::Endpoint
- Extended by:
- Forwardable
- Defined in:
- lib/economic/endpoint.rb
Overview
Economic::Endpoint models the actual SOAP endpoint at E-conomic.
This is where all knowledge of SOAP actions and requests exists.
Instance Method Summary collapse
-
#call(soap_action, data = nil, cookies = nil) ⇒ Object
Invokes soap_action on the API endpoint with the given data.
-
#client(force_new_instance: false) ⇒ Object
Returns a Savon::Client to connect to the e-conomic endpoint.
-
#initialize ⇒ Endpoint
constructor
Create a new Endpoint.
-
#soap_action_name(entity_class, action) ⇒ Object
Returns the E-conomic API action name to call.
Constructor Details
#initialize ⇒ Endpoint
Create a new Endpoint
Economic::Session uses this internally
16 |
# File 'lib/economic/endpoint.rb', line 16 def initialize; end |
Instance Method Details
#call(soap_action, data = nil, cookies = nil) ⇒ Object
Invokes soap_action on the API endpoint with the given data.
Returns a Hash with the resulting response from the endpoint as a Hash.
If you need access to more details from the unparsed SOAP response, supply a block to ‘call`. A Savon::Response will be yielded to the block.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/economic/endpoint.rb', line 24 def call(soap_action, data = nil, = nil) # set_client_headers(headers) response = request(soap_action, data, ) if block_given? yield response else extract_result_from_response(response, soap_action) end end |
#client(force_new_instance: false) ⇒ Object
Returns a Savon::Client to connect to the e-conomic endpoint
Cached on class-level to avoid loading the big WSDL file more than once (can take several hundred megabytes of RAM after a while…)
If you need to refresh the cached client and return a newly built instance, set force_new_instance to true
43 44 45 46 47 |
# File 'lib/economic/endpoint.rb', line 43 def client(force_new_instance: false) reset_client if force_new_instance = @@client ||= Savon.client() end |
#soap_action_name(entity_class, action) ⇒ Object
Returns the E-conomic API action name to call
50 51 52 53 54 55 |
# File 'lib/economic/endpoint.rb', line 50 def soap_action_name(entity_class, action) [ class_name_without_modules(entity_class), action.to_s ].collect(&:snakecase).join("_").intern end |