Class: Quickbooks::Adapters::TestAdapter::Connection
- Defined in:
- lib/quickbooks/adapters/test_adapter.rb
Instance Method Summary collapse
- #clear_responses! ⇒ Object
- #close ⇒ Object
-
#connected? ⇒ Boolean
Returns true if there is an open connection to Quickbooks, false if not.
-
#connection ⇒ Object
Returns the active connection to Quickbooks, or creates a new one if none exists.
-
#initialize(*args) ⇒ Connection
constructor
A new instance of Connection.
- #latest_qbxml_version ⇒ Object
- #next_response(value, &block) ⇒ Object
-
#qbxml_versions ⇒ Object
We can support any version!.
-
#send_xml(xml) ⇒ Object
Sends a request to Quickbooks.
Constructor Details
#initialize(*args) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 11 |
# File 'lib/quickbooks/adapters/test_adapter.rb', line 7 def initialize(*args) @stored_responses = {} @next_value = [] @next_block = [] end |
Instance Method Details
#clear_responses! ⇒ Object
18 19 20 21 |
# File 'lib/quickbooks/adapters/test_adapter.rb', line 18 def clear_responses! @next_value = [] @next_block = [] end |
#close ⇒ Object
28 29 |
# File 'lib/quickbooks/adapters/test_adapter.rb', line 28 def close end |
#connected? ⇒ Boolean
Returns true if there is an open connection to Quickbooks, false if not. Use session? to determine an open session.
24 25 26 |
# File 'lib/quickbooks/adapters/test_adapter.rb', line 24 def connected? @connected ||= false end |
#connection ⇒ Object
Returns the active connection to Quickbooks, or creates a new one if none exists.
43 44 45 |
# File 'lib/quickbooks/adapters/test_adapter.rb', line 43 def connection @connected = true end |
#latest_qbxml_version ⇒ Object
51 52 53 |
# File 'lib/quickbooks/adapters/test_adapter.rb', line 51 def latest_qbxml_version @latest_qbxml_version ||= qbxml_versions.sort.last end |
#next_response(value, &block) ⇒ Object
13 14 15 16 |
# File 'lib/quickbooks/adapters/test_adapter.rb', line 13 def next_response(value, &block) @next_value << value @next_block << block end |
#qbxml_versions ⇒ Object
We can support any version!
48 49 50 |
# File 'lib/quickbooks/adapters/test_adapter.rb', line 48 def qbxml_versions ['1.0','1.1','2.0','2.1','3.0','4.0','4.1','5.0','6.0','7.0','8.0'] end |
#send_xml(xml) ⇒ Object
Sends a request to Quickbooks. This request should be a valid QBXML request. Use Qbxml::Request to generate valid requests.
32 33 34 35 36 37 38 39 40 |
# File 'lib/quickbooks/adapters/test_adapter.rb', line 32 def send_xml(xml) xml = xml.gsub(/ requestID=\"\d+\"/,'') @next_block[0].call(xml) if @next_block[0] cached_response = caching(xml, @next_value[0]) raise RuntimeError, "You must call next_response to set up the next response xml manually for the TestAdapter." unless cached_response @next_value.shift @next_block.shift return cached_response end |