blob: 0682566f7dfe5961244fdd05a11693a054b417ed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
use crate::endpoint::EndpointUrl;
use crate::v1::error::Result;
use crate::v1::error::RepologyError;
use crate::v1::api::ProjectRequestBuilder;
use crate::v1::api::ProblemsRequestBuilder;
static APP_USER_AGENT: &str = concat!(
env!("CARGO_PKG_NAME"),
"/",
env!("CARGO_PKG_VERSION"),
);
#[derive(Debug)]
pub struct ApiClient {
pub(super) endpoint_url: &'static str,
pub(super) client: reqwest::Client,
}
impl ApiClient {
pub fn new<EP: EndpointUrl>() -> Result<Self> {
reqwest::Client::builder()
.user_agent(APP_USER_AGENT)
.build()
.map_err(RepologyError::from)
.map(|client| ApiClient {
endpoint_url: EP::endpoint_url(),
client,
})
}
pub fn client(&self) -> &reqwest::Client {
&self.client
}
pub fn client_mut(&mut self) -> &reqwest::Client {
&mut self.client
}
pub fn projects<'a>(&'a self) -> ProjectRequestBuilder<'a> {
ProjectRequestBuilder(self)
}
pub fn problems<'a>(&'a self) -> ProblemsRequestBuilder<'a> {
ProblemsRequestBuilder(self)
}
}
|