Class: Mozenda::Response::Base

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Base

Returns a new instance of Base.



6
7
8
9
# File 'lib/mozenda/response/base.rb', line 6

def initialize http_response
  @response = http_response
  @xml = @response.body
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



4
5
6
# File 'lib/mozenda/response/base.rb', line 4

def response
  @response
end

Instance Method Details

#nameObject



29
30
31
# File 'lib/mozenda/response/base.rb', line 29

def name
  self.class.const_get(:NAME)
end

#success?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/mozenda/response/base.rb', line 15

def success?
  return false unless valid?
  result = body_hash["Result"] || ""
  result.downcase == "success"
end

#to_hObject



25
26
27
# File 'lib/mozenda/response/base.rb', line 25

def to_h
  @hash ||= ::Nori.new.parse(@xml)
end

#to_xmlObject



21
22
23
# File 'lib/mozenda/response/base.rb', line 21

def to_xml
  @xml
end

#valid?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/mozenda/response/base.rb', line 11

def valid?
  !body_hash.nil?
end