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.
293 294 295 296 |
# File 'lib/aspsms.rb', line 293 def initialize(cfg, args) @cfg = cfg @args = args end |
Class Method Details
.parse(cfg, xmlstr) ⇒ Object
282 283 284 285 286 287 288 289 290 291 |
# File 'lib/aspsms.rb', line 282 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
304 305 306 |
# File 'lib/aspsms.rb', line 304 def errno == '31' end |
#credits ⇒ Object
316 317 318 |
# File 'lib/aspsms.rb', line 316 def credits @args['Credits'] end |
#credits_used ⇒ Object
320 321 322 |
# File 'lib/aspsms.rb', line 320 def credits_used @args['CreditsUsed'] end |
#errdesc ⇒ Object
312 313 314 |
# File 'lib/aspsms.rb', line 312 def errdesc @args['ErrorDescription'] end |
#errno ⇒ Object
308 309 310 |
# File 'lib/aspsms.rb', line 308 def errno @args['ErrorCode'] end |
#success? ⇒ Boolean
1 Ok 30 Originator not Authorized 31 Originator already Authorized
300 301 302 |
# File 'lib/aspsms.rb', line 300 def success? ['1', '30', '31'].include?(errno) end |
#to_s ⇒ Object
324 325 326 |
# File 'lib/aspsms.rb', line 324 def to_s "#{@args['ErrorCode']}: #{@args['ErrorDescription']} #{@args.inspect}" end |