Class: Carousel::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_response, type) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
# File 'lib/carousel/response.rb', line 6

def initialize(raw_response, type)
  @raw_response = raw_response
  @response     = parse_response(raw_response)
  @type         = type
end

Instance Attribute Details

#raw_responseObject

Returns the value of attribute raw_response.



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

def raw_response
  @raw_response
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#failure?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/carousel/response.rb', line 12

def failure?
  !success?
end

#messageObject



28
29
30
# File 'lib/carousel/response.rb', line 28

def message
  @response["order"][0]["details"][0]
end

#parse_response(xml_response) ⇒ Object



32
33
34
35
36
37
# File 'lib/carousel/response.rb', line 32

def parse_response(xml_response)
  return nil if xml_response.nil?
  parsed = XmlSimple.xml_in(xml_response)
  @kind  = parsed.first[0]
  parsed
end

#statusObject



20
21
22
23
24
25
26
# File 'lib/carousel/response.rb', line 20

def status
  if @kind == "stock"
    @response.first["status"]
  else
    @response[@kind][0]["status"][0]
  end
end

#success?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/carousel/response.rb', line 16

def success?
  status == "OK"
end