Sha256: fce6ea8dbda3186462f627af66e1f11aed408620f184bb91a88789dc311f27d9

Contents?: true

Size: 813 Bytes

Versions: 1

Compression:

Stored size: 813 Bytes

Contents

module MWS
  module API

    class Response < Hashie::Rash
      
      def self.parse(hash, name, params)
        rash = self.new(hash)
        handle_error_response(rash["error_response"]["error"]) unless rash["error_response"].nil?
        raise BadResponseError, "received non-matching response type #{rash.keys}" if rash["#{name}_response"].nil?
        rash = rash["#{name}_response"]

        if rash = rash["#{name}_result"]
          # only runs mods if correct result is present
          params[:mods].each {|mod| mod.call(rash) } if params[:mods]
          rash
        end
      end

      def self.handle_error_response(error)
        msg = "#{error.code}: #{error.message}"
        msg << " -- #{error.detail}" unless error.detail.nil?
        raise ErrorResponse, msg
      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-mws-0.0.4 lib/ruby-mws/api/response.rb