Send a HTTPRequest to the Github API

Property definitions

github $ GithubAPI :: send
	# Send a HTTPRequest to the Github API
	fun send(method, path: String, headers: nullable HeaderMap, body: nullable String): nullable String do
		last_error = null
		path = sanitize_uri(path)
		var uri = "{api_url}{path}"
		var request = new CurlHTTPRequest(uri)
		request.method = method
		request.user_agent = user_agent
		request.headers = headers or else self.new_headers
		request.body = body
		return check_response(uri, request.execute)
	end
lib/github/api.nit:94,2--105,4

github $ MockGithubAPI :: send
	# Mock so it returns the response from a file
	#
	# See `update_responses_cache`.
	redef fun send(method, path, headers, body) do
		print path # for debugging

		assert has_response(path)

		if update_responses_cache then
			var file = response_file(path)
			save_actual_response(path, file)
		end

		var response = response_string(path)
		if response_is_error(path) then
			last_error = new GithubAPIError(
				response.parse_json.as(JsonObject)["message"].as(String),
				response_code(path).to_i,
				path
			)
			was_error = true
			return null
		end
		return response
	end
lib/github/tests/test_api.nit:29,2--53,4