1#![allow(non_camel_case_types)]
5#![allow(unused)]
6pub mod model;
7pub mod request;
8use crate::model::*;
9
10pub struct BumpClient {
11 pub(crate) client: httpclient::Client,
12 authentication: BumpAuthentication,
13}
14impl BumpClient {
15 pub fn from_env() -> Self {
16 let url = "https://bump.sh/api/v1".to_string();
17 Self {
18 client: httpclient::Client::new(Some(url)),
19 authentication: BumpAuthentication::from_env(),
20 }
21 }
22}
23impl BumpClient {
24 pub fn new(url: &str, authentication: BumpAuthentication) -> Self {
25 let client = httpclient::Client::new(Some(url.to_string()));
26 Self { client, authentication }
27 }
28 pub fn with_authentication(mut self, authentication: BumpAuthentication) -> Self {
29 self.authentication = authentication;
30 self
31 }
32 pub fn authenticate<'a>(
33 &self,
34 mut r: httpclient::RequestBuilder<'a>,
35 ) -> httpclient::RequestBuilder<'a> {
36 match &self.authentication {
37 BumpAuthentication::AuthorizationToken { authorization_token } => {
38 r = r.token_auth(authorization_token);
39 }
40 BumpAuthentication::BasicToken { basic_token } => {
41 r = r.basic_auth(basic_token);
42 }
43 }
44 r
45 }
46 pub fn with_middleware<M: httpclient::Middleware + 'static>(
47 mut self,
48 middleware: M,
49 ) -> Self {
50 self.client = self.client.with_middleware(middleware);
51 self
52 }
53 pub fn post_diffs(&self) -> request::PostDiffsRequest {
59 request::PostDiffsRequest {
60 client: &self,
61 url: None,
62 previous_url: None,
63 previous_definition: None,
64 previous_references: None,
65 definition: None,
66 references: None,
67 expires_at: None,
68 }
69 }
70 pub fn get_diffs_by_id(&self, id: &str) -> request::GetDiffsByIdRequest {
75 request::GetDiffsByIdRequest {
76 client: &self,
77 id: id.to_owned(),
78 formats: None,
79 }
80 }
81 pub fn get_hubs_by_hub_id_or_slug(
86 &self,
87 hub_id_or_slug: &str,
88 ) -> request::GetHubsByHubIdOrSlugRequest {
89 request::GetHubsByHubIdOrSlugRequest {
90 client: &self,
91 hub_id_or_slug: hub_id_or_slug.to_owned(),
92 }
93 }
94 pub fn post_versions(
99 &self,
100 args: request::PostVersionsRequired,
101 ) -> request::PostVersionsRequest {
102 request::PostVersionsRequest {
103 client: &self,
104 documentation: args.documentation.to_owned(),
105 hub: args.hub.to_owned(),
106 documentation_name: args.documentation_name.to_owned(),
107 auto_create_documentation: args.auto_create_documentation,
108 definition: args.definition.to_owned(),
109 references: args.references,
110 branch_name: args.branch_name.to_owned(),
111 previous_version_id: args.previous_version_id.to_owned(),
112 unpublished: args.unpublished,
113 }
114 }
115 pub fn post_validations(
120 &self,
121 args: request::PostValidationsRequired,
122 ) -> request::PostValidationsRequest {
123 request::PostValidationsRequest {
124 client: &self,
125 documentation: args.documentation.to_owned(),
126 hub: args.hub.to_owned(),
127 documentation_name: args.documentation_name.to_owned(),
128 auto_create_documentation: args.auto_create_documentation,
129 url: args.url.to_owned(),
130 definition: args.definition.to_owned(),
131 references: args.references,
132 }
133 }
134 pub fn post_previews(&self, definition: &str) -> request::PostPreviewsRequest {
139 request::PostPreviewsRequest {
140 client: &self,
141 definition: definition.to_owned(),
142 references: None,
143 }
144 }
145 pub fn put_previews_by_preview_id(
150 &self,
151 preview_id: &str,
152 definition: &str,
153 ) -> request::PutPreviewsByPreviewIdRequest {
154 request::PutPreviewsByPreviewIdRequest {
155 client: &self,
156 preview_id: preview_id.to_owned(),
157 definition: definition.to_owned(),
158 references: None,
159 }
160 }
161 pub fn get_versions_by_version_id(
166 &self,
167 version_id: &str,
168 ) -> request::GetVersionsByVersionIdRequest {
169 request::GetVersionsByVersionIdRequest {
170 client: &self,
171 version_id: version_id.to_owned(),
172 }
173 }
174 pub fn get_ping(&self) -> request::GetPingRequest {
178 request::GetPingRequest {
179 client: &self,
180 }
181 }
182}
183pub enum BumpAuthentication {
184 AuthorizationToken { authorization_token: String },
185 BasicToken { basic_token: String },
186}
187impl BumpAuthentication {
188 pub fn from_env() -> Self {
189 Self::AuthorizationToken {
190 authorization_token: std::env::var("BUMP_AUTHORIZATION_TOKEN")
191 .expect("Environment variable BUMP_AUTHORIZATION_TOKEN is not set."),
192 }
193 }
194}