Class: ActiveZuora::Connection
- Inherits:
-
Object
- Object
- ActiveZuora::Connection
- Defined in:
- lib/active_zuora/connection.rb
Constant Summary collapse
- WSDL =
File.('../../../wsdl/zuora.wsdl', __FILE__)
Instance Attribute Summary collapse
-
#custom_header ⇒ Object
Returns the value of attribute custom_header.
-
#soap_client ⇒ Object
readonly
Returns the value of attribute soap_client.
Instance Method Summary collapse
-
#initialize(configuration = {}) ⇒ Connection
constructor
A new instance of Connection.
- #login ⇒ Object
- #request(*args, &block) ⇒ Object
Constructor Details
#initialize(configuration = {}) ⇒ Connection
Returns a new instance of Connection.
9 10 11 12 13 14 15 16 17 |
# File 'lib/active_zuora/connection.rb', line 9 def initialize(configuration={}) # Store login credentials and create SOAP client. @username = configuration[:username] @password = configuration[:password] @soap_client = Savon::Client.new do wsdl.document = configuration[:wsdl] || WSDL http.proxy = configuration[:http_proxy] if configuration[:http_proxy] end end |
Instance Attribute Details
#custom_header ⇒ Object
Returns the value of attribute custom_header.
5 6 7 |
# File 'lib/active_zuora/connection.rb', line 5 def custom_header @custom_header end |
#soap_client ⇒ Object (readonly)
Returns the value of attribute soap_client.
4 5 6 |
# File 'lib/active_zuora/connection.rb', line 4 def soap_client @soap_client end |
Instance Method Details
#login ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/active_zuora/connection.rb', line 19 def login # Returns a session_id upon success, raises an exception on failure. # Instance variables aren't available within the soap request block. body = { :username => @username, :password => @password } header = @custom_header @soap_client.request(:login) do soap.body = body soap.header = header end[:login_response][:result][:session] end |
#request(*args, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/active_zuora/connection.rb', line 30 def request(*args, &block) # instance variables aren't available within the soap request block for some reason. header = { 'SessionHeader' => { 'session' => @session_id } } header.merge!(@custom_header) if @custom_header @soap_client.request(*args) do soap.header = header yield(soap) end rescue Savon::SOAP::Fault => exception # Catch invalid sessions, and re-issue the request. raise unless exception. =~ /INVALID_SESSION/ @session_id = login request(*args, &block) end |