Class: ASPSMS::Response

Inherits:
Object
  • Object
show all
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

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

Returns:

  • (Boolean)


304
305
306
# File 'lib/aspsms.rb', line 304

def authorized?
  errno == '31'
end

#creditsObject



316
317
318
# File 'lib/aspsms.rb', line 316

def credits
  @args['Credits']
end

#credits_usedObject



320
321
322
# File 'lib/aspsms.rb', line 320

def credits_used
  @args['CreditsUsed']
end

#errdescObject



312
313
314
# File 'lib/aspsms.rb', line 312

def errdesc
  @args['ErrorDescription']
end

#errnoObject



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

Returns:

  • (Boolean)


300
301
302
# File 'lib/aspsms.rb', line 300

def success?
  ['1', '30', '31'].include?(errno)
end

#to_sObject



324
325
326
# File 'lib/aspsms.rb', line 324

def to_s
  "#{@args['ErrorCode']}: #{@args['ErrorDescription']} #{@args.inspect}"
end