Class: Xeroizer::Response
- Inherits:
-
Object
- Object
- Xeroizer::Response
- Defined in:
- lib/xeroizer/response.rb
Instance Attribute Summary collapse
-
#date_time ⇒ Object
Returns the value of attribute date_time.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#id ⇒ Object
Returns the value of attribute id.
-
#provider ⇒ Object
Returns the value of attribute provider.
-
#request_params ⇒ Object
Returns the value of attribute request_params.
-
#request_xml ⇒ Object
Returns the value of attribute request_xml.
-
#response_items ⇒ Object
Returns the value of attribute response_items.
-
#response_xml ⇒ Object
Returns the value of attribute response_xml.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
-
.parse(raw_response, request = {}, options = {}, &block) ⇒ Object
Parse the response retreived during any request.
Instance Method Summary collapse
- #error ⇒ Object
-
#initialize ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
Constructor Details
#initialize ⇒ Response
Returns a new instance of Response.
56 57 58 |
# File 'lib/xeroizer/response.rb', line 56 def initialize @response_items = [] end |
Instance Attribute Details
#date_time ⇒ Object
Returns the value of attribute date_time.
18 19 20 |
# File 'lib/xeroizer/response.rb', line 18 def date_time @date_time end |
#errors ⇒ Object
Returns the value of attribute errors.
18 19 20 |
# File 'lib/xeroizer/response.rb', line 18 def errors @errors end |
#id ⇒ Object
Returns the value of attribute id.
18 19 20 |
# File 'lib/xeroizer/response.rb', line 18 def id @id end |
#provider ⇒ Object
Returns the value of attribute provider.
18 19 20 |
# File 'lib/xeroizer/response.rb', line 18 def provider @provider end |
#request_params ⇒ Object
Returns the value of attribute request_params.
18 19 20 |
# File 'lib/xeroizer/response.rb', line 18 def request_params @request_params end |
#request_xml ⇒ Object
Returns the value of attribute request_xml.
18 19 20 |
# File 'lib/xeroizer/response.rb', line 18 def request_xml @request_xml end |
#response_items ⇒ Object
Returns the value of attribute response_items.
18 19 20 |
# File 'lib/xeroizer/response.rb', line 18 def response_items @response_items end |
#response_xml ⇒ Object
Returns the value of attribute response_xml.
18 19 20 |
# File 'lib/xeroizer/response.rb', line 18 def response_xml @response_xml end |
#status ⇒ Object
Returns the value of attribute status.
18 19 20 |
# File 'lib/xeroizer/response.rb', line 18 def status @status end |
Class Method Details
.parse(raw_response, request = {}, options = {}, &block) ⇒ Object
Parse the response retreived during any request.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/xeroizer/response.rb', line 23 def parse(raw_response, request = {}, = {}, &block) response = Xeroizer::Response.new response.response_xml = raw_response doc = Nokogiri::XML(raw_response) { | cfg | cfg.noblanks } # check for responses we don't understand raise Xeroizer::UnparseableResponse.new(doc.root.name) unless doc.root.name == 'Response' doc.root.elements.each do | element | # Text element if element.children && element.children.size == 1 && element.children.first.text? case element.name when 'Id' then response.id = element.text when 'Status' then response.status = element.text when 'ProviderName' then response.provider = element.text when 'DateTimeUTC' then response.date_time = Time.parse(element.text) end # Records in response elsif element.children && element.children.size > 0 yield(response, element.children, element.children.first.name) end end response end |
Instance Method Details
#error ⇒ Object
64 65 66 |
# File 'lib/xeroizer/response.rb', line 64 def error errors.blank? ? nil : errors[0] end |
#success? ⇒ Boolean
60 61 62 |
# File 'lib/xeroizer/response.rb', line 60 def success? status == 'OK' end |