Sha256: 29b38ee3c317dbe838577d9cb3ae7547181453a3d70c2700631401dc64858d52

Contents?: true

Size: 697 Bytes

Versions: 2

Compression:

Stored size: 697 Bytes

Contents

module Shipcloud
  module Request
    class Validator
      attr_reader :info
      attr_accessor :response

      def initialize(info)
        @info = info
      end

      def validated_data_for(incoming_response)
        self.response = incoming_response
        verify_response_code
        info.data = JSON.parse(response.body)
        validate_response_data
        info.data
      end

      protected

      def verify_response_code
        raise AuthenticationError if response.code.to_i == 401
        raise APIError if response.code.to_i >= 500
      end

      def validate_response_data
        raise APIError.new(info.data["error"]) if info.data["error"]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shipcloud-0.2.0 lib/shipcloud/request/validator.rb
shipcloud-0.1.0 lib/shipcloud/request/validator.rb