Class: SMSBox::XMLResponse
- Inherits:
-
Object
- Object
- SMSBox::XMLResponse
- Defined in:
- lib/sms_box/xml_response.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#command_data ⇒ Object
Returns the value of attribute command_data.
-
#error ⇒ Object
Returns the value of attribute error.
-
#request ⇒ Object
Returns the value of attribute request.
-
#requestUid ⇒ Object
Returns the value of attribute requestUid.
Class Method Summary collapse
Instance Method Summary collapse
- #error? ⇒ Boolean
-
#initialize ⇒ XMLResponse
constructor
A new instance of XMLResponse.
- #success? ⇒ Boolean
Constructor Details
#initialize ⇒ XMLResponse
Returns a new instance of XMLResponse.
21 22 23 24 25 |
# File 'lib/sms_box/xml_response.rb', line 21 def initialize if self.instance_of? XMLResponse raise 'XMLResponse needs to be subclassed' end end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
8 9 10 |
# File 'lib/sms_box/xml_response.rb', line 8 def command @command end |
#command_data ⇒ Object
Returns the value of attribute command_data.
11 12 13 |
# File 'lib/sms_box/xml_response.rb', line 11 def command_data @command_data end |
#error ⇒ Object
Returns the value of attribute error.
10 11 12 |
# File 'lib/sms_box/xml_response.rb', line 10 def error @error end |
#request ⇒ Object
Returns the value of attribute request.
7 8 9 |
# File 'lib/sms_box/xml_response.rb', line 7 def request @request end |
#requestUid ⇒ Object
Returns the value of attribute requestUid.
9 10 11 |
# File 'lib/sms_box/xml_response.rb', line 9 def requestUid @requestUid end |
Class Method Details
.from_xml(xml_string) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sms_box/xml_response.rb', line 27 def self.from_xml(xml_string) doc = Nokogiri::XML(xml_string) command = doc.xpath('//SMSBoxXMLReply/command') command_name = command.attr('name').text res = instantize(command_name) res.command = command_name res.command_data = command res.requestUid = doc.xpath('//SMSBoxXMLReply/requestUid').first.text error = doc.xpath('//SMSBoxXMLReply/error') unless error.empty? res.error = error.attr('type').text end res end |
.instantize(command) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sms_box/xml_response.rb', line 42 def self.instantize(command) klass = nil begin class_name = "SMSBox::#{command.downcase.camelize}Response" klass = class_name.camelize.constantize rescue NameError => e raise NotImplementedError.new("'#{command}' not implemented") rescue Exception => e raise "'#{command}' could not be instantiated" end unless klass < XMLResponse raise "'#{command}' not a SMSBox::XMLResponse" end klass.new end |
Instance Method Details
#error? ⇒ Boolean
13 14 15 |
# File 'lib/sms_box/xml_response.rb', line 13 def error? error.present? end |
#success? ⇒ Boolean
17 18 19 |
# File 'lib/sms_box/xml_response.rb', line 17 def success? not error? end |