google_taskqueue1_beta2/api.rs
1#![allow(clippy::ptr_arg)]
2
3use std::collections::{BTreeSet, HashMap};
4
5use tokio::time::sleep;
6
7// ##############
8// UTILITIES ###
9// ############
10
11/// Identifies the an OAuth2 authorization scope.
12/// A scope is needed when requesting an
13/// [authorization token](https://developers.google.com/youtube/v3/guides/authentication).
14#[derive(PartialEq, Eq, Ord, PartialOrd, Hash, Debug, Clone, Copy)]
15pub enum Scope {
16 /// Manage your Tasks and Taskqueues
17 Full,
18
19 /// Consume Tasks from your Taskqueues
20 Consumer,
21}
22
23impl AsRef<str> for Scope {
24 fn as_ref(&self) -> &str {
25 match *self {
26 Scope::Full => "https://www.googleapis.com/auth/taskqueue",
27 Scope::Consumer => "https://www.googleapis.com/auth/taskqueue.consumer",
28 }
29 }
30}
31
32#[allow(clippy::derivable_impls)]
33impl Default for Scope {
34 fn default() -> Scope {
35 Scope::Full
36 }
37}
38
39// ########
40// HUB ###
41// ######
42
43/// Central instance to access all Taskqueue related resource activities
44///
45/// # Examples
46///
47/// Instantiate a new hub
48///
49/// ```test_harness,no_run
50/// extern crate hyper;
51/// extern crate hyper_rustls;
52/// extern crate google_taskqueue1_beta2 as taskqueue1_beta2;
53/// use taskqueue1_beta2::{Result, Error};
54/// # async fn dox() {
55/// use taskqueue1_beta2::{Taskqueue, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
56///
57/// // Get an ApplicationSecret instance by some means. It contains the `client_id` and
58/// // `client_secret`, among other things.
59/// let secret: yup_oauth2::ApplicationSecret = Default::default();
60/// // Instantiate the authenticator. It will choose a suitable authentication flow for you,
61/// // unless you replace `None` with the desired Flow.
62/// // Provide your own `AuthenticatorDelegate` to adjust the way it operates and get feedback about
63/// // what's going on. You probably want to bring in your own `TokenStorage` to persist tokens and
64/// // retrieve them from storage.
65/// let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
66/// secret,
67/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
68/// ).build().await.unwrap();
69///
70/// let client = hyper_util::client::legacy::Client::builder(
71/// hyper_util::rt::TokioExecutor::new()
72/// )
73/// .build(
74/// hyper_rustls::HttpsConnectorBuilder::new()
75/// .with_native_roots()
76/// .unwrap()
77/// .https_or_http()
78/// .enable_http1()
79/// .build()
80/// );
81/// let mut hub = Taskqueue::new(client, auth);
82/// // You can configure optional parameters by calling the respective setters at will, and
83/// // execute the final call using `doit()`.
84/// // Values shown here are possibly random and not representative !
85/// let result = hub.tasks().lease("project", "taskqueue", -75, -4)
86/// .tag("ea")
87/// .group_by_tag(true)
88/// .doit().await;
89///
90/// match result {
91/// Err(e) => match e {
92/// // The Error enum provides details about what exactly happened.
93/// // You can also just use its `Debug`, `Display` or `Error` traits
94/// Error::HttpError(_)
95/// |Error::Io(_)
96/// |Error::MissingAPIKey
97/// |Error::MissingToken(_)
98/// |Error::Cancelled
99/// |Error::UploadSizeLimitExceeded(_, _)
100/// |Error::Failure(_)
101/// |Error::BadRequest(_)
102/// |Error::FieldClash(_)
103/// |Error::JsonDecodeError(_, _) => println!("{}", e),
104/// },
105/// Ok(res) => println!("Success: {:?}", res),
106/// }
107/// # }
108/// ```
109#[derive(Clone)]
110pub struct Taskqueue<C> {
111 pub client: common::Client<C>,
112 pub auth: Box<dyn common::GetToken>,
113 _user_agent: String,
114 _base_url: String,
115 _root_url: String,
116}
117
118impl<C> common::Hub for Taskqueue<C> {}
119
120impl<'a, C> Taskqueue<C> {
121 pub fn new<A: 'static + common::GetToken>(client: common::Client<C>, auth: A) -> Taskqueue<C> {
122 Taskqueue {
123 client,
124 auth: Box::new(auth),
125 _user_agent: "google-api-rust-client/6.0.0".to_string(),
126 _base_url: "https://www.googleapis.com/taskqueue/v1beta2/projects/".to_string(),
127 _root_url: "https://www.googleapis.com/".to_string(),
128 }
129 }
130
131 pub fn taskqueues(&'a self) -> TaskqueueMethods<'a, C> {
132 TaskqueueMethods { hub: self }
133 }
134 pub fn tasks(&'a self) -> TaskMethods<'a, C> {
135 TaskMethods { hub: self }
136 }
137
138 /// Set the user-agent header field to use in all requests to the server.
139 /// It defaults to `google-api-rust-client/6.0.0`.
140 ///
141 /// Returns the previously set user-agent.
142 pub fn user_agent(&mut self, agent_name: String) -> String {
143 std::mem::replace(&mut self._user_agent, agent_name)
144 }
145
146 /// Set the base url to use in all requests to the server.
147 /// It defaults to `https://www.googleapis.com/taskqueue/v1beta2/projects/`.
148 ///
149 /// Returns the previously set base url.
150 pub fn base_url(&mut self, new_base_url: String) -> String {
151 std::mem::replace(&mut self._base_url, new_base_url)
152 }
153
154 /// Set the root url to use in all requests to the server.
155 /// It defaults to `https://www.googleapis.com/`.
156 ///
157 /// Returns the previously set root url.
158 pub fn root_url(&mut self, new_root_url: String) -> String {
159 std::mem::replace(&mut self._root_url, new_root_url)
160 }
161}
162
163// ############
164// SCHEMAS ###
165// ##########
166/// There is no detailed description.
167///
168/// # Activities
169///
170/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
171/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
172///
173/// * [delete tasks](TaskDeleteCall) (none)
174/// * [get tasks](TaskGetCall) (response)
175/// * [insert tasks](TaskInsertCall) (request|response)
176/// * [lease tasks](TaskLeaseCall) (none)
177/// * [list tasks](TaskListCall) (none)
178/// * [patch tasks](TaskPatchCall) (request|response)
179/// * [update tasks](TaskUpdateCall) (request|response)
180#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
181#[serde_with::serde_as]
182#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
183pub struct Task {
184 /// Time (in seconds since the epoch) at which the task was enqueued.
185 #[serde(rename = "enqueueTimestamp")]
186 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
187 pub enqueue_timestamp: Option<i64>,
188 /// Name of the task.
189 pub id: Option<String>,
190 /// The kind of object returned, in this case set to task.
191 pub kind: Option<String>,
192 /// Time (in seconds since the epoch) at which the task lease will expire. This value is 0 if the task isnt currently leased out to a worker.
193 #[serde(rename = "leaseTimestamp")]
194 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
195 pub lease_timestamp: Option<i64>,
196 /// A bag of bytes which is the task payload. The payload on the JSON side is always Base64 encoded.
197 #[serde(rename = "payloadBase64")]
198 pub payload_base64: Option<String>,
199 /// Name of the queue that the task is in.
200 #[serde(rename = "queueName")]
201 pub queue_name: Option<String>,
202 /// The number of leases applied to this task.
203 pub retry_count: Option<i32>,
204 /// Tag for the task, could be used later to lease tasks grouped by a specific tag.
205 pub tag: Option<String>,
206}
207
208impl common::RequestValue for Task {}
209impl common::Resource for Task {}
210impl common::ResponseResult for Task {}
211
212/// There is no detailed description.
213///
214/// # Activities
215///
216/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
217/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
218///
219/// * [get taskqueues](TaskqueueGetCall) (response)
220#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
221#[serde_with::serde_as]
222#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
223pub struct TaskQueue {
224 /// ACLs that are applicable to this TaskQueue object.
225 pub acl: Option<TaskQueueAcl>,
226 /// Name of the taskqueue.
227 pub id: Option<String>,
228 /// The kind of REST object returned, in this case taskqueue.
229 pub kind: Option<String>,
230 /// The number of times we should lease out tasks before giving up on them. If unset we lease them out forever until a worker deletes the task.
231 #[serde(rename = "maxLeases")]
232 pub max_leases: Option<i32>,
233 /// Statistics for the TaskQueue object in question.
234 pub stats: Option<TaskQueueStats>,
235}
236
237impl common::Resource for TaskQueue {}
238impl common::ResponseResult for TaskQueue {}
239
240/// There is no detailed description.
241///
242/// # Activities
243///
244/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
245/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
246///
247/// * [lease tasks](TaskLeaseCall) (response)
248#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
249#[serde_with::serde_as]
250#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
251pub struct Tasks {
252 /// The actual list of tasks returned as a result of the lease operation.
253 pub items: Option<Vec<Task>>,
254 /// The kind of object returned, a list of tasks.
255 pub kind: Option<String>,
256}
257
258impl common::ResponseResult for Tasks {}
259
260/// There is no detailed description.
261///
262/// # Activities
263///
264/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
265/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
266///
267/// * [list tasks](TaskListCall) (response)
268#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
269#[serde_with::serde_as]
270#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
271pub struct Tasks2 {
272 /// The actual list of tasks currently active in the TaskQueue.
273 pub items: Option<Vec<Task>>,
274 /// The kind of object returned, a list of tasks.
275 pub kind: Option<String>,
276}
277
278impl common::ResponseResult for Tasks2 {}
279
280/// ACLs that are applicable to this TaskQueue object.
281///
282/// This type is not used in any activity, and only used as *part* of another schema.
283///
284#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
285#[serde_with::serde_as]
286#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
287pub struct TaskQueueAcl {
288 /// Email addresses of users who are "admins" of the TaskQueue. This means they can control the queue, eg set ACLs for the queue.
289 #[serde(rename = "adminEmails")]
290 pub admin_emails: Option<Vec<String>>,
291 /// Email addresses of users who can "consume" tasks from the TaskQueue. This means they can Dequeue and Delete tasks from the queue.
292 #[serde(rename = "consumerEmails")]
293 pub consumer_emails: Option<Vec<String>>,
294 /// Email addresses of users who can "produce" tasks into the TaskQueue. This means they can Insert tasks into the queue.
295 #[serde(rename = "producerEmails")]
296 pub producer_emails: Option<Vec<String>>,
297}
298
299impl common::NestedType for TaskQueueAcl {}
300impl common::Part for TaskQueueAcl {}
301
302/// Statistics for the TaskQueue object in question.
303///
304/// This type is not used in any activity, and only used as *part* of another schema.
305///
306#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
307#[serde_with::serde_as]
308#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
309pub struct TaskQueueStats {
310 /// Number of tasks leased in the last hour.
311 #[serde(rename = "leasedLastHour")]
312 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
313 pub leased_last_hour: Option<i64>,
314 /// Number of tasks leased in the last minute.
315 #[serde(rename = "leasedLastMinute")]
316 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
317 pub leased_last_minute: Option<i64>,
318 /// The timestamp (in seconds since the epoch) of the oldest unfinished task.
319 #[serde(rename = "oldestTask")]
320 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
321 pub oldest_task: Option<i64>,
322 /// Number of tasks in the queue.
323 #[serde(rename = "totalTasks")]
324 pub total_tasks: Option<i32>,
325}
326
327impl common::NestedType for TaskQueueStats {}
328impl common::Part for TaskQueueStats {}
329
330// ###################
331// MethodBuilders ###
332// #################
333
334/// A builder providing access to all methods supported on *taskqueue* resources.
335/// It is not used directly, but through the [`Taskqueue`] hub.
336///
337/// # Example
338///
339/// Instantiate a resource builder
340///
341/// ```test_harness,no_run
342/// extern crate hyper;
343/// extern crate hyper_rustls;
344/// extern crate google_taskqueue1_beta2 as taskqueue1_beta2;
345///
346/// # async fn dox() {
347/// use taskqueue1_beta2::{Taskqueue, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
348///
349/// let secret: yup_oauth2::ApplicationSecret = Default::default();
350/// let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
351/// secret,
352/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
353/// ).build().await.unwrap();
354///
355/// let client = hyper_util::client::legacy::Client::builder(
356/// hyper_util::rt::TokioExecutor::new()
357/// )
358/// .build(
359/// hyper_rustls::HttpsConnectorBuilder::new()
360/// .with_native_roots()
361/// .unwrap()
362/// .https_or_http()
363/// .enable_http1()
364/// .build()
365/// );
366/// let mut hub = Taskqueue::new(client, auth);
367/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
368/// // like `get(...)`
369/// // to build up your call.
370/// let rb = hub.taskqueues();
371/// # }
372/// ```
373pub struct TaskqueueMethods<'a, C>
374where
375 C: 'a,
376{
377 hub: &'a Taskqueue<C>,
378}
379
380impl<'a, C> common::MethodsBuilder for TaskqueueMethods<'a, C> {}
381
382impl<'a, C> TaskqueueMethods<'a, C> {
383 /// Create a builder to help you perform the following task:
384 ///
385 /// Get detailed information about a TaskQueue.
386 ///
387 /// # Arguments
388 ///
389 /// * `project` - The project under which the queue lies.
390 /// * `taskqueue` - The id of the taskqueue to get the properties of.
391 pub fn get(&self, project: &str, taskqueue: &str) -> TaskqueueGetCall<'a, C> {
392 TaskqueueGetCall {
393 hub: self.hub,
394 _project: project.to_string(),
395 _taskqueue: taskqueue.to_string(),
396 _get_stats: Default::default(),
397 _delegate: Default::default(),
398 _additional_params: Default::default(),
399 _scopes: Default::default(),
400 }
401 }
402}
403
404/// A builder providing access to all methods supported on *task* resources.
405/// It is not used directly, but through the [`Taskqueue`] hub.
406///
407/// # Example
408///
409/// Instantiate a resource builder
410///
411/// ```test_harness,no_run
412/// extern crate hyper;
413/// extern crate hyper_rustls;
414/// extern crate google_taskqueue1_beta2 as taskqueue1_beta2;
415///
416/// # async fn dox() {
417/// use taskqueue1_beta2::{Taskqueue, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
418///
419/// let secret: yup_oauth2::ApplicationSecret = Default::default();
420/// let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
421/// secret,
422/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
423/// ).build().await.unwrap();
424///
425/// let client = hyper_util::client::legacy::Client::builder(
426/// hyper_util::rt::TokioExecutor::new()
427/// )
428/// .build(
429/// hyper_rustls::HttpsConnectorBuilder::new()
430/// .with_native_roots()
431/// .unwrap()
432/// .https_or_http()
433/// .enable_http1()
434/// .build()
435/// );
436/// let mut hub = Taskqueue::new(client, auth);
437/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
438/// // like `delete(...)`, `get(...)`, `insert(...)`, `lease(...)`, `list(...)`, `patch(...)` and `update(...)`
439/// // to build up your call.
440/// let rb = hub.tasks();
441/// # }
442/// ```
443pub struct TaskMethods<'a, C>
444where
445 C: 'a,
446{
447 hub: &'a Taskqueue<C>,
448}
449
450impl<'a, C> common::MethodsBuilder for TaskMethods<'a, C> {}
451
452impl<'a, C> TaskMethods<'a, C> {
453 /// Create a builder to help you perform the following task:
454 ///
455 /// Delete a task from a TaskQueue.
456 ///
457 /// # Arguments
458 ///
459 /// * `project` - The project under which the queue lies.
460 /// * `taskqueue` - The taskqueue to delete a task from.
461 /// * `task` - The id of the task to delete.
462 pub fn delete(&self, project: &str, taskqueue: &str, task: &str) -> TaskDeleteCall<'a, C> {
463 TaskDeleteCall {
464 hub: self.hub,
465 _project: project.to_string(),
466 _taskqueue: taskqueue.to_string(),
467 _task: task.to_string(),
468 _delegate: Default::default(),
469 _additional_params: Default::default(),
470 _scopes: Default::default(),
471 }
472 }
473
474 /// Create a builder to help you perform the following task:
475 ///
476 /// Get a particular task from a TaskQueue.
477 ///
478 /// # Arguments
479 ///
480 /// * `project` - The project under which the queue lies.
481 /// * `taskqueue` - The taskqueue in which the task belongs.
482 /// * `task` - The task to get properties of.
483 pub fn get(&self, project: &str, taskqueue: &str, task: &str) -> TaskGetCall<'a, C> {
484 TaskGetCall {
485 hub: self.hub,
486 _project: project.to_string(),
487 _taskqueue: taskqueue.to_string(),
488 _task: task.to_string(),
489 _delegate: Default::default(),
490 _additional_params: Default::default(),
491 _scopes: Default::default(),
492 }
493 }
494
495 /// Create a builder to help you perform the following task:
496 ///
497 /// Insert a new task in a TaskQueue
498 ///
499 /// # Arguments
500 ///
501 /// * `request` - No description provided.
502 /// * `project` - The project under which the queue lies
503 /// * `taskqueue` - The taskqueue to insert the task into
504 pub fn insert(&self, request: Task, project: &str, taskqueue: &str) -> TaskInsertCall<'a, C> {
505 TaskInsertCall {
506 hub: self.hub,
507 _request: request,
508 _project: project.to_string(),
509 _taskqueue: taskqueue.to_string(),
510 _delegate: Default::default(),
511 _additional_params: Default::default(),
512 _scopes: Default::default(),
513 }
514 }
515
516 /// Create a builder to help you perform the following task:
517 ///
518 /// Lease 1 or more tasks from a TaskQueue.
519 ///
520 /// # Arguments
521 ///
522 /// * `project` - The project under which the queue lies.
523 /// * `taskqueue` - The taskqueue to lease a task from.
524 /// * `numTasks` - The number of tasks to lease.
525 /// * `leaseSecs` - The lease in seconds.
526 pub fn lease(
527 &self,
528 project: &str,
529 taskqueue: &str,
530 num_tasks: i32,
531 lease_secs: i32,
532 ) -> TaskLeaseCall<'a, C> {
533 TaskLeaseCall {
534 hub: self.hub,
535 _project: project.to_string(),
536 _taskqueue: taskqueue.to_string(),
537 _num_tasks: num_tasks,
538 _lease_secs: lease_secs,
539 _tag: Default::default(),
540 _group_by_tag: Default::default(),
541 _delegate: Default::default(),
542 _additional_params: Default::default(),
543 _scopes: Default::default(),
544 }
545 }
546
547 /// Create a builder to help you perform the following task:
548 ///
549 /// List Tasks in a TaskQueue
550 ///
551 /// # Arguments
552 ///
553 /// * `project` - The project under which the queue lies.
554 /// * `taskqueue` - The id of the taskqueue to list tasks from.
555 pub fn list(&self, project: &str, taskqueue: &str) -> TaskListCall<'a, C> {
556 TaskListCall {
557 hub: self.hub,
558 _project: project.to_string(),
559 _taskqueue: taskqueue.to_string(),
560 _delegate: Default::default(),
561 _additional_params: Default::default(),
562 _scopes: Default::default(),
563 }
564 }
565
566 /// Create a builder to help you perform the following task:
567 ///
568 /// Update tasks that are leased out of a TaskQueue. This method supports patch semantics.
569 ///
570 /// # Arguments
571 ///
572 /// * `request` - No description provided.
573 /// * `project` - The project under which the queue lies.
574 /// * `taskqueue` - No description provided.
575 /// * `task` - No description provided.
576 /// * `newLeaseSeconds` - The new lease in seconds.
577 pub fn patch(
578 &self,
579 request: Task,
580 project: &str,
581 taskqueue: &str,
582 task: &str,
583 new_lease_seconds: i32,
584 ) -> TaskPatchCall<'a, C> {
585 TaskPatchCall {
586 hub: self.hub,
587 _request: request,
588 _project: project.to_string(),
589 _taskqueue: taskqueue.to_string(),
590 _task: task.to_string(),
591 _new_lease_seconds: new_lease_seconds,
592 _delegate: Default::default(),
593 _additional_params: Default::default(),
594 _scopes: Default::default(),
595 }
596 }
597
598 /// Create a builder to help you perform the following task:
599 ///
600 /// Update tasks that are leased out of a TaskQueue.
601 ///
602 /// # Arguments
603 ///
604 /// * `request` - No description provided.
605 /// * `project` - The project under which the queue lies.
606 /// * `taskqueue` - No description provided.
607 /// * `task` - No description provided.
608 /// * `newLeaseSeconds` - The new lease in seconds.
609 pub fn update(
610 &self,
611 request: Task,
612 project: &str,
613 taskqueue: &str,
614 task: &str,
615 new_lease_seconds: i32,
616 ) -> TaskUpdateCall<'a, C> {
617 TaskUpdateCall {
618 hub: self.hub,
619 _request: request,
620 _project: project.to_string(),
621 _taskqueue: taskqueue.to_string(),
622 _task: task.to_string(),
623 _new_lease_seconds: new_lease_seconds,
624 _delegate: Default::default(),
625 _additional_params: Default::default(),
626 _scopes: Default::default(),
627 }
628 }
629}
630
631// ###################
632// CallBuilders ###
633// #################
634
635/// Get detailed information about a TaskQueue.
636///
637/// A builder for the *get* method supported by a *taskqueue* resource.
638/// It is not used directly, but through a [`TaskqueueMethods`] instance.
639///
640/// # Example
641///
642/// Instantiate a resource method builder
643///
644/// ```test_harness,no_run
645/// # extern crate hyper;
646/// # extern crate hyper_rustls;
647/// # extern crate google_taskqueue1_beta2 as taskqueue1_beta2;
648/// # async fn dox() {
649/// # use taskqueue1_beta2::{Taskqueue, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
650///
651/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
652/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
653/// # secret,
654/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
655/// # ).build().await.unwrap();
656///
657/// # let client = hyper_util::client::legacy::Client::builder(
658/// # hyper_util::rt::TokioExecutor::new()
659/// # )
660/// # .build(
661/// # hyper_rustls::HttpsConnectorBuilder::new()
662/// # .with_native_roots()
663/// # .unwrap()
664/// # .https_or_http()
665/// # .enable_http1()
666/// # .build()
667/// # );
668/// # let mut hub = Taskqueue::new(client, auth);
669/// // You can configure optional parameters by calling the respective setters at will, and
670/// // execute the final call using `doit()`.
671/// // Values shown here are possibly random and not representative !
672/// let result = hub.taskqueues().get("project", "taskqueue")
673/// .get_stats(true)
674/// .doit().await;
675/// # }
676/// ```
677pub struct TaskqueueGetCall<'a, C>
678where
679 C: 'a,
680{
681 hub: &'a Taskqueue<C>,
682 _project: String,
683 _taskqueue: String,
684 _get_stats: Option<bool>,
685 _delegate: Option<&'a mut dyn common::Delegate>,
686 _additional_params: HashMap<String, String>,
687 _scopes: BTreeSet<String>,
688}
689
690impl<'a, C> common::CallBuilder for TaskqueueGetCall<'a, C> {}
691
692impl<'a, C> TaskqueueGetCall<'a, C>
693where
694 C: common::Connector,
695{
696 /// Perform the operation you have build so far.
697 pub async fn doit(mut self) -> common::Result<(common::Response, TaskQueue)> {
698 use std::borrow::Cow;
699 use std::io::{Read, Seek};
700
701 use common::{url::Params, ToParts};
702 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
703
704 let mut dd = common::DefaultDelegate;
705 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
706 dlg.begin(common::MethodInfo {
707 id: "taskqueue.taskqueues.get",
708 http_method: hyper::Method::GET,
709 });
710
711 for &field in ["alt", "project", "taskqueue", "getStats"].iter() {
712 if self._additional_params.contains_key(field) {
713 dlg.finished(false);
714 return Err(common::Error::FieldClash(field));
715 }
716 }
717
718 let mut params = Params::with_capacity(5 + self._additional_params.len());
719 params.push("project", self._project);
720 params.push("taskqueue", self._taskqueue);
721 if let Some(value) = self._get_stats.as_ref() {
722 params.push("getStats", value.to_string());
723 }
724
725 params.extend(self._additional_params.iter());
726
727 params.push("alt", "json");
728 let mut url = self.hub._base_url.clone() + "{project}/taskqueues/{taskqueue}";
729 if self._scopes.is_empty() {
730 self._scopes.insert(Scope::Full.as_ref().to_string());
731 }
732
733 #[allow(clippy::single_element_loop)]
734 for &(find_this, param_name) in
735 [("{project}", "project"), ("{taskqueue}", "taskqueue")].iter()
736 {
737 url = params.uri_replacement(url, param_name, find_this, false);
738 }
739 {
740 let to_remove = ["taskqueue", "project"];
741 params.remove_params(&to_remove);
742 }
743
744 let url = params.parse_with_url(&url);
745
746 loop {
747 let token = match self
748 .hub
749 .auth
750 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
751 .await
752 {
753 Ok(token) => token,
754 Err(e) => match dlg.token(e) {
755 Ok(token) => token,
756 Err(e) => {
757 dlg.finished(false);
758 return Err(common::Error::MissingToken(e));
759 }
760 },
761 };
762 let mut req_result = {
763 let client = &self.hub.client;
764 dlg.pre_request();
765 let mut req_builder = hyper::Request::builder()
766 .method(hyper::Method::GET)
767 .uri(url.as_str())
768 .header(USER_AGENT, self.hub._user_agent.clone());
769
770 if let Some(token) = token.as_ref() {
771 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
772 }
773
774 let request = req_builder
775 .header(CONTENT_LENGTH, 0_u64)
776 .body(common::to_body::<String>(None));
777
778 client.request(request.unwrap()).await
779 };
780
781 match req_result {
782 Err(err) => {
783 if let common::Retry::After(d) = dlg.http_error(&err) {
784 sleep(d).await;
785 continue;
786 }
787 dlg.finished(false);
788 return Err(common::Error::HttpError(err));
789 }
790 Ok(res) => {
791 let (mut parts, body) = res.into_parts();
792 let mut body = common::Body::new(body);
793 if !parts.status.is_success() {
794 let bytes = common::to_bytes(body).await.unwrap_or_default();
795 let error = serde_json::from_str(&common::to_string(&bytes));
796 let response = common::to_response(parts, bytes.into());
797
798 if let common::Retry::After(d) =
799 dlg.http_failure(&response, error.as_ref().ok())
800 {
801 sleep(d).await;
802 continue;
803 }
804
805 dlg.finished(false);
806
807 return Err(match error {
808 Ok(value) => common::Error::BadRequest(value),
809 _ => common::Error::Failure(response),
810 });
811 }
812 let response = {
813 let bytes = common::to_bytes(body).await.unwrap_or_default();
814 let encoded = common::to_string(&bytes);
815 match serde_json::from_str(&encoded) {
816 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
817 Err(error) => {
818 dlg.response_json_decode_error(&encoded, &error);
819 return Err(common::Error::JsonDecodeError(
820 encoded.to_string(),
821 error,
822 ));
823 }
824 }
825 };
826
827 dlg.finished(true);
828 return Ok(response);
829 }
830 }
831 }
832 }
833
834 /// The project under which the queue lies.
835 ///
836 /// Sets the *project* path property to the given value.
837 ///
838 /// Even though the property as already been set when instantiating this call,
839 /// we provide this method for API completeness.
840 pub fn project(mut self, new_value: &str) -> TaskqueueGetCall<'a, C> {
841 self._project = new_value.to_string();
842 self
843 }
844 /// The id of the taskqueue to get the properties of.
845 ///
846 /// Sets the *taskqueue* path property to the given value.
847 ///
848 /// Even though the property as already been set when instantiating this call,
849 /// we provide this method for API completeness.
850 pub fn taskqueue(mut self, new_value: &str) -> TaskqueueGetCall<'a, C> {
851 self._taskqueue = new_value.to_string();
852 self
853 }
854 /// Whether to get stats. Optional.
855 ///
856 /// Sets the *get stats* query property to the given value.
857 pub fn get_stats(mut self, new_value: bool) -> TaskqueueGetCall<'a, C> {
858 self._get_stats = Some(new_value);
859 self
860 }
861 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
862 /// while executing the actual API request.
863 ///
864 /// ````text
865 /// It should be used to handle progress information, and to implement a certain level of resilience.
866 /// ````
867 ///
868 /// Sets the *delegate* property to the given value.
869 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> TaskqueueGetCall<'a, C> {
870 self._delegate = Some(new_value);
871 self
872 }
873
874 /// Set any additional parameter of the query string used in the request.
875 /// It should be used to set parameters which are not yet available through their own
876 /// setters.
877 ///
878 /// Please note that this method must not be used to set any of the known parameters
879 /// which have their own setter method. If done anyway, the request will fail.
880 ///
881 /// # Additional Parameters
882 ///
883 /// * *alt* (query-string) - Data format for the response.
884 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
885 /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
886 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
887 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
888 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.
889 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
890 pub fn param<T>(mut self, name: T, value: T) -> TaskqueueGetCall<'a, C>
891 where
892 T: AsRef<str>,
893 {
894 self._additional_params
895 .insert(name.as_ref().to_string(), value.as_ref().to_string());
896 self
897 }
898
899 /// Identifies the authorization scope for the method you are building.
900 ///
901 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
902 /// [`Scope::Full`].
903 ///
904 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
905 /// tokens for more than one scope.
906 ///
907 /// Usually there is more than one suitable scope to authorize an operation, some of which may
908 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
909 /// sufficient, a read-write scope will do as well.
910 pub fn add_scope<St>(mut self, scope: St) -> TaskqueueGetCall<'a, C>
911 where
912 St: AsRef<str>,
913 {
914 self._scopes.insert(String::from(scope.as_ref()));
915 self
916 }
917 /// Identifies the authorization scope(s) for the method you are building.
918 ///
919 /// See [`Self::add_scope()`] for details.
920 pub fn add_scopes<I, St>(mut self, scopes: I) -> TaskqueueGetCall<'a, C>
921 where
922 I: IntoIterator<Item = St>,
923 St: AsRef<str>,
924 {
925 self._scopes
926 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
927 self
928 }
929
930 /// Removes all scopes, and no default scope will be used either.
931 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
932 /// for details).
933 pub fn clear_scopes(mut self) -> TaskqueueGetCall<'a, C> {
934 self._scopes.clear();
935 self
936 }
937}
938
939/// Delete a task from a TaskQueue.
940///
941/// A builder for the *delete* method supported by a *task* resource.
942/// It is not used directly, but through a [`TaskMethods`] instance.
943///
944/// # Example
945///
946/// Instantiate a resource method builder
947///
948/// ```test_harness,no_run
949/// # extern crate hyper;
950/// # extern crate hyper_rustls;
951/// # extern crate google_taskqueue1_beta2 as taskqueue1_beta2;
952/// # async fn dox() {
953/// # use taskqueue1_beta2::{Taskqueue, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
954///
955/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
956/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
957/// # secret,
958/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
959/// # ).build().await.unwrap();
960///
961/// # let client = hyper_util::client::legacy::Client::builder(
962/// # hyper_util::rt::TokioExecutor::new()
963/// # )
964/// # .build(
965/// # hyper_rustls::HttpsConnectorBuilder::new()
966/// # .with_native_roots()
967/// # .unwrap()
968/// # .https_or_http()
969/// # .enable_http1()
970/// # .build()
971/// # );
972/// # let mut hub = Taskqueue::new(client, auth);
973/// // You can configure optional parameters by calling the respective setters at will, and
974/// // execute the final call using `doit()`.
975/// // Values shown here are possibly random and not representative !
976/// let result = hub.tasks().delete("project", "taskqueue", "task")
977/// .doit().await;
978/// # }
979/// ```
980pub struct TaskDeleteCall<'a, C>
981where
982 C: 'a,
983{
984 hub: &'a Taskqueue<C>,
985 _project: String,
986 _taskqueue: String,
987 _task: String,
988 _delegate: Option<&'a mut dyn common::Delegate>,
989 _additional_params: HashMap<String, String>,
990 _scopes: BTreeSet<String>,
991}
992
993impl<'a, C> common::CallBuilder for TaskDeleteCall<'a, C> {}
994
995impl<'a, C> TaskDeleteCall<'a, C>
996where
997 C: common::Connector,
998{
999 /// Perform the operation you have build so far.
1000 pub async fn doit(mut self) -> common::Result<common::Response> {
1001 use std::borrow::Cow;
1002 use std::io::{Read, Seek};
1003
1004 use common::{url::Params, ToParts};
1005 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1006
1007 let mut dd = common::DefaultDelegate;
1008 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1009 dlg.begin(common::MethodInfo {
1010 id: "taskqueue.tasks.delete",
1011 http_method: hyper::Method::DELETE,
1012 });
1013
1014 for &field in ["project", "taskqueue", "task"].iter() {
1015 if self._additional_params.contains_key(field) {
1016 dlg.finished(false);
1017 return Err(common::Error::FieldClash(field));
1018 }
1019 }
1020
1021 let mut params = Params::with_capacity(4 + self._additional_params.len());
1022 params.push("project", self._project);
1023 params.push("taskqueue", self._taskqueue);
1024 params.push("task", self._task);
1025
1026 params.extend(self._additional_params.iter());
1027
1028 let mut url = self.hub._base_url.clone() + "{project}/taskqueues/{taskqueue}/tasks/{task}";
1029 if self._scopes.is_empty() {
1030 self._scopes.insert(Scope::Full.as_ref().to_string());
1031 }
1032
1033 #[allow(clippy::single_element_loop)]
1034 for &(find_this, param_name) in [
1035 ("{project}", "project"),
1036 ("{taskqueue}", "taskqueue"),
1037 ("{task}", "task"),
1038 ]
1039 .iter()
1040 {
1041 url = params.uri_replacement(url, param_name, find_this, false);
1042 }
1043 {
1044 let to_remove = ["task", "taskqueue", "project"];
1045 params.remove_params(&to_remove);
1046 }
1047
1048 let url = params.parse_with_url(&url);
1049
1050 loop {
1051 let token = match self
1052 .hub
1053 .auth
1054 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1055 .await
1056 {
1057 Ok(token) => token,
1058 Err(e) => match dlg.token(e) {
1059 Ok(token) => token,
1060 Err(e) => {
1061 dlg.finished(false);
1062 return Err(common::Error::MissingToken(e));
1063 }
1064 },
1065 };
1066 let mut req_result = {
1067 let client = &self.hub.client;
1068 dlg.pre_request();
1069 let mut req_builder = hyper::Request::builder()
1070 .method(hyper::Method::DELETE)
1071 .uri(url.as_str())
1072 .header(USER_AGENT, self.hub._user_agent.clone());
1073
1074 if let Some(token) = token.as_ref() {
1075 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1076 }
1077
1078 let request = req_builder
1079 .header(CONTENT_LENGTH, 0_u64)
1080 .body(common::to_body::<String>(None));
1081
1082 client.request(request.unwrap()).await
1083 };
1084
1085 match req_result {
1086 Err(err) => {
1087 if let common::Retry::After(d) = dlg.http_error(&err) {
1088 sleep(d).await;
1089 continue;
1090 }
1091 dlg.finished(false);
1092 return Err(common::Error::HttpError(err));
1093 }
1094 Ok(res) => {
1095 let (mut parts, body) = res.into_parts();
1096 let mut body = common::Body::new(body);
1097 if !parts.status.is_success() {
1098 let bytes = common::to_bytes(body).await.unwrap_or_default();
1099 let error = serde_json::from_str(&common::to_string(&bytes));
1100 let response = common::to_response(parts, bytes.into());
1101
1102 if let common::Retry::After(d) =
1103 dlg.http_failure(&response, error.as_ref().ok())
1104 {
1105 sleep(d).await;
1106 continue;
1107 }
1108
1109 dlg.finished(false);
1110
1111 return Err(match error {
1112 Ok(value) => common::Error::BadRequest(value),
1113 _ => common::Error::Failure(response),
1114 });
1115 }
1116 let response = common::Response::from_parts(parts, body);
1117
1118 dlg.finished(true);
1119 return Ok(response);
1120 }
1121 }
1122 }
1123 }
1124
1125 /// The project under which the queue lies.
1126 ///
1127 /// Sets the *project* path property to the given value.
1128 ///
1129 /// Even though the property as already been set when instantiating this call,
1130 /// we provide this method for API completeness.
1131 pub fn project(mut self, new_value: &str) -> TaskDeleteCall<'a, C> {
1132 self._project = new_value.to_string();
1133 self
1134 }
1135 /// The taskqueue to delete a task from.
1136 ///
1137 /// Sets the *taskqueue* path property to the given value.
1138 ///
1139 /// Even though the property as already been set when instantiating this call,
1140 /// we provide this method for API completeness.
1141 pub fn taskqueue(mut self, new_value: &str) -> TaskDeleteCall<'a, C> {
1142 self._taskqueue = new_value.to_string();
1143 self
1144 }
1145 /// The id of the task to delete.
1146 ///
1147 /// Sets the *task* path property to the given value.
1148 ///
1149 /// Even though the property as already been set when instantiating this call,
1150 /// we provide this method for API completeness.
1151 pub fn task(mut self, new_value: &str) -> TaskDeleteCall<'a, C> {
1152 self._task = new_value.to_string();
1153 self
1154 }
1155 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1156 /// while executing the actual API request.
1157 ///
1158 /// ````text
1159 /// It should be used to handle progress information, and to implement a certain level of resilience.
1160 /// ````
1161 ///
1162 /// Sets the *delegate* property to the given value.
1163 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> TaskDeleteCall<'a, C> {
1164 self._delegate = Some(new_value);
1165 self
1166 }
1167
1168 /// Set any additional parameter of the query string used in the request.
1169 /// It should be used to set parameters which are not yet available through their own
1170 /// setters.
1171 ///
1172 /// Please note that this method must not be used to set any of the known parameters
1173 /// which have their own setter method. If done anyway, the request will fail.
1174 ///
1175 /// # Additional Parameters
1176 ///
1177 /// * *alt* (query-string) - Data format for the response.
1178 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1179 /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
1180 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1181 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1182 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.
1183 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
1184 pub fn param<T>(mut self, name: T, value: T) -> TaskDeleteCall<'a, C>
1185 where
1186 T: AsRef<str>,
1187 {
1188 self._additional_params
1189 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1190 self
1191 }
1192
1193 /// Identifies the authorization scope for the method you are building.
1194 ///
1195 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1196 /// [`Scope::Full`].
1197 ///
1198 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1199 /// tokens for more than one scope.
1200 ///
1201 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1202 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1203 /// sufficient, a read-write scope will do as well.
1204 pub fn add_scope<St>(mut self, scope: St) -> TaskDeleteCall<'a, C>
1205 where
1206 St: AsRef<str>,
1207 {
1208 self._scopes.insert(String::from(scope.as_ref()));
1209 self
1210 }
1211 /// Identifies the authorization scope(s) for the method you are building.
1212 ///
1213 /// See [`Self::add_scope()`] for details.
1214 pub fn add_scopes<I, St>(mut self, scopes: I) -> TaskDeleteCall<'a, C>
1215 where
1216 I: IntoIterator<Item = St>,
1217 St: AsRef<str>,
1218 {
1219 self._scopes
1220 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1221 self
1222 }
1223
1224 /// Removes all scopes, and no default scope will be used either.
1225 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1226 /// for details).
1227 pub fn clear_scopes(mut self) -> TaskDeleteCall<'a, C> {
1228 self._scopes.clear();
1229 self
1230 }
1231}
1232
1233/// Get a particular task from a TaskQueue.
1234///
1235/// A builder for the *get* method supported by a *task* resource.
1236/// It is not used directly, but through a [`TaskMethods`] instance.
1237///
1238/// # Example
1239///
1240/// Instantiate a resource method builder
1241///
1242/// ```test_harness,no_run
1243/// # extern crate hyper;
1244/// # extern crate hyper_rustls;
1245/// # extern crate google_taskqueue1_beta2 as taskqueue1_beta2;
1246/// # async fn dox() {
1247/// # use taskqueue1_beta2::{Taskqueue, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1248///
1249/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1250/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
1251/// # secret,
1252/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1253/// # ).build().await.unwrap();
1254///
1255/// # let client = hyper_util::client::legacy::Client::builder(
1256/// # hyper_util::rt::TokioExecutor::new()
1257/// # )
1258/// # .build(
1259/// # hyper_rustls::HttpsConnectorBuilder::new()
1260/// # .with_native_roots()
1261/// # .unwrap()
1262/// # .https_or_http()
1263/// # .enable_http1()
1264/// # .build()
1265/// # );
1266/// # let mut hub = Taskqueue::new(client, auth);
1267/// // You can configure optional parameters by calling the respective setters at will, and
1268/// // execute the final call using `doit()`.
1269/// // Values shown here are possibly random and not representative !
1270/// let result = hub.tasks().get("project", "taskqueue", "task")
1271/// .doit().await;
1272/// # }
1273/// ```
1274pub struct TaskGetCall<'a, C>
1275where
1276 C: 'a,
1277{
1278 hub: &'a Taskqueue<C>,
1279 _project: String,
1280 _taskqueue: String,
1281 _task: String,
1282 _delegate: Option<&'a mut dyn common::Delegate>,
1283 _additional_params: HashMap<String, String>,
1284 _scopes: BTreeSet<String>,
1285}
1286
1287impl<'a, C> common::CallBuilder for TaskGetCall<'a, C> {}
1288
1289impl<'a, C> TaskGetCall<'a, C>
1290where
1291 C: common::Connector,
1292{
1293 /// Perform the operation you have build so far.
1294 pub async fn doit(mut self) -> common::Result<(common::Response, Task)> {
1295 use std::borrow::Cow;
1296 use std::io::{Read, Seek};
1297
1298 use common::{url::Params, ToParts};
1299 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1300
1301 let mut dd = common::DefaultDelegate;
1302 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1303 dlg.begin(common::MethodInfo {
1304 id: "taskqueue.tasks.get",
1305 http_method: hyper::Method::GET,
1306 });
1307
1308 for &field in ["alt", "project", "taskqueue", "task"].iter() {
1309 if self._additional_params.contains_key(field) {
1310 dlg.finished(false);
1311 return Err(common::Error::FieldClash(field));
1312 }
1313 }
1314
1315 let mut params = Params::with_capacity(5 + self._additional_params.len());
1316 params.push("project", self._project);
1317 params.push("taskqueue", self._taskqueue);
1318 params.push("task", self._task);
1319
1320 params.extend(self._additional_params.iter());
1321
1322 params.push("alt", "json");
1323 let mut url = self.hub._base_url.clone() + "{project}/taskqueues/{taskqueue}/tasks/{task}";
1324 if self._scopes.is_empty() {
1325 self._scopes.insert(Scope::Full.as_ref().to_string());
1326 }
1327
1328 #[allow(clippy::single_element_loop)]
1329 for &(find_this, param_name) in [
1330 ("{project}", "project"),
1331 ("{taskqueue}", "taskqueue"),
1332 ("{task}", "task"),
1333 ]
1334 .iter()
1335 {
1336 url = params.uri_replacement(url, param_name, find_this, false);
1337 }
1338 {
1339 let to_remove = ["task", "taskqueue", "project"];
1340 params.remove_params(&to_remove);
1341 }
1342
1343 let url = params.parse_with_url(&url);
1344
1345 loop {
1346 let token = match self
1347 .hub
1348 .auth
1349 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1350 .await
1351 {
1352 Ok(token) => token,
1353 Err(e) => match dlg.token(e) {
1354 Ok(token) => token,
1355 Err(e) => {
1356 dlg.finished(false);
1357 return Err(common::Error::MissingToken(e));
1358 }
1359 },
1360 };
1361 let mut req_result = {
1362 let client = &self.hub.client;
1363 dlg.pre_request();
1364 let mut req_builder = hyper::Request::builder()
1365 .method(hyper::Method::GET)
1366 .uri(url.as_str())
1367 .header(USER_AGENT, self.hub._user_agent.clone());
1368
1369 if let Some(token) = token.as_ref() {
1370 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1371 }
1372
1373 let request = req_builder
1374 .header(CONTENT_LENGTH, 0_u64)
1375 .body(common::to_body::<String>(None));
1376
1377 client.request(request.unwrap()).await
1378 };
1379
1380 match req_result {
1381 Err(err) => {
1382 if let common::Retry::After(d) = dlg.http_error(&err) {
1383 sleep(d).await;
1384 continue;
1385 }
1386 dlg.finished(false);
1387 return Err(common::Error::HttpError(err));
1388 }
1389 Ok(res) => {
1390 let (mut parts, body) = res.into_parts();
1391 let mut body = common::Body::new(body);
1392 if !parts.status.is_success() {
1393 let bytes = common::to_bytes(body).await.unwrap_or_default();
1394 let error = serde_json::from_str(&common::to_string(&bytes));
1395 let response = common::to_response(parts, bytes.into());
1396
1397 if let common::Retry::After(d) =
1398 dlg.http_failure(&response, error.as_ref().ok())
1399 {
1400 sleep(d).await;
1401 continue;
1402 }
1403
1404 dlg.finished(false);
1405
1406 return Err(match error {
1407 Ok(value) => common::Error::BadRequest(value),
1408 _ => common::Error::Failure(response),
1409 });
1410 }
1411 let response = {
1412 let bytes = common::to_bytes(body).await.unwrap_or_default();
1413 let encoded = common::to_string(&bytes);
1414 match serde_json::from_str(&encoded) {
1415 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1416 Err(error) => {
1417 dlg.response_json_decode_error(&encoded, &error);
1418 return Err(common::Error::JsonDecodeError(
1419 encoded.to_string(),
1420 error,
1421 ));
1422 }
1423 }
1424 };
1425
1426 dlg.finished(true);
1427 return Ok(response);
1428 }
1429 }
1430 }
1431 }
1432
1433 /// The project under which the queue lies.
1434 ///
1435 /// Sets the *project* path property to the given value.
1436 ///
1437 /// Even though the property as already been set when instantiating this call,
1438 /// we provide this method for API completeness.
1439 pub fn project(mut self, new_value: &str) -> TaskGetCall<'a, C> {
1440 self._project = new_value.to_string();
1441 self
1442 }
1443 /// The taskqueue in which the task belongs.
1444 ///
1445 /// Sets the *taskqueue* path property to the given value.
1446 ///
1447 /// Even though the property as already been set when instantiating this call,
1448 /// we provide this method for API completeness.
1449 pub fn taskqueue(mut self, new_value: &str) -> TaskGetCall<'a, C> {
1450 self._taskqueue = new_value.to_string();
1451 self
1452 }
1453 /// The task to get properties of.
1454 ///
1455 /// Sets the *task* path property to the given value.
1456 ///
1457 /// Even though the property as already been set when instantiating this call,
1458 /// we provide this method for API completeness.
1459 pub fn task(mut self, new_value: &str) -> TaskGetCall<'a, C> {
1460 self._task = new_value.to_string();
1461 self
1462 }
1463 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1464 /// while executing the actual API request.
1465 ///
1466 /// ````text
1467 /// It should be used to handle progress information, and to implement a certain level of resilience.
1468 /// ````
1469 ///
1470 /// Sets the *delegate* property to the given value.
1471 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> TaskGetCall<'a, C> {
1472 self._delegate = Some(new_value);
1473 self
1474 }
1475
1476 /// Set any additional parameter of the query string used in the request.
1477 /// It should be used to set parameters which are not yet available through their own
1478 /// setters.
1479 ///
1480 /// Please note that this method must not be used to set any of the known parameters
1481 /// which have their own setter method. If done anyway, the request will fail.
1482 ///
1483 /// # Additional Parameters
1484 ///
1485 /// * *alt* (query-string) - Data format for the response.
1486 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1487 /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
1488 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1489 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1490 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.
1491 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
1492 pub fn param<T>(mut self, name: T, value: T) -> TaskGetCall<'a, C>
1493 where
1494 T: AsRef<str>,
1495 {
1496 self._additional_params
1497 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1498 self
1499 }
1500
1501 /// Identifies the authorization scope for the method you are building.
1502 ///
1503 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1504 /// [`Scope::Full`].
1505 ///
1506 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1507 /// tokens for more than one scope.
1508 ///
1509 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1510 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1511 /// sufficient, a read-write scope will do as well.
1512 pub fn add_scope<St>(mut self, scope: St) -> TaskGetCall<'a, C>
1513 where
1514 St: AsRef<str>,
1515 {
1516 self._scopes.insert(String::from(scope.as_ref()));
1517 self
1518 }
1519 /// Identifies the authorization scope(s) for the method you are building.
1520 ///
1521 /// See [`Self::add_scope()`] for details.
1522 pub fn add_scopes<I, St>(mut self, scopes: I) -> TaskGetCall<'a, C>
1523 where
1524 I: IntoIterator<Item = St>,
1525 St: AsRef<str>,
1526 {
1527 self._scopes
1528 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1529 self
1530 }
1531
1532 /// Removes all scopes, and no default scope will be used either.
1533 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1534 /// for details).
1535 pub fn clear_scopes(mut self) -> TaskGetCall<'a, C> {
1536 self._scopes.clear();
1537 self
1538 }
1539}
1540
1541/// Insert a new task in a TaskQueue
1542///
1543/// A builder for the *insert* method supported by a *task* resource.
1544/// It is not used directly, but through a [`TaskMethods`] instance.
1545///
1546/// # Example
1547///
1548/// Instantiate a resource method builder
1549///
1550/// ```test_harness,no_run
1551/// # extern crate hyper;
1552/// # extern crate hyper_rustls;
1553/// # extern crate google_taskqueue1_beta2 as taskqueue1_beta2;
1554/// use taskqueue1_beta2::api::Task;
1555/// # async fn dox() {
1556/// # use taskqueue1_beta2::{Taskqueue, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1557///
1558/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1559/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
1560/// # secret,
1561/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1562/// # ).build().await.unwrap();
1563///
1564/// # let client = hyper_util::client::legacy::Client::builder(
1565/// # hyper_util::rt::TokioExecutor::new()
1566/// # )
1567/// # .build(
1568/// # hyper_rustls::HttpsConnectorBuilder::new()
1569/// # .with_native_roots()
1570/// # .unwrap()
1571/// # .https_or_http()
1572/// # .enable_http1()
1573/// # .build()
1574/// # );
1575/// # let mut hub = Taskqueue::new(client, auth);
1576/// // As the method needs a request, you would usually fill it with the desired information
1577/// // into the respective structure. Some of the parts shown here might not be applicable !
1578/// // Values shown here are possibly random and not representative !
1579/// let mut req = Task::default();
1580///
1581/// // You can configure optional parameters by calling the respective setters at will, and
1582/// // execute the final call using `doit()`.
1583/// // Values shown here are possibly random and not representative !
1584/// let result = hub.tasks().insert(req, "project", "taskqueue")
1585/// .doit().await;
1586/// # }
1587/// ```
1588pub struct TaskInsertCall<'a, C>
1589where
1590 C: 'a,
1591{
1592 hub: &'a Taskqueue<C>,
1593 _request: Task,
1594 _project: String,
1595 _taskqueue: String,
1596 _delegate: Option<&'a mut dyn common::Delegate>,
1597 _additional_params: HashMap<String, String>,
1598 _scopes: BTreeSet<String>,
1599}
1600
1601impl<'a, C> common::CallBuilder for TaskInsertCall<'a, C> {}
1602
1603impl<'a, C> TaskInsertCall<'a, C>
1604where
1605 C: common::Connector,
1606{
1607 /// Perform the operation you have build so far.
1608 pub async fn doit(mut self) -> common::Result<(common::Response, Task)> {
1609 use std::borrow::Cow;
1610 use std::io::{Read, Seek};
1611
1612 use common::{url::Params, ToParts};
1613 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1614
1615 let mut dd = common::DefaultDelegate;
1616 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1617 dlg.begin(common::MethodInfo {
1618 id: "taskqueue.tasks.insert",
1619 http_method: hyper::Method::POST,
1620 });
1621
1622 for &field in ["alt", "project", "taskqueue"].iter() {
1623 if self._additional_params.contains_key(field) {
1624 dlg.finished(false);
1625 return Err(common::Error::FieldClash(field));
1626 }
1627 }
1628
1629 let mut params = Params::with_capacity(5 + self._additional_params.len());
1630 params.push("project", self._project);
1631 params.push("taskqueue", self._taskqueue);
1632
1633 params.extend(self._additional_params.iter());
1634
1635 params.push("alt", "json");
1636 let mut url = self.hub._base_url.clone() + "{project}/taskqueues/{taskqueue}/tasks";
1637 if self._scopes.is_empty() {
1638 self._scopes.insert(Scope::Full.as_ref().to_string());
1639 }
1640
1641 #[allow(clippy::single_element_loop)]
1642 for &(find_this, param_name) in
1643 [("{project}", "project"), ("{taskqueue}", "taskqueue")].iter()
1644 {
1645 url = params.uri_replacement(url, param_name, find_this, false);
1646 }
1647 {
1648 let to_remove = ["taskqueue", "project"];
1649 params.remove_params(&to_remove);
1650 }
1651
1652 let url = params.parse_with_url(&url);
1653
1654 let mut json_mime_type = mime::APPLICATION_JSON;
1655 let mut request_value_reader = {
1656 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
1657 common::remove_json_null_values(&mut value);
1658 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
1659 serde_json::to_writer(&mut dst, &value).unwrap();
1660 dst
1661 };
1662 let request_size = request_value_reader
1663 .seek(std::io::SeekFrom::End(0))
1664 .unwrap();
1665 request_value_reader
1666 .seek(std::io::SeekFrom::Start(0))
1667 .unwrap();
1668
1669 loop {
1670 let token = match self
1671 .hub
1672 .auth
1673 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1674 .await
1675 {
1676 Ok(token) => token,
1677 Err(e) => match dlg.token(e) {
1678 Ok(token) => token,
1679 Err(e) => {
1680 dlg.finished(false);
1681 return Err(common::Error::MissingToken(e));
1682 }
1683 },
1684 };
1685 request_value_reader
1686 .seek(std::io::SeekFrom::Start(0))
1687 .unwrap();
1688 let mut req_result = {
1689 let client = &self.hub.client;
1690 dlg.pre_request();
1691 let mut req_builder = hyper::Request::builder()
1692 .method(hyper::Method::POST)
1693 .uri(url.as_str())
1694 .header(USER_AGENT, self.hub._user_agent.clone());
1695
1696 if let Some(token) = token.as_ref() {
1697 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1698 }
1699
1700 let request = req_builder
1701 .header(CONTENT_TYPE, json_mime_type.to_string())
1702 .header(CONTENT_LENGTH, request_size as u64)
1703 .body(common::to_body(
1704 request_value_reader.get_ref().clone().into(),
1705 ));
1706
1707 client.request(request.unwrap()).await
1708 };
1709
1710 match req_result {
1711 Err(err) => {
1712 if let common::Retry::After(d) = dlg.http_error(&err) {
1713 sleep(d).await;
1714 continue;
1715 }
1716 dlg.finished(false);
1717 return Err(common::Error::HttpError(err));
1718 }
1719 Ok(res) => {
1720 let (mut parts, body) = res.into_parts();
1721 let mut body = common::Body::new(body);
1722 if !parts.status.is_success() {
1723 let bytes = common::to_bytes(body).await.unwrap_or_default();
1724 let error = serde_json::from_str(&common::to_string(&bytes));
1725 let response = common::to_response(parts, bytes.into());
1726
1727 if let common::Retry::After(d) =
1728 dlg.http_failure(&response, error.as_ref().ok())
1729 {
1730 sleep(d).await;
1731 continue;
1732 }
1733
1734 dlg.finished(false);
1735
1736 return Err(match error {
1737 Ok(value) => common::Error::BadRequest(value),
1738 _ => common::Error::Failure(response),
1739 });
1740 }
1741 let response = {
1742 let bytes = common::to_bytes(body).await.unwrap_or_default();
1743 let encoded = common::to_string(&bytes);
1744 match serde_json::from_str(&encoded) {
1745 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1746 Err(error) => {
1747 dlg.response_json_decode_error(&encoded, &error);
1748 return Err(common::Error::JsonDecodeError(
1749 encoded.to_string(),
1750 error,
1751 ));
1752 }
1753 }
1754 };
1755
1756 dlg.finished(true);
1757 return Ok(response);
1758 }
1759 }
1760 }
1761 }
1762
1763 ///
1764 /// Sets the *request* property to the given value.
1765 ///
1766 /// Even though the property as already been set when instantiating this call,
1767 /// we provide this method for API completeness.
1768 pub fn request(mut self, new_value: Task) -> TaskInsertCall<'a, C> {
1769 self._request = new_value;
1770 self
1771 }
1772 /// The project under which the queue lies
1773 ///
1774 /// Sets the *project* path property to the given value.
1775 ///
1776 /// Even though the property as already been set when instantiating this call,
1777 /// we provide this method for API completeness.
1778 pub fn project(mut self, new_value: &str) -> TaskInsertCall<'a, C> {
1779 self._project = new_value.to_string();
1780 self
1781 }
1782 /// The taskqueue to insert the task into
1783 ///
1784 /// Sets the *taskqueue* path property to the given value.
1785 ///
1786 /// Even though the property as already been set when instantiating this call,
1787 /// we provide this method for API completeness.
1788 pub fn taskqueue(mut self, new_value: &str) -> TaskInsertCall<'a, C> {
1789 self._taskqueue = new_value.to_string();
1790 self
1791 }
1792 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1793 /// while executing the actual API request.
1794 ///
1795 /// ````text
1796 /// It should be used to handle progress information, and to implement a certain level of resilience.
1797 /// ````
1798 ///
1799 /// Sets the *delegate* property to the given value.
1800 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> TaskInsertCall<'a, C> {
1801 self._delegate = Some(new_value);
1802 self
1803 }
1804
1805 /// Set any additional parameter of the query string used in the request.
1806 /// It should be used to set parameters which are not yet available through their own
1807 /// setters.
1808 ///
1809 /// Please note that this method must not be used to set any of the known parameters
1810 /// which have their own setter method. If done anyway, the request will fail.
1811 ///
1812 /// # Additional Parameters
1813 ///
1814 /// * *alt* (query-string) - Data format for the response.
1815 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1816 /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
1817 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1818 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1819 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.
1820 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
1821 pub fn param<T>(mut self, name: T, value: T) -> TaskInsertCall<'a, C>
1822 where
1823 T: AsRef<str>,
1824 {
1825 self._additional_params
1826 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1827 self
1828 }
1829
1830 /// Identifies the authorization scope for the method you are building.
1831 ///
1832 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1833 /// [`Scope::Full`].
1834 ///
1835 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1836 /// tokens for more than one scope.
1837 ///
1838 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1839 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1840 /// sufficient, a read-write scope will do as well.
1841 pub fn add_scope<St>(mut self, scope: St) -> TaskInsertCall<'a, C>
1842 where
1843 St: AsRef<str>,
1844 {
1845 self._scopes.insert(String::from(scope.as_ref()));
1846 self
1847 }
1848 /// Identifies the authorization scope(s) for the method you are building.
1849 ///
1850 /// See [`Self::add_scope()`] for details.
1851 pub fn add_scopes<I, St>(mut self, scopes: I) -> TaskInsertCall<'a, C>
1852 where
1853 I: IntoIterator<Item = St>,
1854 St: AsRef<str>,
1855 {
1856 self._scopes
1857 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1858 self
1859 }
1860
1861 /// Removes all scopes, and no default scope will be used either.
1862 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1863 /// for details).
1864 pub fn clear_scopes(mut self) -> TaskInsertCall<'a, C> {
1865 self._scopes.clear();
1866 self
1867 }
1868}
1869
1870/// Lease 1 or more tasks from a TaskQueue.
1871///
1872/// A builder for the *lease* method supported by a *task* resource.
1873/// It is not used directly, but through a [`TaskMethods`] instance.
1874///
1875/// # Example
1876///
1877/// Instantiate a resource method builder
1878///
1879/// ```test_harness,no_run
1880/// # extern crate hyper;
1881/// # extern crate hyper_rustls;
1882/// # extern crate google_taskqueue1_beta2 as taskqueue1_beta2;
1883/// # async fn dox() {
1884/// # use taskqueue1_beta2::{Taskqueue, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1885///
1886/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1887/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
1888/// # secret,
1889/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1890/// # ).build().await.unwrap();
1891///
1892/// # let client = hyper_util::client::legacy::Client::builder(
1893/// # hyper_util::rt::TokioExecutor::new()
1894/// # )
1895/// # .build(
1896/// # hyper_rustls::HttpsConnectorBuilder::new()
1897/// # .with_native_roots()
1898/// # .unwrap()
1899/// # .https_or_http()
1900/// # .enable_http1()
1901/// # .build()
1902/// # );
1903/// # let mut hub = Taskqueue::new(client, auth);
1904/// // You can configure optional parameters by calling the respective setters at will, and
1905/// // execute the final call using `doit()`.
1906/// // Values shown here are possibly random and not representative !
1907/// let result = hub.tasks().lease("project", "taskqueue", -99, -56)
1908/// .tag("eos")
1909/// .group_by_tag(false)
1910/// .doit().await;
1911/// # }
1912/// ```
1913pub struct TaskLeaseCall<'a, C>
1914where
1915 C: 'a,
1916{
1917 hub: &'a Taskqueue<C>,
1918 _project: String,
1919 _taskqueue: String,
1920 _num_tasks: i32,
1921 _lease_secs: i32,
1922 _tag: Option<String>,
1923 _group_by_tag: Option<bool>,
1924 _delegate: Option<&'a mut dyn common::Delegate>,
1925 _additional_params: HashMap<String, String>,
1926 _scopes: BTreeSet<String>,
1927}
1928
1929impl<'a, C> common::CallBuilder for TaskLeaseCall<'a, C> {}
1930
1931impl<'a, C> TaskLeaseCall<'a, C>
1932where
1933 C: common::Connector,
1934{
1935 /// Perform the operation you have build so far.
1936 pub async fn doit(mut self) -> common::Result<(common::Response, Tasks)> {
1937 use std::borrow::Cow;
1938 use std::io::{Read, Seek};
1939
1940 use common::{url::Params, ToParts};
1941 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1942
1943 let mut dd = common::DefaultDelegate;
1944 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1945 dlg.begin(common::MethodInfo {
1946 id: "taskqueue.tasks.lease",
1947 http_method: hyper::Method::POST,
1948 });
1949
1950 for &field in [
1951 "alt",
1952 "project",
1953 "taskqueue",
1954 "numTasks",
1955 "leaseSecs",
1956 "tag",
1957 "groupByTag",
1958 ]
1959 .iter()
1960 {
1961 if self._additional_params.contains_key(field) {
1962 dlg.finished(false);
1963 return Err(common::Error::FieldClash(field));
1964 }
1965 }
1966
1967 let mut params = Params::with_capacity(8 + self._additional_params.len());
1968 params.push("project", self._project);
1969 params.push("taskqueue", self._taskqueue);
1970 params.push("numTasks", self._num_tasks.to_string());
1971 params.push("leaseSecs", self._lease_secs.to_string());
1972 if let Some(value) = self._tag.as_ref() {
1973 params.push("tag", value);
1974 }
1975 if let Some(value) = self._group_by_tag.as_ref() {
1976 params.push("groupByTag", value.to_string());
1977 }
1978
1979 params.extend(self._additional_params.iter());
1980
1981 params.push("alt", "json");
1982 let mut url = self.hub._base_url.clone() + "{project}/taskqueues/{taskqueue}/tasks/lease";
1983 if self._scopes.is_empty() {
1984 self._scopes.insert(Scope::Full.as_ref().to_string());
1985 }
1986
1987 #[allow(clippy::single_element_loop)]
1988 for &(find_this, param_name) in
1989 [("{project}", "project"), ("{taskqueue}", "taskqueue")].iter()
1990 {
1991 url = params.uri_replacement(url, param_name, find_this, false);
1992 }
1993 {
1994 let to_remove = ["taskqueue", "project"];
1995 params.remove_params(&to_remove);
1996 }
1997
1998 let url = params.parse_with_url(&url);
1999
2000 loop {
2001 let token = match self
2002 .hub
2003 .auth
2004 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2005 .await
2006 {
2007 Ok(token) => token,
2008 Err(e) => match dlg.token(e) {
2009 Ok(token) => token,
2010 Err(e) => {
2011 dlg.finished(false);
2012 return Err(common::Error::MissingToken(e));
2013 }
2014 },
2015 };
2016 let mut req_result = {
2017 let client = &self.hub.client;
2018 dlg.pre_request();
2019 let mut req_builder = hyper::Request::builder()
2020 .method(hyper::Method::POST)
2021 .uri(url.as_str())
2022 .header(USER_AGENT, self.hub._user_agent.clone());
2023
2024 if let Some(token) = token.as_ref() {
2025 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2026 }
2027
2028 let request = req_builder
2029 .header(CONTENT_LENGTH, 0_u64)
2030 .body(common::to_body::<String>(None));
2031
2032 client.request(request.unwrap()).await
2033 };
2034
2035 match req_result {
2036 Err(err) => {
2037 if let common::Retry::After(d) = dlg.http_error(&err) {
2038 sleep(d).await;
2039 continue;
2040 }
2041 dlg.finished(false);
2042 return Err(common::Error::HttpError(err));
2043 }
2044 Ok(res) => {
2045 let (mut parts, body) = res.into_parts();
2046 let mut body = common::Body::new(body);
2047 if !parts.status.is_success() {
2048 let bytes = common::to_bytes(body).await.unwrap_or_default();
2049 let error = serde_json::from_str(&common::to_string(&bytes));
2050 let response = common::to_response(parts, bytes.into());
2051
2052 if let common::Retry::After(d) =
2053 dlg.http_failure(&response, error.as_ref().ok())
2054 {
2055 sleep(d).await;
2056 continue;
2057 }
2058
2059 dlg.finished(false);
2060
2061 return Err(match error {
2062 Ok(value) => common::Error::BadRequest(value),
2063 _ => common::Error::Failure(response),
2064 });
2065 }
2066 let response = {
2067 let bytes = common::to_bytes(body).await.unwrap_or_default();
2068 let encoded = common::to_string(&bytes);
2069 match serde_json::from_str(&encoded) {
2070 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
2071 Err(error) => {
2072 dlg.response_json_decode_error(&encoded, &error);
2073 return Err(common::Error::JsonDecodeError(
2074 encoded.to_string(),
2075 error,
2076 ));
2077 }
2078 }
2079 };
2080
2081 dlg.finished(true);
2082 return Ok(response);
2083 }
2084 }
2085 }
2086 }
2087
2088 /// The project under which the queue lies.
2089 ///
2090 /// Sets the *project* path property to the given value.
2091 ///
2092 /// Even though the property as already been set when instantiating this call,
2093 /// we provide this method for API completeness.
2094 pub fn project(mut self, new_value: &str) -> TaskLeaseCall<'a, C> {
2095 self._project = new_value.to_string();
2096 self
2097 }
2098 /// The taskqueue to lease a task from.
2099 ///
2100 /// Sets the *taskqueue* path property to the given value.
2101 ///
2102 /// Even though the property as already been set when instantiating this call,
2103 /// we provide this method for API completeness.
2104 pub fn taskqueue(mut self, new_value: &str) -> TaskLeaseCall<'a, C> {
2105 self._taskqueue = new_value.to_string();
2106 self
2107 }
2108 /// The number of tasks to lease.
2109 ///
2110 /// Sets the *num tasks* query property to the given value.
2111 ///
2112 /// Even though the property as already been set when instantiating this call,
2113 /// we provide this method for API completeness.
2114 pub fn num_tasks(mut self, new_value: i32) -> TaskLeaseCall<'a, C> {
2115 self._num_tasks = new_value;
2116 self
2117 }
2118 /// The lease in seconds.
2119 ///
2120 /// Sets the *lease secs* query property to the given value.
2121 ///
2122 /// Even though the property as already been set when instantiating this call,
2123 /// we provide this method for API completeness.
2124 pub fn lease_secs(mut self, new_value: i32) -> TaskLeaseCall<'a, C> {
2125 self._lease_secs = new_value;
2126 self
2127 }
2128 /// The tag allowed for tasks in the response. Must only be specified if group_by_tag is true. If group_by_tag is true and tag is not specified the tag will be that of the oldest task by eta, i.e. the first available tag
2129 ///
2130 /// Sets the *tag* query property to the given value.
2131 pub fn tag(mut self, new_value: &str) -> TaskLeaseCall<'a, C> {
2132 self._tag = Some(new_value.to_string());
2133 self
2134 }
2135 /// When true, all returned tasks will have the same tag
2136 ///
2137 /// Sets the *group by tag* query property to the given value.
2138 pub fn group_by_tag(mut self, new_value: bool) -> TaskLeaseCall<'a, C> {
2139 self._group_by_tag = Some(new_value);
2140 self
2141 }
2142 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2143 /// while executing the actual API request.
2144 ///
2145 /// ````text
2146 /// It should be used to handle progress information, and to implement a certain level of resilience.
2147 /// ````
2148 ///
2149 /// Sets the *delegate* property to the given value.
2150 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> TaskLeaseCall<'a, C> {
2151 self._delegate = Some(new_value);
2152 self
2153 }
2154
2155 /// Set any additional parameter of the query string used in the request.
2156 /// It should be used to set parameters which are not yet available through their own
2157 /// setters.
2158 ///
2159 /// Please note that this method must not be used to set any of the known parameters
2160 /// which have their own setter method. If done anyway, the request will fail.
2161 ///
2162 /// # Additional Parameters
2163 ///
2164 /// * *alt* (query-string) - Data format for the response.
2165 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2166 /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
2167 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2168 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2169 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.
2170 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
2171 pub fn param<T>(mut self, name: T, value: T) -> TaskLeaseCall<'a, C>
2172 where
2173 T: AsRef<str>,
2174 {
2175 self._additional_params
2176 .insert(name.as_ref().to_string(), value.as_ref().to_string());
2177 self
2178 }
2179
2180 /// Identifies the authorization scope for the method you are building.
2181 ///
2182 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2183 /// [`Scope::Full`].
2184 ///
2185 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2186 /// tokens for more than one scope.
2187 ///
2188 /// Usually there is more than one suitable scope to authorize an operation, some of which may
2189 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2190 /// sufficient, a read-write scope will do as well.
2191 pub fn add_scope<St>(mut self, scope: St) -> TaskLeaseCall<'a, C>
2192 where
2193 St: AsRef<str>,
2194 {
2195 self._scopes.insert(String::from(scope.as_ref()));
2196 self
2197 }
2198 /// Identifies the authorization scope(s) for the method you are building.
2199 ///
2200 /// See [`Self::add_scope()`] for details.
2201 pub fn add_scopes<I, St>(mut self, scopes: I) -> TaskLeaseCall<'a, C>
2202 where
2203 I: IntoIterator<Item = St>,
2204 St: AsRef<str>,
2205 {
2206 self._scopes
2207 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2208 self
2209 }
2210
2211 /// Removes all scopes, and no default scope will be used either.
2212 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2213 /// for details).
2214 pub fn clear_scopes(mut self) -> TaskLeaseCall<'a, C> {
2215 self._scopes.clear();
2216 self
2217 }
2218}
2219
2220/// List Tasks in a TaskQueue
2221///
2222/// A builder for the *list* method supported by a *task* resource.
2223/// It is not used directly, but through a [`TaskMethods`] instance.
2224///
2225/// # Example
2226///
2227/// Instantiate a resource method builder
2228///
2229/// ```test_harness,no_run
2230/// # extern crate hyper;
2231/// # extern crate hyper_rustls;
2232/// # extern crate google_taskqueue1_beta2 as taskqueue1_beta2;
2233/// # async fn dox() {
2234/// # use taskqueue1_beta2::{Taskqueue, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2235///
2236/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2237/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
2238/// # secret,
2239/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2240/// # ).build().await.unwrap();
2241///
2242/// # let client = hyper_util::client::legacy::Client::builder(
2243/// # hyper_util::rt::TokioExecutor::new()
2244/// # )
2245/// # .build(
2246/// # hyper_rustls::HttpsConnectorBuilder::new()
2247/// # .with_native_roots()
2248/// # .unwrap()
2249/// # .https_or_http()
2250/// # .enable_http1()
2251/// # .build()
2252/// # );
2253/// # let mut hub = Taskqueue::new(client, auth);
2254/// // You can configure optional parameters by calling the respective setters at will, and
2255/// // execute the final call using `doit()`.
2256/// // Values shown here are possibly random and not representative !
2257/// let result = hub.tasks().list("project", "taskqueue")
2258/// .doit().await;
2259/// # }
2260/// ```
2261pub struct TaskListCall<'a, C>
2262where
2263 C: 'a,
2264{
2265 hub: &'a Taskqueue<C>,
2266 _project: String,
2267 _taskqueue: String,
2268 _delegate: Option<&'a mut dyn common::Delegate>,
2269 _additional_params: HashMap<String, String>,
2270 _scopes: BTreeSet<String>,
2271}
2272
2273impl<'a, C> common::CallBuilder for TaskListCall<'a, C> {}
2274
2275impl<'a, C> TaskListCall<'a, C>
2276where
2277 C: common::Connector,
2278{
2279 /// Perform the operation you have build so far.
2280 pub async fn doit(mut self) -> common::Result<(common::Response, Tasks2)> {
2281 use std::borrow::Cow;
2282 use std::io::{Read, Seek};
2283
2284 use common::{url::Params, ToParts};
2285 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2286
2287 let mut dd = common::DefaultDelegate;
2288 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2289 dlg.begin(common::MethodInfo {
2290 id: "taskqueue.tasks.list",
2291 http_method: hyper::Method::GET,
2292 });
2293
2294 for &field in ["alt", "project", "taskqueue"].iter() {
2295 if self._additional_params.contains_key(field) {
2296 dlg.finished(false);
2297 return Err(common::Error::FieldClash(field));
2298 }
2299 }
2300
2301 let mut params = Params::with_capacity(4 + self._additional_params.len());
2302 params.push("project", self._project);
2303 params.push("taskqueue", self._taskqueue);
2304
2305 params.extend(self._additional_params.iter());
2306
2307 params.push("alt", "json");
2308 let mut url = self.hub._base_url.clone() + "{project}/taskqueues/{taskqueue}/tasks";
2309 if self._scopes.is_empty() {
2310 self._scopes.insert(Scope::Full.as_ref().to_string());
2311 }
2312
2313 #[allow(clippy::single_element_loop)]
2314 for &(find_this, param_name) in
2315 [("{project}", "project"), ("{taskqueue}", "taskqueue")].iter()
2316 {
2317 url = params.uri_replacement(url, param_name, find_this, false);
2318 }
2319 {
2320 let to_remove = ["taskqueue", "project"];
2321 params.remove_params(&to_remove);
2322 }
2323
2324 let url = params.parse_with_url(&url);
2325
2326 loop {
2327 let token = match self
2328 .hub
2329 .auth
2330 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2331 .await
2332 {
2333 Ok(token) => token,
2334 Err(e) => match dlg.token(e) {
2335 Ok(token) => token,
2336 Err(e) => {
2337 dlg.finished(false);
2338 return Err(common::Error::MissingToken(e));
2339 }
2340 },
2341 };
2342 let mut req_result = {
2343 let client = &self.hub.client;
2344 dlg.pre_request();
2345 let mut req_builder = hyper::Request::builder()
2346 .method(hyper::Method::GET)
2347 .uri(url.as_str())
2348 .header(USER_AGENT, self.hub._user_agent.clone());
2349
2350 if let Some(token) = token.as_ref() {
2351 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2352 }
2353
2354 let request = req_builder
2355 .header(CONTENT_LENGTH, 0_u64)
2356 .body(common::to_body::<String>(None));
2357
2358 client.request(request.unwrap()).await
2359 };
2360
2361 match req_result {
2362 Err(err) => {
2363 if let common::Retry::After(d) = dlg.http_error(&err) {
2364 sleep(d).await;
2365 continue;
2366 }
2367 dlg.finished(false);
2368 return Err(common::Error::HttpError(err));
2369 }
2370 Ok(res) => {
2371 let (mut parts, body) = res.into_parts();
2372 let mut body = common::Body::new(body);
2373 if !parts.status.is_success() {
2374 let bytes = common::to_bytes(body).await.unwrap_or_default();
2375 let error = serde_json::from_str(&common::to_string(&bytes));
2376 let response = common::to_response(parts, bytes.into());
2377
2378 if let common::Retry::After(d) =
2379 dlg.http_failure(&response, error.as_ref().ok())
2380 {
2381 sleep(d).await;
2382 continue;
2383 }
2384
2385 dlg.finished(false);
2386
2387 return Err(match error {
2388 Ok(value) => common::Error::BadRequest(value),
2389 _ => common::Error::Failure(response),
2390 });
2391 }
2392 let response = {
2393 let bytes = common::to_bytes(body).await.unwrap_or_default();
2394 let encoded = common::to_string(&bytes);
2395 match serde_json::from_str(&encoded) {
2396 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
2397 Err(error) => {
2398 dlg.response_json_decode_error(&encoded, &error);
2399 return Err(common::Error::JsonDecodeError(
2400 encoded.to_string(),
2401 error,
2402 ));
2403 }
2404 }
2405 };
2406
2407 dlg.finished(true);
2408 return Ok(response);
2409 }
2410 }
2411 }
2412 }
2413
2414 /// The project under which the queue lies.
2415 ///
2416 /// Sets the *project* path property to the given value.
2417 ///
2418 /// Even though the property as already been set when instantiating this call,
2419 /// we provide this method for API completeness.
2420 pub fn project(mut self, new_value: &str) -> TaskListCall<'a, C> {
2421 self._project = new_value.to_string();
2422 self
2423 }
2424 /// The id of the taskqueue to list tasks from.
2425 ///
2426 /// Sets the *taskqueue* path property to the given value.
2427 ///
2428 /// Even though the property as already been set when instantiating this call,
2429 /// we provide this method for API completeness.
2430 pub fn taskqueue(mut self, new_value: &str) -> TaskListCall<'a, C> {
2431 self._taskqueue = new_value.to_string();
2432 self
2433 }
2434 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2435 /// while executing the actual API request.
2436 ///
2437 /// ````text
2438 /// It should be used to handle progress information, and to implement a certain level of resilience.
2439 /// ````
2440 ///
2441 /// Sets the *delegate* property to the given value.
2442 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> TaskListCall<'a, C> {
2443 self._delegate = Some(new_value);
2444 self
2445 }
2446
2447 /// Set any additional parameter of the query string used in the request.
2448 /// It should be used to set parameters which are not yet available through their own
2449 /// setters.
2450 ///
2451 /// Please note that this method must not be used to set any of the known parameters
2452 /// which have their own setter method. If done anyway, the request will fail.
2453 ///
2454 /// # Additional Parameters
2455 ///
2456 /// * *alt* (query-string) - Data format for the response.
2457 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2458 /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
2459 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2460 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2461 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.
2462 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
2463 pub fn param<T>(mut self, name: T, value: T) -> TaskListCall<'a, C>
2464 where
2465 T: AsRef<str>,
2466 {
2467 self._additional_params
2468 .insert(name.as_ref().to_string(), value.as_ref().to_string());
2469 self
2470 }
2471
2472 /// Identifies the authorization scope for the method you are building.
2473 ///
2474 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2475 /// [`Scope::Full`].
2476 ///
2477 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2478 /// tokens for more than one scope.
2479 ///
2480 /// Usually there is more than one suitable scope to authorize an operation, some of which may
2481 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2482 /// sufficient, a read-write scope will do as well.
2483 pub fn add_scope<St>(mut self, scope: St) -> TaskListCall<'a, C>
2484 where
2485 St: AsRef<str>,
2486 {
2487 self._scopes.insert(String::from(scope.as_ref()));
2488 self
2489 }
2490 /// Identifies the authorization scope(s) for the method you are building.
2491 ///
2492 /// See [`Self::add_scope()`] for details.
2493 pub fn add_scopes<I, St>(mut self, scopes: I) -> TaskListCall<'a, C>
2494 where
2495 I: IntoIterator<Item = St>,
2496 St: AsRef<str>,
2497 {
2498 self._scopes
2499 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2500 self
2501 }
2502
2503 /// Removes all scopes, and no default scope will be used either.
2504 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2505 /// for details).
2506 pub fn clear_scopes(mut self) -> TaskListCall<'a, C> {
2507 self._scopes.clear();
2508 self
2509 }
2510}
2511
2512/// Update tasks that are leased out of a TaskQueue. This method supports patch semantics.
2513///
2514/// A builder for the *patch* method supported by a *task* resource.
2515/// It is not used directly, but through a [`TaskMethods`] instance.
2516///
2517/// # Example
2518///
2519/// Instantiate a resource method builder
2520///
2521/// ```test_harness,no_run
2522/// # extern crate hyper;
2523/// # extern crate hyper_rustls;
2524/// # extern crate google_taskqueue1_beta2 as taskqueue1_beta2;
2525/// use taskqueue1_beta2::api::Task;
2526/// # async fn dox() {
2527/// # use taskqueue1_beta2::{Taskqueue, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2528///
2529/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2530/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
2531/// # secret,
2532/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2533/// # ).build().await.unwrap();
2534///
2535/// # let client = hyper_util::client::legacy::Client::builder(
2536/// # hyper_util::rt::TokioExecutor::new()
2537/// # )
2538/// # .build(
2539/// # hyper_rustls::HttpsConnectorBuilder::new()
2540/// # .with_native_roots()
2541/// # .unwrap()
2542/// # .https_or_http()
2543/// # .enable_http1()
2544/// # .build()
2545/// # );
2546/// # let mut hub = Taskqueue::new(client, auth);
2547/// // As the method needs a request, you would usually fill it with the desired information
2548/// // into the respective structure. Some of the parts shown here might not be applicable !
2549/// // Values shown here are possibly random and not representative !
2550/// let mut req = Task::default();
2551///
2552/// // You can configure optional parameters by calling the respective setters at will, and
2553/// // execute the final call using `doit()`.
2554/// // Values shown here are possibly random and not representative !
2555/// let result = hub.tasks().patch(req, "project", "taskqueue", "task", -13)
2556/// .doit().await;
2557/// # }
2558/// ```
2559pub struct TaskPatchCall<'a, C>
2560where
2561 C: 'a,
2562{
2563 hub: &'a Taskqueue<C>,
2564 _request: Task,
2565 _project: String,
2566 _taskqueue: String,
2567 _task: String,
2568 _new_lease_seconds: i32,
2569 _delegate: Option<&'a mut dyn common::Delegate>,
2570 _additional_params: HashMap<String, String>,
2571 _scopes: BTreeSet<String>,
2572}
2573
2574impl<'a, C> common::CallBuilder for TaskPatchCall<'a, C> {}
2575
2576impl<'a, C> TaskPatchCall<'a, C>
2577where
2578 C: common::Connector,
2579{
2580 /// Perform the operation you have build so far.
2581 pub async fn doit(mut self) -> common::Result<(common::Response, Task)> {
2582 use std::borrow::Cow;
2583 use std::io::{Read, Seek};
2584
2585 use common::{url::Params, ToParts};
2586 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2587
2588 let mut dd = common::DefaultDelegate;
2589 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2590 dlg.begin(common::MethodInfo {
2591 id: "taskqueue.tasks.patch",
2592 http_method: hyper::Method::PATCH,
2593 });
2594
2595 for &field in ["alt", "project", "taskqueue", "task", "newLeaseSeconds"].iter() {
2596 if self._additional_params.contains_key(field) {
2597 dlg.finished(false);
2598 return Err(common::Error::FieldClash(field));
2599 }
2600 }
2601
2602 let mut params = Params::with_capacity(7 + self._additional_params.len());
2603 params.push("project", self._project);
2604 params.push("taskqueue", self._taskqueue);
2605 params.push("task", self._task);
2606 params.push("newLeaseSeconds", self._new_lease_seconds.to_string());
2607
2608 params.extend(self._additional_params.iter());
2609
2610 params.push("alt", "json");
2611 let mut url = self.hub._base_url.clone() + "{project}/taskqueues/{taskqueue}/tasks/{task}";
2612 if self._scopes.is_empty() {
2613 self._scopes.insert(Scope::Full.as_ref().to_string());
2614 }
2615
2616 #[allow(clippy::single_element_loop)]
2617 for &(find_this, param_name) in [
2618 ("{project}", "project"),
2619 ("{taskqueue}", "taskqueue"),
2620 ("{task}", "task"),
2621 ]
2622 .iter()
2623 {
2624 url = params.uri_replacement(url, param_name, find_this, false);
2625 }
2626 {
2627 let to_remove = ["task", "taskqueue", "project"];
2628 params.remove_params(&to_remove);
2629 }
2630
2631 let url = params.parse_with_url(&url);
2632
2633 let mut json_mime_type = mime::APPLICATION_JSON;
2634 let mut request_value_reader = {
2635 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
2636 common::remove_json_null_values(&mut value);
2637 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
2638 serde_json::to_writer(&mut dst, &value).unwrap();
2639 dst
2640 };
2641 let request_size = request_value_reader
2642 .seek(std::io::SeekFrom::End(0))
2643 .unwrap();
2644 request_value_reader
2645 .seek(std::io::SeekFrom::Start(0))
2646 .unwrap();
2647
2648 loop {
2649 let token = match self
2650 .hub
2651 .auth
2652 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2653 .await
2654 {
2655 Ok(token) => token,
2656 Err(e) => match dlg.token(e) {
2657 Ok(token) => token,
2658 Err(e) => {
2659 dlg.finished(false);
2660 return Err(common::Error::MissingToken(e));
2661 }
2662 },
2663 };
2664 request_value_reader
2665 .seek(std::io::SeekFrom::Start(0))
2666 .unwrap();
2667 let mut req_result = {
2668 let client = &self.hub.client;
2669 dlg.pre_request();
2670 let mut req_builder = hyper::Request::builder()
2671 .method(hyper::Method::PATCH)
2672 .uri(url.as_str())
2673 .header(USER_AGENT, self.hub._user_agent.clone());
2674
2675 if let Some(token) = token.as_ref() {
2676 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2677 }
2678
2679 let request = req_builder
2680 .header(CONTENT_TYPE, json_mime_type.to_string())
2681 .header(CONTENT_LENGTH, request_size as u64)
2682 .body(common::to_body(
2683 request_value_reader.get_ref().clone().into(),
2684 ));
2685
2686 client.request(request.unwrap()).await
2687 };
2688
2689 match req_result {
2690 Err(err) => {
2691 if let common::Retry::After(d) = dlg.http_error(&err) {
2692 sleep(d).await;
2693 continue;
2694 }
2695 dlg.finished(false);
2696 return Err(common::Error::HttpError(err));
2697 }
2698 Ok(res) => {
2699 let (mut parts, body) = res.into_parts();
2700 let mut body = common::Body::new(body);
2701 if !parts.status.is_success() {
2702 let bytes = common::to_bytes(body).await.unwrap_or_default();
2703 let error = serde_json::from_str(&common::to_string(&bytes));
2704 let response = common::to_response(parts, bytes.into());
2705
2706 if let common::Retry::After(d) =
2707 dlg.http_failure(&response, error.as_ref().ok())
2708 {
2709 sleep(d).await;
2710 continue;
2711 }
2712
2713 dlg.finished(false);
2714
2715 return Err(match error {
2716 Ok(value) => common::Error::BadRequest(value),
2717 _ => common::Error::Failure(response),
2718 });
2719 }
2720 let response = {
2721 let bytes = common::to_bytes(body).await.unwrap_or_default();
2722 let encoded = common::to_string(&bytes);
2723 match serde_json::from_str(&encoded) {
2724 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
2725 Err(error) => {
2726 dlg.response_json_decode_error(&encoded, &error);
2727 return Err(common::Error::JsonDecodeError(
2728 encoded.to_string(),
2729 error,
2730 ));
2731 }
2732 }
2733 };
2734
2735 dlg.finished(true);
2736 return Ok(response);
2737 }
2738 }
2739 }
2740 }
2741
2742 ///
2743 /// Sets the *request* property to the given value.
2744 ///
2745 /// Even though the property as already been set when instantiating this call,
2746 /// we provide this method for API completeness.
2747 pub fn request(mut self, new_value: Task) -> TaskPatchCall<'a, C> {
2748 self._request = new_value;
2749 self
2750 }
2751 /// The project under which the queue lies.
2752 ///
2753 /// Sets the *project* path property to the given value.
2754 ///
2755 /// Even though the property as already been set when instantiating this call,
2756 /// we provide this method for API completeness.
2757 pub fn project(mut self, new_value: &str) -> TaskPatchCall<'a, C> {
2758 self._project = new_value.to_string();
2759 self
2760 }
2761 ///
2762 /// Sets the *taskqueue* path property to the given value.
2763 ///
2764 /// Even though the property as already been set when instantiating this call,
2765 /// we provide this method for API completeness.
2766 pub fn taskqueue(mut self, new_value: &str) -> TaskPatchCall<'a, C> {
2767 self._taskqueue = new_value.to_string();
2768 self
2769 }
2770 ///
2771 /// Sets the *task* path property to the given value.
2772 ///
2773 /// Even though the property as already been set when instantiating this call,
2774 /// we provide this method for API completeness.
2775 pub fn task(mut self, new_value: &str) -> TaskPatchCall<'a, C> {
2776 self._task = new_value.to_string();
2777 self
2778 }
2779 /// The new lease in seconds.
2780 ///
2781 /// Sets the *new lease seconds* query property to the given value.
2782 ///
2783 /// Even though the property as already been set when instantiating this call,
2784 /// we provide this method for API completeness.
2785 pub fn new_lease_seconds(mut self, new_value: i32) -> TaskPatchCall<'a, C> {
2786 self._new_lease_seconds = new_value;
2787 self
2788 }
2789 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2790 /// while executing the actual API request.
2791 ///
2792 /// ````text
2793 /// It should be used to handle progress information, and to implement a certain level of resilience.
2794 /// ````
2795 ///
2796 /// Sets the *delegate* property to the given value.
2797 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> TaskPatchCall<'a, C> {
2798 self._delegate = Some(new_value);
2799 self
2800 }
2801
2802 /// Set any additional parameter of the query string used in the request.
2803 /// It should be used to set parameters which are not yet available through their own
2804 /// setters.
2805 ///
2806 /// Please note that this method must not be used to set any of the known parameters
2807 /// which have their own setter method. If done anyway, the request will fail.
2808 ///
2809 /// # Additional Parameters
2810 ///
2811 /// * *alt* (query-string) - Data format for the response.
2812 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2813 /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
2814 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2815 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2816 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.
2817 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
2818 pub fn param<T>(mut self, name: T, value: T) -> TaskPatchCall<'a, C>
2819 where
2820 T: AsRef<str>,
2821 {
2822 self._additional_params
2823 .insert(name.as_ref().to_string(), value.as_ref().to_string());
2824 self
2825 }
2826
2827 /// Identifies the authorization scope for the method you are building.
2828 ///
2829 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2830 /// [`Scope::Full`].
2831 ///
2832 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2833 /// tokens for more than one scope.
2834 ///
2835 /// Usually there is more than one suitable scope to authorize an operation, some of which may
2836 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2837 /// sufficient, a read-write scope will do as well.
2838 pub fn add_scope<St>(mut self, scope: St) -> TaskPatchCall<'a, C>
2839 where
2840 St: AsRef<str>,
2841 {
2842 self._scopes.insert(String::from(scope.as_ref()));
2843 self
2844 }
2845 /// Identifies the authorization scope(s) for the method you are building.
2846 ///
2847 /// See [`Self::add_scope()`] for details.
2848 pub fn add_scopes<I, St>(mut self, scopes: I) -> TaskPatchCall<'a, C>
2849 where
2850 I: IntoIterator<Item = St>,
2851 St: AsRef<str>,
2852 {
2853 self._scopes
2854 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2855 self
2856 }
2857
2858 /// Removes all scopes, and no default scope will be used either.
2859 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2860 /// for details).
2861 pub fn clear_scopes(mut self) -> TaskPatchCall<'a, C> {
2862 self._scopes.clear();
2863 self
2864 }
2865}
2866
2867/// Update tasks that are leased out of a TaskQueue.
2868///
2869/// A builder for the *update* method supported by a *task* resource.
2870/// It is not used directly, but through a [`TaskMethods`] instance.
2871///
2872/// # Example
2873///
2874/// Instantiate a resource method builder
2875///
2876/// ```test_harness,no_run
2877/// # extern crate hyper;
2878/// # extern crate hyper_rustls;
2879/// # extern crate google_taskqueue1_beta2 as taskqueue1_beta2;
2880/// use taskqueue1_beta2::api::Task;
2881/// # async fn dox() {
2882/// # use taskqueue1_beta2::{Taskqueue, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2883///
2884/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2885/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
2886/// # secret,
2887/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2888/// # ).build().await.unwrap();
2889///
2890/// # let client = hyper_util::client::legacy::Client::builder(
2891/// # hyper_util::rt::TokioExecutor::new()
2892/// # )
2893/// # .build(
2894/// # hyper_rustls::HttpsConnectorBuilder::new()
2895/// # .with_native_roots()
2896/// # .unwrap()
2897/// # .https_or_http()
2898/// # .enable_http1()
2899/// # .build()
2900/// # );
2901/// # let mut hub = Taskqueue::new(client, auth);
2902/// // As the method needs a request, you would usually fill it with the desired information
2903/// // into the respective structure. Some of the parts shown here might not be applicable !
2904/// // Values shown here are possibly random and not representative !
2905/// let mut req = Task::default();
2906///
2907/// // You can configure optional parameters by calling the respective setters at will, and
2908/// // execute the final call using `doit()`.
2909/// // Values shown here are possibly random and not representative !
2910/// let result = hub.tasks().update(req, "project", "taskqueue", "task", -68)
2911/// .doit().await;
2912/// # }
2913/// ```
2914pub struct TaskUpdateCall<'a, C>
2915where
2916 C: 'a,
2917{
2918 hub: &'a Taskqueue<C>,
2919 _request: Task,
2920 _project: String,
2921 _taskqueue: String,
2922 _task: String,
2923 _new_lease_seconds: i32,
2924 _delegate: Option<&'a mut dyn common::Delegate>,
2925 _additional_params: HashMap<String, String>,
2926 _scopes: BTreeSet<String>,
2927}
2928
2929impl<'a, C> common::CallBuilder for TaskUpdateCall<'a, C> {}
2930
2931impl<'a, C> TaskUpdateCall<'a, C>
2932where
2933 C: common::Connector,
2934{
2935 /// Perform the operation you have build so far.
2936 pub async fn doit(mut self) -> common::Result<(common::Response, Task)> {
2937 use std::borrow::Cow;
2938 use std::io::{Read, Seek};
2939
2940 use common::{url::Params, ToParts};
2941 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2942
2943 let mut dd = common::DefaultDelegate;
2944 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2945 dlg.begin(common::MethodInfo {
2946 id: "taskqueue.tasks.update",
2947 http_method: hyper::Method::POST,
2948 });
2949
2950 for &field in ["alt", "project", "taskqueue", "task", "newLeaseSeconds"].iter() {
2951 if self._additional_params.contains_key(field) {
2952 dlg.finished(false);
2953 return Err(common::Error::FieldClash(field));
2954 }
2955 }
2956
2957 let mut params = Params::with_capacity(7 + self._additional_params.len());
2958 params.push("project", self._project);
2959 params.push("taskqueue", self._taskqueue);
2960 params.push("task", self._task);
2961 params.push("newLeaseSeconds", self._new_lease_seconds.to_string());
2962
2963 params.extend(self._additional_params.iter());
2964
2965 params.push("alt", "json");
2966 let mut url = self.hub._base_url.clone() + "{project}/taskqueues/{taskqueue}/tasks/{task}";
2967 if self._scopes.is_empty() {
2968 self._scopes.insert(Scope::Full.as_ref().to_string());
2969 }
2970
2971 #[allow(clippy::single_element_loop)]
2972 for &(find_this, param_name) in [
2973 ("{project}", "project"),
2974 ("{taskqueue}", "taskqueue"),
2975 ("{task}", "task"),
2976 ]
2977 .iter()
2978 {
2979 url = params.uri_replacement(url, param_name, find_this, false);
2980 }
2981 {
2982 let to_remove = ["task", "taskqueue", "project"];
2983 params.remove_params(&to_remove);
2984 }
2985
2986 let url = params.parse_with_url(&url);
2987
2988 let mut json_mime_type = mime::APPLICATION_JSON;
2989 let mut request_value_reader = {
2990 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
2991 common::remove_json_null_values(&mut value);
2992 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
2993 serde_json::to_writer(&mut dst, &value).unwrap();
2994 dst
2995 };
2996 let request_size = request_value_reader
2997 .seek(std::io::SeekFrom::End(0))
2998 .unwrap();
2999 request_value_reader
3000 .seek(std::io::SeekFrom::Start(0))
3001 .unwrap();
3002
3003 loop {
3004 let token = match self
3005 .hub
3006 .auth
3007 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
3008 .await
3009 {
3010 Ok(token) => token,
3011 Err(e) => match dlg.token(e) {
3012 Ok(token) => token,
3013 Err(e) => {
3014 dlg.finished(false);
3015 return Err(common::Error::MissingToken(e));
3016 }
3017 },
3018 };
3019 request_value_reader
3020 .seek(std::io::SeekFrom::Start(0))
3021 .unwrap();
3022 let mut req_result = {
3023 let client = &self.hub.client;
3024 dlg.pre_request();
3025 let mut req_builder = hyper::Request::builder()
3026 .method(hyper::Method::POST)
3027 .uri(url.as_str())
3028 .header(USER_AGENT, self.hub._user_agent.clone());
3029
3030 if let Some(token) = token.as_ref() {
3031 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
3032 }
3033
3034 let request = req_builder
3035 .header(CONTENT_TYPE, json_mime_type.to_string())
3036 .header(CONTENT_LENGTH, request_size as u64)
3037 .body(common::to_body(
3038 request_value_reader.get_ref().clone().into(),
3039 ));
3040
3041 client.request(request.unwrap()).await
3042 };
3043
3044 match req_result {
3045 Err(err) => {
3046 if let common::Retry::After(d) = dlg.http_error(&err) {
3047 sleep(d).await;
3048 continue;
3049 }
3050 dlg.finished(false);
3051 return Err(common::Error::HttpError(err));
3052 }
3053 Ok(res) => {
3054 let (mut parts, body) = res.into_parts();
3055 let mut body = common::Body::new(body);
3056 if !parts.status.is_success() {
3057 let bytes = common::to_bytes(body).await.unwrap_or_default();
3058 let error = serde_json::from_str(&common::to_string(&bytes));
3059 let response = common::to_response(parts, bytes.into());
3060
3061 if let common::Retry::After(d) =
3062 dlg.http_failure(&response, error.as_ref().ok())
3063 {
3064 sleep(d).await;
3065 continue;
3066 }
3067
3068 dlg.finished(false);
3069
3070 return Err(match error {
3071 Ok(value) => common::Error::BadRequest(value),
3072 _ => common::Error::Failure(response),
3073 });
3074 }
3075 let response = {
3076 let bytes = common::to_bytes(body).await.unwrap_or_default();
3077 let encoded = common::to_string(&bytes);
3078 match serde_json::from_str(&encoded) {
3079 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
3080 Err(error) => {
3081 dlg.response_json_decode_error(&encoded, &error);
3082 return Err(common::Error::JsonDecodeError(
3083 encoded.to_string(),
3084 error,
3085 ));
3086 }
3087 }
3088 };
3089
3090 dlg.finished(true);
3091 return Ok(response);
3092 }
3093 }
3094 }
3095 }
3096
3097 ///
3098 /// Sets the *request* property to the given value.
3099 ///
3100 /// Even though the property as already been set when instantiating this call,
3101 /// we provide this method for API completeness.
3102 pub fn request(mut self, new_value: Task) -> TaskUpdateCall<'a, C> {
3103 self._request = new_value;
3104 self
3105 }
3106 /// The project under which the queue lies.
3107 ///
3108 /// Sets the *project* path property to the given value.
3109 ///
3110 /// Even though the property as already been set when instantiating this call,
3111 /// we provide this method for API completeness.
3112 pub fn project(mut self, new_value: &str) -> TaskUpdateCall<'a, C> {
3113 self._project = new_value.to_string();
3114 self
3115 }
3116 ///
3117 /// Sets the *taskqueue* path property to the given value.
3118 ///
3119 /// Even though the property as already been set when instantiating this call,
3120 /// we provide this method for API completeness.
3121 pub fn taskqueue(mut self, new_value: &str) -> TaskUpdateCall<'a, C> {
3122 self._taskqueue = new_value.to_string();
3123 self
3124 }
3125 ///
3126 /// Sets the *task* path property to the given value.
3127 ///
3128 /// Even though the property as already been set when instantiating this call,
3129 /// we provide this method for API completeness.
3130 pub fn task(mut self, new_value: &str) -> TaskUpdateCall<'a, C> {
3131 self._task = new_value.to_string();
3132 self
3133 }
3134 /// The new lease in seconds.
3135 ///
3136 /// Sets the *new lease seconds* query property to the given value.
3137 ///
3138 /// Even though the property as already been set when instantiating this call,
3139 /// we provide this method for API completeness.
3140 pub fn new_lease_seconds(mut self, new_value: i32) -> TaskUpdateCall<'a, C> {
3141 self._new_lease_seconds = new_value;
3142 self
3143 }
3144 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
3145 /// while executing the actual API request.
3146 ///
3147 /// ````text
3148 /// It should be used to handle progress information, and to implement a certain level of resilience.
3149 /// ````
3150 ///
3151 /// Sets the *delegate* property to the given value.
3152 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> TaskUpdateCall<'a, C> {
3153 self._delegate = Some(new_value);
3154 self
3155 }
3156
3157 /// Set any additional parameter of the query string used in the request.
3158 /// It should be used to set parameters which are not yet available through their own
3159 /// setters.
3160 ///
3161 /// Please note that this method must not be used to set any of the known parameters
3162 /// which have their own setter method. If done anyway, the request will fail.
3163 ///
3164 /// # Additional Parameters
3165 ///
3166 /// * *alt* (query-string) - Data format for the response.
3167 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
3168 /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
3169 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
3170 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
3171 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.
3172 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
3173 pub fn param<T>(mut self, name: T, value: T) -> TaskUpdateCall<'a, C>
3174 where
3175 T: AsRef<str>,
3176 {
3177 self._additional_params
3178 .insert(name.as_ref().to_string(), value.as_ref().to_string());
3179 self
3180 }
3181
3182 /// Identifies the authorization scope for the method you are building.
3183 ///
3184 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
3185 /// [`Scope::Full`].
3186 ///
3187 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
3188 /// tokens for more than one scope.
3189 ///
3190 /// Usually there is more than one suitable scope to authorize an operation, some of which may
3191 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
3192 /// sufficient, a read-write scope will do as well.
3193 pub fn add_scope<St>(mut self, scope: St) -> TaskUpdateCall<'a, C>
3194 where
3195 St: AsRef<str>,
3196 {
3197 self._scopes.insert(String::from(scope.as_ref()));
3198 self
3199 }
3200 /// Identifies the authorization scope(s) for the method you are building.
3201 ///
3202 /// See [`Self::add_scope()`] for details.
3203 pub fn add_scopes<I, St>(mut self, scopes: I) -> TaskUpdateCall<'a, C>
3204 where
3205 I: IntoIterator<Item = St>,
3206 St: AsRef<str>,
3207 {
3208 self._scopes
3209 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
3210 self
3211 }
3212
3213 /// Removes all scopes, and no default scope will be used either.
3214 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
3215 /// for details).
3216 pub fn clear_scopes(mut self) -> TaskUpdateCall<'a, C> {
3217 self._scopes.clear();
3218 self
3219 }
3220}