Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix up Qbxml::Response a bit

  • Loading branch information...
commit 55eab526eb661827b418608fe66dd6dd2a7099bf 1 parent cc284c9
Xavier Shay xaviershay authored Daniel Parker committed
Showing with 8 additions and 5 deletions.
  1. +8 −5 lib/qbxml/response.rb
13 lib/qbxml/response.rb
View
@@ -10,7 +10,7 @@ def set
end
@set
end
- delegate_methods [:each, :length, :first, :last, :[], :map, :join] => :set
+ delegate_methods [:collect, :each, :each_with_index, :length, :first, :last, :[], :map, :join] => :set
def <<(qbxml_response)
if qbxml_response.is_a?(Qbxml::Response)
set << qbxml_response
@@ -36,6 +36,7 @@ def initialize(xml_or_hash)
def append_from_xml(xml)
self.append_from_hash(xml.formatted(:xml).to_hash)
end
+
def append_from_hash(hsh)
to_append = []
hsh = hsh['QBXML'] if hsh.has_key?('QBXML')
@@ -51,10 +52,10 @@ def append_from_hash(hsh)
class << self
def from_xml(xml)
- new.append_from_xml(xml)
+ new(xml)
end
def from_hash(hsh)
- new.append_from_hash(hsh)
+ new(hsh)
end
end
end
@@ -79,6 +80,8 @@ def import_from_xml(xml)
end
def import_from_hash(hsh)
raise ArgumentError, "Hash passed to Qbxml::Response.from_hash must contain only one top-level key" unless hsh.keys.length == 1
+ hsh = hsh['QBXML'] if hsh.has_key?('QBXML')
+ hsh = hsh['QBXMLMsgsRs'] if hsh.has_key?('QBXMLMsgsRs')
name = hsh.keys.first
self.raw_response = hsh # (for development purposes)
hsh = hsh[name]
@@ -118,10 +121,10 @@ def import_from_hash(hsh)
class << self
def from_xml(xml)
- new.import_from_xml(xml)
+ new(xml)
end
def from_hash(hsh)
- new.import_from_hash(hsh)
+ new(hsh)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.