Property definitions

neo4j $ JsonCurlRequest :: defaultinit
# An abstract request that defines most of the standard options for Neo4j REST API
abstract class JsonCurlRequest
	super CurlHTTPRequest

	# OAuth token
	var auth: nullable String is writable

	# init HTTP headers for Neo4j REST API
	protected fun init_headers do
		headers = new HeaderMap
		headers["Accept"] = "application/json; charset=UTF-8"
		headers["Transfer-Encoding"] = "chunked"
		headers["X-Stream"] = "true"
		if auth != null then
			headers["Authorization"] = "token {auth.to_s}"
		end

		# User agent (is used by github to contact devs in case of problems)
		if user_agent != null then
			headers["User-Agent"] = user_agent.to_s
		end
	end

	redef fun execute do
		init_headers

		if not self.curl.is_ok then
			return answer_failure(0, "Curl instance is not correctly initialized")
		end

		var success_response = new CurlResponseSuccess
		var callback_receiver: CurlCallbacks = success_response
		if self.delegate != null then callback_receiver = self.delegate.as(not null)

		var err = self.curl.native.easy_setopt(new CURLOption.follow_location, 1)
		if not err.is_ok then return answer_failure(err.to_i, err.to_s)

		err = self.curl.native.easy_setopt(new CURLOption.http_version, 1)
		if not err.is_ok then return answer_failure(err.to_i, err.to_s)

		err = self.curl.native.easy_setopt(new CURLOption.url, url)
		if not err.is_ok then return answer_failure(err.to_i, err.to_s)

		err = self.curl.native.register_callback_header(callback_receiver)
		if not err.is_ok then return answer_failure(err.to_i, err.to_s)

		err = self.curl.native.register_callback_body(callback_receiver)
		if not err.is_ok then return answer_failure(err.to_i, err.to_s)

		# HTTP Header
		if self.headers != null then
			var headers_joined = self.headers.join_pairs(": ")
			err = self.curl.native.easy_setopt(
				new CURLOption.httpheader, headers_joined.to_curlslist)
			if not err.is_ok then return answer_failure(err.to_i, err.to_s)
		end

		var err_hook = execute_hook
		if err_hook != null then return err_hook

		var err_resp = perform
		if err_resp != null then return err_resp

		var st_code = self.curl.native.easy_getinfo_long(new CURLInfoLong.response_code)
		if not st_code == null then success_response.status_code = st_code

		return success_response
	end

	# Hook to implement in concrete requests
	protected fun execute_hook: nullable CurlResponse do return null
end
lib/neo4j/curl_json.nit:22,1--93,3