def response_ok?(response, request)
      
      # first allow for debugging
      d {request.object_id}
      d {request}
      d {response.object_id}
      d {response.code}
      d {response.headers_hash}
      d {response.body}

      case response.code.to_i

      when 502, 503, 504
          raise AMEE::ConnectionFailed.new("A connection error occurred while talking to AMEE: HTTP response code #{response.code}.\nRequest: #{request.method.upcase} #{request.url.gsub(request.host, '')}")
      when 408
        raise AMEE::TimeOut.new("Request timed out.")
      when 404
        raise AMEE::NotFound.new("The URL was not found on the server.\nRequest: #{request.method.upcase} #{request.url.gsub(request.host, '')}")
      when 403
        raise AMEE::PermissionDenied.new("You do not have permission to perform the requested operation.\nRequest: #{request.method.upcase} #{request.url.gsub(request.host, '')}\n#{request.body}\Response: #{response.body}")
      when 401
        authenticate
        return false
      when 400
        if response.body.include? "would have resulted in a duplicate resource being created"
          raise AMEE::DuplicateResource.new("The specified resource already exists. This is most often caused by creating an item that overlaps another in time.\nRequest: #{request.method.upcase} #{request.url.gsub(request.host, '')}\n#{request.body}\Response: #{response.body}")
        else
          raise AMEE::BadRequest.new("Bad request. This is probably due to malformed input data.\nRequest: #{request.method.upcase} #{request.url.gsub(request.host, '')}\n#{request.body}\Response: #{response.body}")
        end
      when 200, 201, 204
        return response
      when 0
        connection_failed
      end
      # If we get here, something unhandled has happened, so raise an unknown error.
      raise AMEE::UnknownError.new("An error occurred while talking to AMEE: HTTP response code #{response.code}.\nRequest: #{request.method.upcase} #{request.url}\n#{request.body}\Response: #{response.body}")
    end
def response_ok?(response, request)
      
      # first allow for debugging
      d {request.object_id}
      d {request}
      d {response.object_id}
      d {response.code}
      d {response.headers_hash}
      d {response.body}

      case response.code.to_i

      when 502, 503, 504
          raise AMEE::ConnectionFailed.new("A connection error occurred while talking to AMEE: HTTP response code #{response.code}.\nRequest: #{request.method.upcase} #{request.url.gsub(request.host, '')}")
      when 408
        raise AMEE::TimeOut.new("Request timed out.")
      when 404
        raise AMEE::NotFound.new("The URL was not found on the server.\nRequest: #{request.method.upcase} #{request.url.gsub(request.host, '')}")
      when 403
        raise AMEE::PermissionDenied.new("You do not have permission to perform the requested operation.\nRequest: #{request.method.upcase} #{request.url.gsub(request.host, '')}\n#{request.body}\Response: #{response.body}")
      when 401
        authenticate
        return false
      when 400
        if response.body.include? "would have resulted in a duplicate resource being created"
          raise AMEE::DuplicateResource.new("The specified resource already exists. This is most often caused by creating an item that overlaps another in time.\nRequest: #{request.method.upcase} #{request.url.gsub(request.host, '')}\n#{request.body}\Response: #{response.body}")
        else
          raise AMEE::BadRequest.new("Bad request. This is probably due to malformed input data.\nRequest: #{request.method.upcase} #{request.url.gsub(request.host, '')}\n#{request.body}\Response: #{response.body}")
        end
      when 200, 201, 204
        return response
      when 0
        connection_failed
      end
      # If we get here, something unhandled has happened, so raise an unknown error.
      raise AMEE::UnknownError.new("An error occurred while talking to AMEE: HTTP response code #{response.code}.\nRequest: #{request.method.upcase} #{request.url}\n#{request.body}\Response: #{response.body}")
    end
run each request through some basic error checking, and
 if needed log requests