Class: Zuora::Soap::Client
- Inherits:
-
Object
- Object
- Zuora::Soap::Client
- Defined in:
- lib/zuora/soap/client.rb
Constant Summary collapse
- SOAP_API_URI =
'/apps/services/a/74.0'.freeze
- SESSION_TOKEN_XPATH =
%w(//soapenv:Envelope soapenv:Body api:loginResponse api:result api:Session).join('/').freeze
Instance Attribute Summary collapse
-
#session_token ⇒ Object
readonly
Returns the value of attribute session_token.
Instance Method Summary collapse
-
#call!(call_name, *args) ⇒ Faraday:Response
The primary interface via which users should make SOAP requests.
-
#initialize(username, password, sandbox = true) ⇒ Zuora::SoapClient
constructor
Creates a connection instance.
-
#request!(body) ⇒ Zuora::Response
Fire a request.
Constructor Details
#initialize(username, password, sandbox = true) ⇒ Zuora::SoapClient
Creates a connection instance. Makes an initial SOAP request to fetch session token. Subsequent requests contain the authenticated session id in headers.
20 21 22 23 |
# File 'lib/zuora/soap/client.rb', line 20 def initialize(username, password, sandbox = true) @sandbox = sandbox authenticate!(username, password) end |
Instance Attribute Details
#session_token ⇒ Object (readonly)
Returns the value of attribute session_token.
5 6 7 |
# File 'lib/zuora/soap/client.rb', line 5 def session_token @session_token end |
Instance Method Details
#call!(call_name, *args) ⇒ Faraday:Response
The primary interface via which users should make SOAP requests. client.call :create, object_name: :BillRun, data: … client.call :subscribe, account: …, sold_to_contact: …
54 55 56 57 58 59 |
# File 'lib/zuora/soap/client.rb', line 54 def call!(call_name, *args) factory = Zuora::Dispatcher.send call_name xml_builder = factory.new(*args).xml_builder request_data = envelope_for call_name, xml_builder request! request_data end |
#request!(body) ⇒ Zuora::Response
Fire a request
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/zuora/soap/client.rb', line 28 def request!(body) fail 'body must support .to_xml' unless body.respond_to? :to_xml raw_response = connection.post do |request| request.url SOAP_API_URI request.headers['Content-Type'] = 'text/xml' request.body = body.to_xml end # Handle rate limiting return handle_rate_limiting(body) if raw_response.status == 429 response = Zuora::Response.new(raw_response) begin response.handle_errors(response.to_h) rescue => e return handle_lock_competition(e, body) end response end |