git-gemini-forge 0.6.2

A simple Gemini server that serves a read-only view of public repositories from a Git forge.
use super::GitLabApi;
use super::converters::GitLabUser;
use crate::network::ForgeApi;
use crate::network::error;
use crate::network::net::{ApiEndpoint, Net};
use url::Url;

struct UserEndpoint<'a> {
	api: &'a GitLabApi,
	base_url: Url,
}

impl ApiEndpoint<GitLabApi, GitLabUser> for UserEndpoint<'_> {
	fn api(&self) -> &GitLabApi {
		self.api
	}

	fn url(&self) -> Url {
		self.base_url.join("user").expect("Valid URL path")
	}
}

/// Retrieves the authenticated user from the given API.
pub fn get_authed_user(api: &GitLabApi, net: &Net) -> Result<GitLabUser, error::Error> {
	let base_url = api.base_url().clone();
	let endpoint = UserEndpoint { api, base_url };

	// Should fail if our API key isn't valid:
	net.call(&endpoint)
}