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(app_identifier = nil) ⇒ 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(app_identifier = nil) ⇒ Endpoint
Create a new Endpoint
Economic::Session uses this internally
Attributes
-
app_identifier- A string identifiying your application, as described in techtalk.e-conomic.com/e-conomic-soap-api-now-requires-you-to-specify-a-custom-x-economicappidentifier-header/
19 20 21 |
# File 'lib/economic/endpoint.rb', line 19 def initialize(app_identifier = nil) @app_identifier = app_identifier 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.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/economic/endpoint.rb', line 29 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
48 49 50 51 52 53 54 55 |
# File 'lib/economic/endpoint.rb', line 48 def client(force_new_instance: false) reset_client if force_new_instance = if @app_identifier [:headers] = {"X-EconomicAppIdentifier" => @app_identifier} end @@client ||= Savon.client() end |
#soap_action_name(entity_class, action) ⇒ Object
Returns the E-conomic API action name to call
58 59 60 61 62 63 |
# File 'lib/economic/endpoint.rb', line 58 def soap_action_name(entity_class, action) [ class_name_without_modules(entity_class), action.to_s ].collect(&:snakecase).join("_").intern end |