Class: ASPSMS::Response
- Inherits:
-
Object
- Object
- ASPSMS::Response
- Defined in:
- lib/aspsms.rb
Overview
Represents a response to a request of any type. Handles parsing of the response XML document and provides easy access to data fields therein.
Class Method Summary collapse
Instance Method Summary collapse
- #authorized? ⇒ Boolean
- #credits ⇒ Object
- #credits_used ⇒ Object
- #errdesc ⇒ Object
- #errno ⇒ Object
-
#initialize(cfg, args) ⇒ Response
constructor
A new instance of Response.
-
#success? ⇒ Boolean
1 Ok 30 Originator not Authorized 31 Originator already Authorized.
- #to_s ⇒ Object
Constructor Details
#initialize(cfg, args) ⇒ Response
Returns a new instance of Response.
290 291 292 293 |
# File 'lib/aspsms.rb', line 290 def initialize(cfg, args) @cfg = cfg @args = args end |
Class Method Details
.parse(cfg, xmlstr) ⇒ Object
279 280 281 282 283 284 285 286 287 288 |
# File 'lib/aspsms.rb', line 279 def self.parse(cfg, xmlstr) args = {} doc = REXML::Document.new(xmlstr) doc.root.each_element('*') do |element| args[element.name] = element.text.chomp end raise "'ErrorCode' missing!" if args['ErrorCode'].nil? raise "'ErrorDescription' missing!" if args['ErrorDescription'].nil? Response.new(cfg, args) end |
Instance Method Details
#authorized? ⇒ Boolean
301 302 303 |
# File 'lib/aspsms.rb', line 301 def errno == '31' end |
#credits ⇒ Object
313 314 315 |
# File 'lib/aspsms.rb', line 313 def credits @args['Credits'] end |
#credits_used ⇒ Object
317 318 319 |
# File 'lib/aspsms.rb', line 317 def credits_used @args['CreditsUsed'] end |
#errdesc ⇒ Object
309 310 311 |
# File 'lib/aspsms.rb', line 309 def errdesc @args['ErrorDescription'] end |
#errno ⇒ Object
305 306 307 |
# File 'lib/aspsms.rb', line 305 def errno @args['ErrorCode'] end |
#success? ⇒ Boolean
1 Ok 30 Originator not Authorized 31 Originator already Authorized
297 298 299 |
# File 'lib/aspsms.rb', line 297 def success? ['1', '30', '31'].include?(errno) end |
#to_s ⇒ Object
321 322 323 |
# File 'lib/aspsms.rb', line 321 def to_s "#{@args['ErrorCode']}: #{@args['ErrorDescription']} #{@args.inspect}" end |