1#![allow(non_camel_case_types)]
5pub mod model;
6pub mod request_model;
7use crate::model::*;
8
9pub struct BlendClient {
10 pub(crate) client: httpclient::Client,
11 authentication: Option<BlendAuthentication>,
12}
13impl BlendClient {}
14impl BlendClient {
15 pub fn new(url: &str) -> Self {
16 let client = httpclient::Client::new(Some(url.to_string()));
17 let authentication = None;
18 Self { client, authentication }
19 }
20 pub fn with_authentication(mut self, authentication: BlendAuthentication) -> Self {
21 self.authentication = Some(authentication);
22 self
23 }
24 pub fn authenticate<'a>(
25 &self,
26 mut r: httpclient::RequestBuilder<'a>,
27 ) -> httpclient::RequestBuilder<'a> {
28 if let Some(ref authentication) = self.authentication {
29 match authentication {
30 BlendAuthentication::BasicAuth { basic_auth, target_instance } => {
31 r = r.basic_auth(basic_auth);
32 r = r.header("blend-target-instance", target_instance);
33 }
34 BlendAuthentication::BearerAuth { bearer_auth, target_instance } => {
35 r = r.bearer_auth(bearer_auth);
36 r = r.header("blend-target-instance", target_instance);
37 }
38 }
39 }
40 r
41 }
42 pub fn with_middleware<M: httpclient::Middleware + 'static>(
43 mut self,
44 middleware: M,
45 ) -> Self {
46 self.client = self.client.with_middleware(middleware);
47 self
48 }
49 pub fn get_current_user(&self) -> request_model::GetCurrentUserRequest {
51 request_model::GetCurrentUserRequest {
52 client: &self,
53 }
54 }
55}
56pub enum BlendAuthentication {
57 BasicAuth { basic_auth: String, target_instance: String },
58 BearerAuth { bearer_auth: String, target_instance: String },
59}
60impl BlendAuthentication {
61 pub fn from_env() -> Self {
62 Self::BasicAuth {
63 basic_auth: std::env::var("BLEND_BASIC_AUTH")
64 .expect("Environment variable BLEND_BASIC_AUTH is not set."),
65 target_instance: std::env::var("BLEND_TARGET_INSTANCE")
66 .expect("Environment variable BLEND_TARGET_INSTANCE is not set."),
67 }
68 }
69}