Class: PennySMSMuncher::PennySMS::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/penny_sms.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Response

Returns a new instance of Response.



42
43
44
45
46
47
# File 'lib/penny_sms.rb', line 42

def initialize(raw)
  self.raw = raw
  self.data = XML::Parser.string(raw.body).parse # JSON?
  self.set_status
  self
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



40
41
42
# File 'lib/penny_sms.rb', line 40

def data
  @data
end

#rawObject

Returns the value of attribute raw.



40
41
42
# File 'lib/penny_sms.rb', line 40

def raw
  @raw
end

#statusObject

Returns the value of attribute status.



40
41
42
# File 'lib/penny_sms.rb', line 40

def status
  @status
end

Instance Method Details

#faultObject



69
70
71
72
# File 'lib/penny_sms.rb', line 69

def fault
  return unless data && !data.find('//fault').empty?
  data.find('//fault//member')[0]
end

#fault_codeObject



61
62
63
# File 'lib/penny_sms.rb', line 61

def fault_code
  fault.find('//i4').first.content if fault
end

#fault_nameObject



65
66
67
# File 'lib/penny_sms.rb', line 65

def fault_name
  fault.find('//string').first.content if fault
end

#set_statusObject



53
54
55
56
57
58
59
# File 'lib/penny_sms.rb', line 53

def set_status
  if fault
    self.status = 'error'
  else
    self.status = data.find('//params//string').first.content
  end
end

#success?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/penny_sms.rb', line 49

def success?
  !fault_code
end