Class: Silverpop::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



7
8
9
# File 'lib/silverpop/response.rb', line 7

def initialize(response)
  self.parse(response)
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



5
6
7
# File 'lib/silverpop/response.rb', line 5

def body
  @body
end

#errorsObject

Returns the value of attribute errors.



5
6
7
# File 'lib/silverpop/response.rb', line 5

def errors
  @errors
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/silverpop/response.rb', line 5

def response
  @response
end

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/silverpop/response.rb', line 5

def status
  @status
end

Instance Method Details

#inspectObject



24
25
26
# File 'lib/silverpop/response.rb', line 24

def inspect
  "#<Silverpop::Response status:#{self.status} response=#{self.response.inspect}>"
end

#parse(response) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/silverpop/response.rb', line 11

def parse(response)
  Silverpop.logger.debug "*** RESPONSE:\n#{response}\n"
  self.body = REXML::Document.new(response)
  self.response = {
    :status => self.body.root.elements['STATUS'][0].value,
    :error_code => (self.body.root.elements['ERROR_CODE'][0].value rescue nil),
    :error_string => (self.body.root.elements['ERROR_STRING'][0].value rescue nil)
  }
  self.status = self.response[:status].to_i
  self.errors ||= []
  self.errors << {:code => self.response[:error_code], :message => self.response[:error_string]}
end