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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#![allow(non_camel_case_types)]
#![allow(unused)]
pub mod model;
pub mod request;
use crate::model::*;
pub struct BumpClient {
pub(crate) client: httpclient::Client,
authentication: Option<BumpAuthentication>,
}
impl BumpClient {
pub fn from_env() -> Self {
let url = std::env::var("BUMP_BASE_URL")
.expect("Missing environment variable BUMP_BASE_URL");
Self::new(&url)
}
}
impl BumpClient {
pub fn new(url: &str) -> Self {
let client = httpclient::Client::new(Some(url.to_string()));
let authentication = None;
Self { client, authentication }
}
pub fn with_authentication(mut self, authentication: BumpAuthentication) -> Self {
self.authentication = Some(authentication);
self
}
pub fn authenticate<'a>(
&self,
mut r: httpclient::RequestBuilder<'a>,
) -> httpclient::RequestBuilder<'a> {
if let Some(ref authentication) = self.authentication {
match authentication {
BumpAuthentication::AuthorizationToken { authorization_token } => {
r = r.token_auth(authorization_token);
}
BumpAuthentication::BasicToken { basic_token } => {
r = r.basic_auth(basic_token);
}
}
}
r
}
pub fn with_middleware<M: httpclient::Middleware + 'static>(
mut self,
middleware: M,
) -> Self {
self.client = self.client.with_middleware(middleware);
self
}
pub fn post_diffs(&self) -> request::PostDiffsRequest {
request::PostDiffsRequest {
client: &self,
url: None,
previous_url: None,
previous_definition: None,
previous_references: None,
definition: None,
references: None,
expires_at: None,
}
}
pub fn get_diffs_by_id(&self, id: &str) -> request::GetDiffsByIdRequest {
request::GetDiffsByIdRequest {
client: &self,
id: id.to_owned(),
formats: None,
}
}
pub fn get_hubs_by_hub_id_or_slug(
&self,
hub_id_or_slug: &str,
) -> request::GetHubsByHubIdOrSlugRequest {
request::GetHubsByHubIdOrSlugRequest {
client: &self,
hub_id_or_slug: hub_id_or_slug.to_owned(),
}
}
pub fn post_versions(
&self,
args: request::PostVersionsRequired,
) -> request::PostVersionsRequest {
request::PostVersionsRequest {
client: &self,
documentation: args.documentation.to_owned(),
hub: args.hub.to_owned(),
documentation_name: args.documentation_name.to_owned(),
auto_create_documentation: args.auto_create_documentation,
definition: args.definition.to_owned(),
references: args.references,
branch_name: args.branch_name.to_owned(),
previous_version_id: args.previous_version_id.to_owned(),
unpublished: args.unpublished,
}
}
pub fn post_validations(
&self,
args: request::PostValidationsRequired,
) -> request::PostValidationsRequest {
request::PostValidationsRequest {
client: &self,
documentation: args.documentation.to_owned(),
hub: args.hub.to_owned(),
documentation_name: args.documentation_name.to_owned(),
auto_create_documentation: args.auto_create_documentation,
url: args.url.to_owned(),
definition: args.definition.to_owned(),
references: args.references,
}
}
pub fn post_previews(&self, definition: &str) -> request::PostPreviewsRequest {
request::PostPreviewsRequest {
client: &self,
definition: definition.to_owned(),
references: None,
}
}
pub fn put_previews_by_preview_id(
&self,
preview_id: &str,
definition: &str,
) -> request::PutPreviewsByPreviewIdRequest {
request::PutPreviewsByPreviewIdRequest {
client: &self,
preview_id: preview_id.to_owned(),
definition: definition.to_owned(),
references: None,
}
}
pub fn get_versions_by_version_id(
&self,
version_id: &str,
) -> request::GetVersionsByVersionIdRequest {
request::GetVersionsByVersionIdRequest {
client: &self,
version_id: version_id.to_owned(),
}
}
pub fn get_ping(&self) -> request::GetPingRequest {
request::GetPingRequest {
client: &self,
}
}
}
pub enum BumpAuthentication {
AuthorizationToken { authorization_token: String },
BasicToken { basic_token: String },
}
impl BumpAuthentication {
pub fn from_env() -> Self {
Self::AuthorizationToken {
authorization_token: std::env::var("BUMP_AUTHORIZATION_TOKEN")
.expect("Environment variable BUMP_AUTHORIZATION_TOKEN is not set."),
}
}
}