azure_devops_rust_api/operations/
mod.rs1#![allow(unused_mut)]
4#![allow(unused_variables)]
5#![allow(unused_imports)]
6#![allow(clippy::redundant_clone)]
7#![allow(clippy::too_many_arguments)]
8#![allow(clippy::module_inception)]
9pub mod models;
10#[derive(Clone)]
11pub struct Client {
12 endpoint: azure_core::http::Url,
13 credential: crate::Credential,
14 scopes: Vec<String>,
15 pipeline: azure_core::http::Pipeline,
16}
17#[derive(Clone)]
18pub struct ClientBuilder {
19 credential: crate::Credential,
20 endpoint: Option<azure_core::http::Url>,
21 scopes: Option<Vec<String>>,
22 options: azure_core::http::ClientOptions,
23}
24azure_core::static_url!(DEFAULT_ENDPOINT, "https://dev.azure.com");
25impl ClientBuilder {
26 #[doc = "Create a new instance of `ClientBuilder`."]
27 #[must_use]
28 pub fn new(credential: crate::Credential) -> Self {
29 Self {
30 credential,
31 endpoint: None,
32 scopes: None,
33 options: azure_core::http::ClientOptions::default(),
34 }
35 }
36 #[doc = "Set the endpoint."]
37 #[must_use]
38 pub fn endpoint(mut self, endpoint: impl Into<azure_core::http::Url>) -> Self {
39 self.endpoint = Some(endpoint.into());
40 self
41 }
42 #[doc = "Set the scopes."]
43 #[must_use]
44 pub fn scopes(mut self, scopes: &[&str]) -> Self {
45 self.scopes = Some(scopes.iter().map(|scope| (*scope).to_owned()).collect());
46 self
47 }
48 #[doc = "Set the retry options."]
49 #[must_use]
50 pub fn retry(mut self, retry: impl Into<azure_core::http::RetryOptions>) -> Self {
51 self.options.retry = retry.into();
52 self
53 }
54 #[doc = "Set the transport options."]
55 #[must_use]
56 pub fn transport(mut self, transport: impl Into<azure_core::http::Transport>) -> Self {
57 self.options.transport = Some(transport.into());
58 self
59 }
60 #[doc = "Set per-call policies."]
61 #[must_use]
62 pub fn per_call_policies(
63 mut self,
64 policies: impl Into<Vec<std::sync::Arc<dyn azure_core::http::policies::Policy>>>,
65 ) -> Self {
66 self.options.per_call_policies = policies.into();
67 self
68 }
69 #[doc = "Set per-try policies."]
70 #[must_use]
71 pub fn per_try_policies(
72 mut self,
73 policies: impl Into<Vec<std::sync::Arc<dyn azure_core::http::policies::Policy>>>,
74 ) -> Self {
75 self.options.per_try_policies = policies.into();
76 self
77 }
78 #[doc = "Convert the builder into a `Client` instance."]
79 pub fn build(self) -> Client {
80 let endpoint = self.endpoint.unwrap_or_else(|| DEFAULT_ENDPOINT.to_owned());
81 let scopes = self
82 .scopes
83 .unwrap_or_else(|| vec![crate::ADO_SCOPE.to_string()]);
84 Client::new(endpoint, self.credential, scopes, self.options)
85 }
86}
87impl Client {
88 pub(crate) fn endpoint(&self) -> &azure_core::http::Url {
89 &self.endpoint
90 }
91 pub(crate) fn token_credential(&self) -> &crate::Credential {
92 &self.credential
93 }
94 pub(crate) fn scopes(&self) -> Vec<&str> {
95 self.scopes.iter().map(String::as_str).collect()
96 }
97 pub(crate) async fn send(
98 &self,
99 request: &mut azure_core::http::Request,
100 ) -> azure_core::Result<azure_core::http::RawResponse> {
101 let context = azure_core::http::Context::default();
102 self.pipeline.send(&context, request, None).await
103 }
104 #[doc = "Create a new `ClientBuilder`."]
105 #[must_use]
106 pub fn builder(credential: crate::Credential) -> ClientBuilder {
107 ClientBuilder::new(credential)
108 }
109 #[doc = "Create a new `Client`."]
110 #[must_use]
111 pub fn new(
112 endpoint: impl Into<azure_core::http::Url>,
113 credential: crate::Credential,
114 scopes: Vec<String>,
115 options: azure_core::http::ClientOptions,
116 ) -> Self {
117 let endpoint = endpoint.into();
118 let pipeline = azure_core::http::Pipeline::new(
119 option_env!("CARGO_PKG_NAME"),
120 option_env!("CARGO_PKG_VERSION"),
121 options,
122 Vec::new(),
123 Vec::new(),
124 None,
125 );
126 Self {
127 endpoint,
128 credential,
129 scopes,
130 pipeline,
131 }
132 }
133 pub fn operations_client(&self) -> operations::Client {
134 operations::Client(self.clone())
135 }
136}
137pub mod operations {
138 use super::models;
139 #[cfg(not(target_arch = "wasm32"))]
140 use futures::future::BoxFuture;
141 #[cfg(target_arch = "wasm32")]
142 use futures::future::LocalBoxFuture as BoxFuture;
143 pub struct Client(pub(crate) super::Client);
144 impl Client {
145 #[doc = "Gets an operation from the operationId using the given pluginId.\n\nSome scenarios don’t require a pluginId. If a pluginId is not included in the call then just the operationId will be used to find an operation."]
146 #[doc = ""]
147 #[doc = "Arguments:"]
148 #[doc = "* `operation_id`: The ID for the operation."]
149 #[doc = "* `organization`: The name of the Azure DevOps organization."]
150 pub fn get(
151 &self,
152 operation_id: impl Into<String>,
153 organization: impl Into<String>,
154 ) -> get::RequestBuilder {
155 get::RequestBuilder {
156 client: self.0.clone(),
157 operation_id: operation_id.into(),
158 organization: organization.into(),
159 plugin_id: None,
160 }
161 }
162 }
163 pub mod get {
164 use super::models;
165 #[cfg(not(target_arch = "wasm32"))]
166 use futures::future::BoxFuture;
167 #[cfg(target_arch = "wasm32")]
168 use futures::future::LocalBoxFuture as BoxFuture;
169 #[derive(Debug)]
170 pub struct Response(
171 azure_core::http::Response<models::Operation, azure_core::http::JsonFormat>,
172 );
173 impl Response {
174 pub fn into_body(self) -> azure_core::Result<models::Operation> {
175 self.0.into_model()
176 }
177 pub fn into_raw_response(self) -> azure_core::http::RawResponse {
178 self.0.into()
179 }
180 }
181 #[derive(Clone)]
182 #[doc = r" `RequestBuilder` provides a mechanism for setting optional parameters on a request."]
183 #[doc = r""]
184 #[doc = r" Each `RequestBuilder` parameter method call returns `Self`, so setting of multiple"]
185 #[doc = r" parameters can be chained."]
186 #[doc = r""]
187 #[doc = r" To finalize and submit the request, invoke `.await`, which"]
188 #[doc = r" converts the [`RequestBuilder`] into a future,"]
189 #[doc = r" executes the request and returns a `Result` with the parsed"]
190 #[doc = r" response."]
191 #[doc = r""]
192 #[doc = r" If you need lower-level access to the raw response details"]
193 #[doc = r" (e.g. to inspect response headers or raw body data) then you"]
194 #[doc = r" can finalize the request using the"]
195 #[doc = r" [`RequestBuilder::send()`] method which returns a future"]
196 #[doc = r" that resolves to a lower-level [`Response`] value."]
197 pub struct RequestBuilder {
198 pub(crate) client: super::super::Client,
199 pub(crate) operation_id: String,
200 pub(crate) organization: String,
201 pub(crate) plugin_id: Option<String>,
202 }
203 impl RequestBuilder {
204 #[doc = "The ID for the plugin."]
205 pub fn plugin_id(mut self, plugin_id: impl Into<String>) -> Self {
206 self.plugin_id = Some(plugin_id.into());
207 self
208 }
209 #[doc = "Returns a future that sends the request and returns a [`Response`] object that provides low-level access to full response details."]
210 #[doc = ""]
211 #[doc = "You should typically use `.await` (which implicitly calls `IntoFuture::into_future()`) to finalize and send requests rather than `send()`."]
212 #[doc = "However, this function can provide more flexibility when required."]
213 pub fn send(self) -> BoxFuture<'static, azure_core::Result<Response>> {
214 Box::pin({
215 let this = self.clone();
216 async move {
217 let url = this.url()?;
218 let mut req =
219 azure_core::http::Request::new(url, azure_core::http::Method::Get);
220 if let Some(auth_header) = this
221 .client
222 .token_credential()
223 .http_authorization_header(&this.client.scopes())
224 .await?
225 {
226 req.insert_header(
227 azure_core::http::headers::AUTHORIZATION,
228 auth_header,
229 );
230 }
231 if let Some(plugin_id) = &this.plugin_id {
232 req.url_mut()
233 .query_pairs_mut()
234 .append_pair("pluginId", plugin_id);
235 }
236 let req_body = azure_core::Bytes::new();
237 req.set_body(req_body);
238 Ok(Response(this.client.send(&mut req).await?.into()))
239 }
240 })
241 }
242 fn url(&self) -> azure_core::Result<azure_core::http::Url> {
243 let mut url = azure_core::http::Url::parse(&format!(
244 "{}/{}/_apis/operations/{}",
245 self.client.endpoint(),
246 &self.organization,
247 &self.operation_id
248 ))?;
249 let has_api_version_already = url.query_pairs().any(|(k, _)| k == "api-version");
250 if !has_api_version_already {
251 url.query_pairs_mut()
252 .append_pair("api-version", "7.1-preview");
253 }
254 Ok(url)
255 }
256 }
257 impl std::future::IntoFuture for RequestBuilder {
258 type Output = azure_core::Result<models::Operation>;
259 type IntoFuture = BoxFuture<'static, azure_core::Result<models::Operation>>;
260 #[doc = "Returns a future that sends the request and returns the parsed response body."]
261 #[doc = ""]
262 #[doc = "You should not normally call this method directly, simply invoke `.await` which implicitly calls `IntoFuture::into_future`."]
263 #[doc = ""]
264 #[doc = "See [IntoFuture documentation](https://doc.rust-lang.org/std/future/trait.IntoFuture.html) for more details."]
265 fn into_future(self) -> Self::IntoFuture {
266 Box::pin(async move { self.send().await?.into_body() })
267 }
268 }
269 }
270}