paper_mc/
lib.rs

1//! [`PaperMcClient`](struct.PaperMcClient.html) is the main entry point for this library.
2//!
3//! Library created with [`libninja`](https://www.libninja.com).
4#![allow(non_camel_case_types)]
5#![allow(unused)]
6pub mod model;
7pub mod request;
8use crate::model::*;
9
10pub struct PaperMcClient {
11    pub(crate) client: httpclient::Client,
12}
13impl PaperMcClient {
14    pub fn from_env() -> Self {
15        let url = std::env::var("PAPER_MC_BASE_URL")
16            .expect("Missing environment variable PAPER_MC_BASE_URL");
17        Self::new(&url)
18    }
19}
20impl PaperMcClient {
21    pub fn new(url: &str) -> Self {
22        let client = httpclient::Client::new(Some(url.to_string()));
23        PaperMcClient { client }
24    }
25    pub fn with_middleware<M: httpclient::Middleware + 'static>(
26        mut self,
27        middleware: M,
28    ) -> Self {
29        self.client = self.client.with_middleware(middleware);
30        self
31    }
32    ///Gets a list of all available projects.
33    pub fn projects(&self) -> request::ProjectsRequest {
34        request::ProjectsRequest {
35            client: &self,
36        }
37    }
38    ///Gets information about a project.
39    pub fn project(&self, project: &str) -> request::ProjectRequest {
40        request::ProjectRequest {
41            client: &self,
42            project: project.to_owned(),
43        }
44    }
45    ///Gets information about a version.
46    pub fn version(&self, project: &str, version: &str) -> request::VersionRequest {
47        request::VersionRequest {
48            client: &self,
49            project: project.to_owned(),
50            version: version.to_owned(),
51        }
52    }
53    ///Gets all available builds for a project's version.
54    pub fn builds(&self, project: &str, version: &str) -> request::BuildsRequest {
55        request::BuildsRequest {
56            client: &self,
57            project: project.to_owned(),
58            version: version.to_owned(),
59        }
60    }
61    ///Gets information related to a specific build.
62    pub fn build(
63        &self,
64        project: &str,
65        version: &str,
66        build: i64,
67    ) -> request::BuildRequest {
68        request::BuildRequest {
69            client: &self,
70            project: project.to_owned(),
71            version: version.to_owned(),
72            build,
73        }
74    }
75    ///Downloads the given file from a build's data.
76    pub fn download(&self, args: request::DownloadRequired) -> request::DownloadRequest {
77        request::DownloadRequest {
78            client: &self,
79            project: args.project.to_owned(),
80            version: args.version.to_owned(),
81            build: args.build,
82            download: args.download.to_owned(),
83        }
84    }
85    ///Gets information about a project's version group.
86    pub fn family(&self, project: &str, family: &str) -> request::FamilyRequest {
87        request::FamilyRequest {
88            client: &self,
89            project: project.to_owned(),
90            family: family.to_owned(),
91        }
92    }
93    ///Gets all available builds for a project's version group.
94    pub fn family_builds(
95        &self,
96        project: &str,
97        family: &str,
98    ) -> request::FamilyBuildsRequest {
99        request::FamilyBuildsRequest {
100            client: &self,
101            project: project.to_owned(),
102            family: family.to_owned(),
103        }
104    }
105}