bump_api/
lib.rs

1//! [`BumpClient`](struct.BumpClient.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 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    /**Create a diff
54
55Create a diff between any two given API definitions.
56The diff result will be available asynchronously and needs to be retrieved with the [`GET /diffs/:id` API endpoint](#operation-get-diffs-parameter).
57*/
58    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    /**Fetch detailed information from an existing diff
71
72Fetch the result of a previously created diff with the [`POST /diffs` API endpoint](#operation-post-diffs).
73*/
74    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    /**Fetch information of an existing Hub
82
83Fetch information of an existing Hub including the list of APIs it contains. The response follows the [APIs.json specification](http://apisjson.org/)
84*/
85    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    /**Create a new version
95
96Deploy a new version for a given documentation, which will become the current version.
97*/
98    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    /**Validate a documentation definition
116
117Validate a definition against its schema (OpenAPI or AsyncAPI) and return errors without creating a new version. This is useful in a CI process, to validate that a changed definition file is valid and won't fail when being deployed on Bump.
118*/
119    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    /**Create a preview
135
136Create a preview for a given documentation file. The preview will have a unique temporary URL, and will be active for 30 minutes.
137*/
138    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    /**Update an existing preview
146
147Update a preview with the given documentation file. The preview will stay active for 30 minutes after the last update.
148*/
149    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    /**Fetch a full documentation version including diff summary
162
163Fetch a full documentation version including diff summary.
164*/
165    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    /**Check the API status
175
176Responds a pong if the API is up and running.*/
177    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}