Class: PicturePath::Response
- Inherits:
-
Object
- Object
- PicturePath::Response
- Includes:
- REXML
- Defined in:
- lib/picturepath/response.rb
Overview
The PicturePath response returned from the client
Instance Attribute Summary collapse
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#order_number ⇒ Object
Returns the value of attribute order_number.
-
#price ⇒ Object
Returns the value of attribute price.
-
#status_code ⇒ Object
Returns the value of attribute status_code.
Instance Method Summary collapse
-
#charge_applies? ⇒ Boolean
Return true if the submition charged the account money for the post.
- #error? ⇒ Boolean
-
#initialize(xml) ⇒ Response
constructor
Create a response by parsing an xml response string.
-
#parse_xml(xml) ⇒ Object
Parse the response xml to a Response object.
- #success? ⇒ Boolean
- #system_unavailable? ⇒ Boolean
- #warning? ⇒ Boolean
Constructor Details
#initialize(xml) ⇒ Response
Create a response by parsing an xml response string.
11 12 13 14 |
# File 'lib/picturepath/response.rb', line 11 def initialize(xml) @messages = [] parse_xml(xml) end |
Instance Attribute Details
#messages ⇒ Object
Returns the value of attribute messages.
8 9 10 |
# File 'lib/picturepath/response.rb', line 8 def @messages end |
#order_number ⇒ Object
Returns the value of attribute order_number.
8 9 10 |
# File 'lib/picturepath/response.rb', line 8 def order_number @order_number end |
#price ⇒ Object
Returns the value of attribute price.
8 9 10 |
# File 'lib/picturepath/response.rb', line 8 def price @price end |
#status_code ⇒ Object
Returns the value of attribute status_code.
8 9 10 |
# File 'lib/picturepath/response.rb', line 8 def status_code @status_code end |
Instance Method Details
#charge_applies? ⇒ Boolean
Return true if the submition charged the account money for the post.
33 34 35 |
# File 'lib/picturepath/response.rb', line 33 def charge_applies? return price != null && price > 0 end |
#error? ⇒ Boolean
24 25 26 |
# File 'lib/picturepath/response.rb', line 24 def error? return !success? && !warning? end |
#parse_xml(xml) ⇒ Object
Parse the response xml to a Response object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/picturepath/response.rb', line 38 def parse_xml(xml) doc = Document.new(xml) order_number_node = XPath.first(doc, '//ORDER_NUMBER') @order_number = (order_number_node && order_number_node[0]) # which message do we use for the status_code?? XPath.each(doc, '//MESSAGE') do || code = .attributes['CODE'].to_i description = .attributes['DESCRIPTION'] text = .text @messages.push :code => code, :description => description, :text => text if code >= 4000 && @order_number == nil && text =~ /Please use edit \(order number \w+\)/ @order_number = /order number (\w+)/.match(text.to_s)[1] end end if @messages.size > 0 @status_code = @messages[0][:code] end @price = 0 XPath.each(doc, '//PRODUCT') do || @price += .attributes['PRICE'].to_f end end |
#success? ⇒ Boolean
16 17 18 |
# File 'lib/picturepath/response.rb', line 16 def success? return status_code >= 0 && status_code <= 3 end |
#system_unavailable? ⇒ Boolean
28 29 30 |
# File 'lib/picturepath/response.rb', line 28 def system_unavailable? return status_code == 1000 end |
#warning? ⇒ Boolean
20 21 22 |
# File 'lib/picturepath/response.rb', line 20 def warning? return status_code >= 100 && status_code <= 200 end |