Sha256: a69f72ed4d19a72257939cc82e32e09e8108a0bc0c304bc47047f5a2964afd8d

Contents?: true

Size: 725 Bytes

Versions: 4

Compression:

Stored size: 725 Bytes

Contents

module Carousel
  class Response

    attr_accessor :response, :raw_response

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

    def failure?
      !success?
    end

    def success?
      status == "OK"
    end

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

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

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

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
carousel-ruby-api-0.0.6 lib/carousel/response.rb
carousel-ruby-api-0.0.5 lib/carousel/response.rb
carousel-ruby-api-0.0.4 lib/carousel/response.rb
carousel-ruby-api-0.0.3 lib/carousel/response.rb