google_consumersurveys2/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 /// View and edit your surveys and results
17 Full,
18
19 /// View the results for your surveys
20 Readonly,
21
22 /// View your email address
23 UserinfoEmail,
24}
25
26impl AsRef<str> for Scope {
27 fn as_ref(&self) -> &str {
28 match *self {
29 Scope::Full => "https://www.googleapis.com/auth/consumersurveys",
30 Scope::Readonly => "https://www.googleapis.com/auth/consumersurveys.readonly",
31 Scope::UserinfoEmail => "https://www.googleapis.com/auth/userinfo.email",
32 }
33 }
34}
35
36#[allow(clippy::derivable_impls)]
37impl Default for Scope {
38 fn default() -> Scope {
39 Scope::Readonly
40 }
41}
42
43// ########
44// HUB ###
45// ######
46
47/// Central instance to access all ConsumerSurveys related resource activities
48///
49/// # Examples
50///
51/// Instantiate a new hub
52///
53/// ```test_harness,no_run
54/// extern crate hyper;
55/// extern crate hyper_rustls;
56/// extern crate google_consumersurveys2 as consumersurveys2;
57/// use consumersurveys2::{Result, Error};
58/// # async fn dox() {
59/// use consumersurveys2::{ConsumerSurveys, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
60///
61/// // Get an ApplicationSecret instance by some means. It contains the `client_id` and
62/// // `client_secret`, among other things.
63/// let secret: yup_oauth2::ApplicationSecret = Default::default();
64/// // Instantiate the authenticator. It will choose a suitable authentication flow for you,
65/// // unless you replace `None` with the desired Flow.
66/// // Provide your own `AuthenticatorDelegate` to adjust the way it operates and get feedback about
67/// // what's going on. You probably want to bring in your own `TokenStorage` to persist tokens and
68/// // retrieve them from storage.
69/// let connector = hyper_rustls::HttpsConnectorBuilder::new()
70/// .with_native_roots()
71/// .unwrap()
72/// .https_only()
73/// .enable_http2()
74/// .build();
75///
76/// let executor = hyper_util::rt::TokioExecutor::new();
77/// let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
78/// secret,
79/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
80/// yup_oauth2::client::CustomHyperClientBuilder::from(
81/// hyper_util::client::legacy::Client::builder(executor).build(connector),
82/// ),
83/// ).build().await.unwrap();
84///
85/// let client = hyper_util::client::legacy::Client::builder(
86/// hyper_util::rt::TokioExecutor::new()
87/// )
88/// .build(
89/// hyper_rustls::HttpsConnectorBuilder::new()
90/// .with_native_roots()
91/// .unwrap()
92/// .https_or_http()
93/// .enable_http2()
94/// .build()
95/// );
96/// let mut hub = ConsumerSurveys::new(client, auth);
97/// // You can configure optional parameters by calling the respective setters at will, and
98/// // execute the final call using `doit()`.
99/// // Values shown here are possibly random and not representative !
100/// let result = hub.surveys().list()
101/// .token("sanctus")
102/// .start_index(21)
103/// .max_results(99)
104/// .doit().await;
105///
106/// match result {
107/// Err(e) => match e {
108/// // The Error enum provides details about what exactly happened.
109/// // You can also just use its `Debug`, `Display` or `Error` traits
110/// Error::HttpError(_)
111/// |Error::Io(_)
112/// |Error::MissingAPIKey
113/// |Error::MissingToken(_)
114/// |Error::Cancelled
115/// |Error::UploadSizeLimitExceeded(_, _)
116/// |Error::Failure(_)
117/// |Error::BadRequest(_)
118/// |Error::FieldClash(_)
119/// |Error::JsonDecodeError(_, _) => println!("{}", e),
120/// },
121/// Ok(res) => println!("Success: {:?}", res),
122/// }
123/// # }
124/// ```
125#[derive(Clone)]
126pub struct ConsumerSurveys<C> {
127 pub client: common::Client<C>,
128 pub auth: Box<dyn common::GetToken>,
129 _user_agent: String,
130 _base_url: String,
131 _root_url: String,
132}
133
134impl<C> common::Hub for ConsumerSurveys<C> {}
135
136impl<'a, C> ConsumerSurveys<C> {
137 pub fn new<A: 'static + common::GetToken>(
138 client: common::Client<C>,
139 auth: A,
140 ) -> ConsumerSurveys<C> {
141 ConsumerSurveys {
142 client,
143 auth: Box::new(auth),
144 _user_agent: "google-api-rust-client/7.0.0".to_string(),
145 _base_url: "https://www.googleapis.com/consumersurveys/v2/".to_string(),
146 _root_url: "https://www.googleapis.com/".to_string(),
147 }
148 }
149
150 pub fn mobileapppanels(&'a self) -> MobileapppanelMethods<'a, C> {
151 MobileapppanelMethods { hub: self }
152 }
153 pub fn results(&'a self) -> ResultMethods<'a, C> {
154 ResultMethods { hub: self }
155 }
156 pub fn surveys(&'a self) -> SurveyMethods<'a, C> {
157 SurveyMethods { hub: self }
158 }
159
160 /// Set the user-agent header field to use in all requests to the server.
161 /// It defaults to `google-api-rust-client/7.0.0`.
162 ///
163 /// Returns the previously set user-agent.
164 pub fn user_agent(&mut self, agent_name: String) -> String {
165 std::mem::replace(&mut self._user_agent, agent_name)
166 }
167
168 /// Set the base url to use in all requests to the server.
169 /// It defaults to `https://www.googleapis.com/consumersurveys/v2/`.
170 ///
171 /// Returns the previously set base url.
172 pub fn base_url(&mut self, new_base_url: String) -> String {
173 std::mem::replace(&mut self._base_url, new_base_url)
174 }
175
176 /// Set the root url to use in all requests to the server.
177 /// It defaults to `https://www.googleapis.com/`.
178 ///
179 /// Returns the previously set root url.
180 pub fn root_url(&mut self, new_root_url: String) -> String {
181 std::mem::replace(&mut self._root_url, new_root_url)
182 }
183}
184
185// ############
186// SCHEMAS ###
187// ##########
188/// There is no detailed description.
189///
190/// This type is not used in any activity, and only used as *part* of another schema.
191///
192#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
193#[serde_with::serde_as]
194#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
195pub struct FieldMask {
196 /// no description provided
197 pub fields: Option<Vec<FieldMask>>,
198 /// no description provided
199 pub id: Option<i32>,
200}
201
202impl common::Part for FieldMask {}
203
204/// There is no detailed description.
205///
206/// # Activities
207///
208/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
209/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
210///
211/// * [get mobileapppanels](MobileapppanelGetCall) (response)
212/// * [update mobileapppanels](MobileapppanelUpdateCall) (request|response)
213#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
214#[serde_with::serde_as]
215#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
216pub struct MobileAppPanel {
217 /// no description provided
218 pub country: Option<String>,
219 /// no description provided
220 #[serde(rename = "isPublicPanel")]
221 pub is_public_panel: Option<bool>,
222 /// no description provided
223 pub language: Option<String>,
224 /// no description provided
225 #[serde(rename = "mobileAppPanelId")]
226 pub mobile_app_panel_id: Option<String>,
227 /// no description provided
228 pub name: Option<String>,
229 /// no description provided
230 pub owners: Option<Vec<String>>,
231}
232
233impl common::RequestValue for MobileAppPanel {}
234impl common::Resource for MobileAppPanel {}
235impl common::ResponseResult for MobileAppPanel {}
236
237/// There is no detailed description.
238///
239/// # Activities
240///
241/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
242/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
243///
244/// * [list mobileapppanels](MobileapppanelListCall) (response)
245#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
246#[serde_with::serde_as]
247#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
248pub struct MobileAppPanelsListResponse {
249 /// no description provided
250 #[serde(rename = "pageInfo")]
251 pub page_info: Option<PageInfo>,
252 /// Unique request ID used for logging and debugging. Please include in any error reporting or troubleshooting requests.
253 #[serde(rename = "requestId")]
254 pub request_id: Option<String>,
255 /// An individual predefined panel of Opinion Rewards mobile users.
256 pub resources: Option<Vec<MobileAppPanel>>,
257 /// no description provided
258 #[serde(rename = "tokenPagination")]
259 pub token_pagination: Option<TokenPagination>,
260}
261
262impl common::ResponseResult for MobileAppPanelsListResponse {}
263
264/// There is no detailed description.
265///
266/// This type is not used in any activity, and only used as *part* of another schema.
267///
268#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
269#[serde_with::serde_as]
270#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
271pub struct PageInfo {
272 /// no description provided
273 #[serde(rename = "resultPerPage")]
274 pub result_per_page: Option<i32>,
275 /// no description provided
276 #[serde(rename = "startIndex")]
277 pub start_index: Option<i32>,
278 /// no description provided
279 #[serde(rename = "totalResults")]
280 pub total_results: Option<i32>,
281}
282
283impl common::Part for PageInfo {}
284
285/// There is no detailed description.
286///
287/// # Activities
288///
289/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
290/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
291///
292/// * [get results](ResultGetCall) (request)
293#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
294#[serde_with::serde_as]
295#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
296pub struct ResultsGetRequest {
297 /// no description provided
298 #[serde(rename = "resultMask")]
299 pub result_mask: Option<ResultsMask>,
300}
301
302impl common::RequestValue for ResultsGetRequest {}
303
304/// There is no detailed description.
305///
306/// This type is not used in any activity, and only used as *part* of another schema.
307///
308#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
309#[serde_with::serde_as]
310#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
311pub struct ResultsMask {
312 /// no description provided
313 pub fields: Option<Vec<FieldMask>>,
314 /// no description provided
315 pub projection: Option<String>,
316}
317
318impl common::Part for ResultsMask {}
319
320/// There is no detailed description.
321///
322/// # Activities
323///
324/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
325/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
326///
327/// * [delete surveys](SurveyDeleteCall) (none)
328/// * [get surveys](SurveyGetCall) (response)
329/// * [insert surveys](SurveyInsertCall) (request|response)
330/// * [list surveys](SurveyListCall) (none)
331/// * [start surveys](SurveyStartCall) (none)
332/// * [stop surveys](SurveyStopCall) (none)
333/// * [update surveys](SurveyUpdateCall) (request|response)
334#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
335#[serde_with::serde_as]
336#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
337pub struct Survey {
338 /// no description provided
339 pub audience: Option<SurveyAudience>,
340 /// no description provided
341 pub cost: Option<SurveyCost>,
342 /// no description provided
343 #[serde(rename = "customerData")]
344 #[serde_as(as = "Option<common::serde::standard_base64::Wrapper>")]
345 pub customer_data: Option<Vec<u8>>,
346 /// no description provided
347 pub description: Option<String>,
348 /// no description provided
349 pub owners: Option<Vec<String>>,
350 /// no description provided
351 pub questions: Option<Vec<SurveyQuestion>>,
352 /// no description provided
353 #[serde(rename = "rejectionReason")]
354 pub rejection_reason: Option<SurveyRejection>,
355 /// no description provided
356 pub state: Option<String>,
357 /// no description provided
358 #[serde(rename = "surveyUrlId")]
359 pub survey_url_id: Option<String>,
360 /// no description provided
361 pub title: Option<String>,
362 /// no description provided
363 #[serde(rename = "wantedResponseCount")]
364 pub wanted_response_count: Option<i32>,
365}
366
367impl common::RequestValue for Survey {}
368impl common::Resource for Survey {}
369impl common::ResponseResult for Survey {}
370
371/// There is no detailed description.
372///
373/// This type is not used in any activity, and only used as *part* of another schema.
374///
375#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
376#[serde_with::serde_as]
377#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
378pub struct SurveyAudience {
379 /// no description provided
380 pub ages: Option<Vec<String>>,
381 /// no description provided
382 pub country: Option<String>,
383 /// no description provided
384 #[serde(rename = "countrySubdivision")]
385 pub country_subdivision: Option<String>,
386 /// no description provided
387 pub gender: Option<String>,
388 /// no description provided
389 pub languages: Option<Vec<String>>,
390 /// no description provided
391 #[serde(rename = "mobileAppPanelId")]
392 pub mobile_app_panel_id: Option<String>,
393 /// no description provided
394 #[serde(rename = "populationSource")]
395 pub population_source: Option<String>,
396}
397
398impl common::Part for SurveyAudience {}
399
400/// There is no detailed description.
401///
402/// This type is not used in any activity, and only used as *part* of another schema.
403///
404#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
405#[serde_with::serde_as]
406#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
407pub struct SurveyCost {
408 /// no description provided
409 #[serde(rename = "costPerResponseNanos")]
410 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
411 pub cost_per_response_nanos: Option<i64>,
412 /// no description provided
413 #[serde(rename = "currencyCode")]
414 pub currency_code: Option<String>,
415 /// no description provided
416 #[serde(rename = "maxCostPerResponseNanos")]
417 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
418 pub max_cost_per_response_nanos: Option<i64>,
419 /// no description provided
420 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
421 pub nanos: Option<i64>,
422}
423
424impl common::Part for SurveyCost {}
425
426/// There is no detailed description.
427///
428/// This type is not used in any activity, and only used as *part* of another schema.
429///
430#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
431#[serde_with::serde_as]
432#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
433pub struct SurveyQuestion {
434 /// no description provided
435 #[serde(rename = "answerOrder")]
436 pub answer_order: Option<String>,
437 /// no description provided
438 pub answers: Option<Vec<String>>,
439 /// no description provided
440 #[serde(rename = "hasOther")]
441 pub has_other: Option<bool>,
442 /// no description provided
443 #[serde(rename = "highValueLabel")]
444 pub high_value_label: Option<String>,
445 /// no description provided
446 pub images: Option<Vec<SurveyQuestionImage>>,
447 /// no description provided
448 #[serde(rename = "lastAnswerPositionPinned")]
449 pub last_answer_position_pinned: Option<bool>,
450 /// no description provided
451 #[serde(rename = "lowValueLabel")]
452 pub low_value_label: Option<String>,
453 /// no description provided
454 #[serde(rename = "mustPickSuggestion")]
455 pub must_pick_suggestion: Option<bool>,
456 /// no description provided
457 #[serde(rename = "numStars")]
458 pub num_stars: Option<String>,
459 /// no description provided
460 #[serde(rename = "openTextPlaceholder")]
461 pub open_text_placeholder: Option<String>,
462 /// no description provided
463 #[serde(rename = "openTextSuggestions")]
464 pub open_text_suggestions: Option<Vec<String>>,
465 /// no description provided
466 pub question: Option<String>,
467 /// no description provided
468 #[serde(rename = "sentimentText")]
469 pub sentiment_text: Option<String>,
470 /// no description provided
471 #[serde(rename = "singleLineResponse")]
472 pub single_line_response: Option<bool>,
473 /// no description provided
474 #[serde(rename = "thresholdAnswers")]
475 pub threshold_answers: Option<Vec<String>>,
476 /// no description provided
477 #[serde(rename = "type")]
478 pub type_: Option<String>,
479 /// no description provided
480 #[serde(rename = "unitOfMeasurementLabel")]
481 pub unit_of_measurement_label: Option<String>,
482 /// no description provided
483 #[serde(rename = "videoId")]
484 pub video_id: Option<String>,
485}
486
487impl common::Part for SurveyQuestion {}
488
489/// There is no detailed description.
490///
491/// This type is not used in any activity, and only used as *part* of another schema.
492///
493#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
494#[serde_with::serde_as]
495#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
496pub struct SurveyQuestionImage {
497 /// no description provided
498 #[serde(rename = "altText")]
499 pub alt_text: Option<String>,
500 /// no description provided
501 #[serde_as(as = "Option<common::serde::standard_base64::Wrapper>")]
502 pub data: Option<Vec<u8>>,
503 /// no description provided
504 pub url: Option<String>,
505}
506
507impl common::Part for SurveyQuestionImage {}
508
509/// There is no detailed description.
510///
511/// This type is not used in any activity, and only used as *part* of another schema.
512///
513#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
514#[serde_with::serde_as]
515#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
516pub struct SurveyRejection {
517 /// no description provided
518 pub explanation: Option<String>,
519 /// no description provided
520 #[serde(rename = "type")]
521 pub type_: Option<String>,
522}
523
524impl common::Part for SurveyRejection {}
525
526/// There is no detailed description.
527///
528/// # Activities
529///
530/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
531/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
532///
533/// * [get results](ResultGetCall) (response)
534#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
535#[serde_with::serde_as]
536#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
537pub struct SurveyResults {
538 /// no description provided
539 pub status: Option<String>,
540 /// no description provided
541 #[serde(rename = "surveyUrlId")]
542 pub survey_url_id: Option<String>,
543}
544
545impl common::ResponseResult for SurveyResults {}
546
547/// There is no detailed description.
548///
549/// # Activities
550///
551/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
552/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
553///
554/// * [delete surveys](SurveyDeleteCall) (response)
555#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
556#[serde_with::serde_as]
557#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
558pub struct SurveysDeleteResponse {
559 /// Unique request ID used for logging and debugging. Please include in any error reporting or troubleshooting requests.
560 #[serde(rename = "requestId")]
561 pub request_id: Option<String>,
562}
563
564impl common::ResponseResult for SurveysDeleteResponse {}
565
566/// There is no detailed description.
567///
568/// # Activities
569///
570/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
571/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
572///
573/// * [list surveys](SurveyListCall) (response)
574#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
575#[serde_with::serde_as]
576#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
577pub struct SurveysListResponse {
578 /// no description provided
579 #[serde(rename = "pageInfo")]
580 pub page_info: Option<PageInfo>,
581 /// Unique request ID used for logging and debugging. Please include in any error reporting or troubleshooting requests.
582 #[serde(rename = "requestId")]
583 pub request_id: Option<String>,
584 /// An individual survey resource.
585 pub resources: Option<Vec<Survey>>,
586 /// no description provided
587 #[serde(rename = "tokenPagination")]
588 pub token_pagination: Option<TokenPagination>,
589}
590
591impl common::ResponseResult for SurveysListResponse {}
592
593/// There is no detailed description.
594///
595/// # Activities
596///
597/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
598/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
599///
600/// * [start surveys](SurveyStartCall) (request)
601#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
602#[serde_with::serde_as]
603#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
604pub struct SurveysStartRequest {
605 /// Threshold to start a survey automically if the quoted prices is less than or equal to this value. See Survey.Cost for more details.
606 #[serde(rename = "maxCostPerResponseNanos")]
607 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
608 pub max_cost_per_response_nanos: Option<i64>,
609}
610
611impl common::RequestValue for SurveysStartRequest {}
612
613/// There is no detailed description.
614///
615/// # Activities
616///
617/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
618/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
619///
620/// * [start surveys](SurveyStartCall) (response)
621#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
622#[serde_with::serde_as]
623#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
624pub struct SurveysStartResponse {
625 /// Unique request ID used for logging and debugging. Please include in any error reporting or troubleshooting requests.
626 #[serde(rename = "requestId")]
627 pub request_id: Option<String>,
628}
629
630impl common::ResponseResult for SurveysStartResponse {}
631
632/// There is no detailed description.
633///
634/// # Activities
635///
636/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
637/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
638///
639/// * [stop surveys](SurveyStopCall) (response)
640#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
641#[serde_with::serde_as]
642#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
643pub struct SurveysStopResponse {
644 /// Unique request ID used for logging and debugging. Please include in any error reporting or troubleshooting requests.
645 #[serde(rename = "requestId")]
646 pub request_id: Option<String>,
647}
648
649impl common::ResponseResult for SurveysStopResponse {}
650
651/// There is no detailed description.
652///
653/// This type is not used in any activity, and only used as *part* of another schema.
654///
655#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
656#[serde_with::serde_as]
657#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
658pub struct TokenPagination {
659 /// no description provided
660 #[serde(rename = "nextPageToken")]
661 pub next_page_token: Option<String>,
662 /// no description provided
663 #[serde(rename = "previousPageToken")]
664 pub previous_page_token: Option<String>,
665}
666
667impl common::Part for TokenPagination {}
668
669// ###################
670// MethodBuilders ###
671// #################
672
673/// A builder providing access to all methods supported on *mobileapppanel* resources.
674/// It is not used directly, but through the [`ConsumerSurveys`] hub.
675///
676/// # Example
677///
678/// Instantiate a resource builder
679///
680/// ```test_harness,no_run
681/// extern crate hyper;
682/// extern crate hyper_rustls;
683/// extern crate google_consumersurveys2 as consumersurveys2;
684///
685/// # async fn dox() {
686/// use consumersurveys2::{ConsumerSurveys, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
687///
688/// let secret: yup_oauth2::ApplicationSecret = Default::default();
689/// let connector = hyper_rustls::HttpsConnectorBuilder::new()
690/// .with_native_roots()
691/// .unwrap()
692/// .https_only()
693/// .enable_http2()
694/// .build();
695///
696/// let executor = hyper_util::rt::TokioExecutor::new();
697/// let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
698/// secret,
699/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
700/// yup_oauth2::client::CustomHyperClientBuilder::from(
701/// hyper_util::client::legacy::Client::builder(executor).build(connector),
702/// ),
703/// ).build().await.unwrap();
704///
705/// let client = hyper_util::client::legacy::Client::builder(
706/// hyper_util::rt::TokioExecutor::new()
707/// )
708/// .build(
709/// hyper_rustls::HttpsConnectorBuilder::new()
710/// .with_native_roots()
711/// .unwrap()
712/// .https_or_http()
713/// .enable_http2()
714/// .build()
715/// );
716/// let mut hub = ConsumerSurveys::new(client, auth);
717/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
718/// // like `get(...)`, `list(...)` and `update(...)`
719/// // to build up your call.
720/// let rb = hub.mobileapppanels();
721/// # }
722/// ```
723pub struct MobileapppanelMethods<'a, C>
724where
725 C: 'a,
726{
727 hub: &'a ConsumerSurveys<C>,
728}
729
730impl<'a, C> common::MethodsBuilder for MobileapppanelMethods<'a, C> {}
731
732impl<'a, C> MobileapppanelMethods<'a, C> {
733 /// Create a builder to help you perform the following task:
734 ///
735 /// Retrieves a MobileAppPanel that is available to the authenticated user.
736 ///
737 /// # Arguments
738 ///
739 /// * `panelId` - External URL ID for the panel.
740 pub fn get(&self, panel_id: &str) -> MobileapppanelGetCall<'a, C> {
741 MobileapppanelGetCall {
742 hub: self.hub,
743 _panel_id: panel_id.to_string(),
744 _delegate: Default::default(),
745 _additional_params: Default::default(),
746 _scopes: Default::default(),
747 }
748 }
749
750 /// Create a builder to help you perform the following task:
751 ///
752 /// Lists the MobileAppPanels available to the authenticated user.
753 pub fn list(&self) -> MobileapppanelListCall<'a, C> {
754 MobileapppanelListCall {
755 hub: self.hub,
756 _token: Default::default(),
757 _start_index: Default::default(),
758 _max_results: Default::default(),
759 _delegate: Default::default(),
760 _additional_params: Default::default(),
761 _scopes: Default::default(),
762 }
763 }
764
765 /// Create a builder to help you perform the following task:
766 ///
767 /// Updates a MobileAppPanel. Currently the only property that can be updated is the owners property.
768 ///
769 /// # Arguments
770 ///
771 /// * `request` - No description provided.
772 /// * `panelId` - External URL ID for the panel.
773 pub fn update(
774 &self,
775 request: MobileAppPanel,
776 panel_id: &str,
777 ) -> MobileapppanelUpdateCall<'a, C> {
778 MobileapppanelUpdateCall {
779 hub: self.hub,
780 _request: request,
781 _panel_id: panel_id.to_string(),
782 _delegate: Default::default(),
783 _additional_params: Default::default(),
784 _scopes: Default::default(),
785 }
786 }
787}
788
789/// A builder providing access to all methods supported on *result* resources.
790/// It is not used directly, but through the [`ConsumerSurveys`] hub.
791///
792/// # Example
793///
794/// Instantiate a resource builder
795///
796/// ```test_harness,no_run
797/// extern crate hyper;
798/// extern crate hyper_rustls;
799/// extern crate google_consumersurveys2 as consumersurveys2;
800///
801/// # async fn dox() {
802/// use consumersurveys2::{ConsumerSurveys, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
803///
804/// let secret: yup_oauth2::ApplicationSecret = Default::default();
805/// let connector = hyper_rustls::HttpsConnectorBuilder::new()
806/// .with_native_roots()
807/// .unwrap()
808/// .https_only()
809/// .enable_http2()
810/// .build();
811///
812/// let executor = hyper_util::rt::TokioExecutor::new();
813/// let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
814/// secret,
815/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
816/// yup_oauth2::client::CustomHyperClientBuilder::from(
817/// hyper_util::client::legacy::Client::builder(executor).build(connector),
818/// ),
819/// ).build().await.unwrap();
820///
821/// let client = hyper_util::client::legacy::Client::builder(
822/// hyper_util::rt::TokioExecutor::new()
823/// )
824/// .build(
825/// hyper_rustls::HttpsConnectorBuilder::new()
826/// .with_native_roots()
827/// .unwrap()
828/// .https_or_http()
829/// .enable_http2()
830/// .build()
831/// );
832/// let mut hub = ConsumerSurveys::new(client, auth);
833/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
834/// // like `get(...)`
835/// // to build up your call.
836/// let rb = hub.results();
837/// # }
838/// ```
839pub struct ResultMethods<'a, C>
840where
841 C: 'a,
842{
843 hub: &'a ConsumerSurveys<C>,
844}
845
846impl<'a, C> common::MethodsBuilder for ResultMethods<'a, C> {}
847
848impl<'a, C> ResultMethods<'a, C> {
849 /// Create a builder to help you perform the following task:
850 ///
851 /// Retrieves any survey results that have been produced so far. Results are formatted as an Excel file. You must add "?alt=media" to the URL as an argument to get results.
852 ///
853 /// # Arguments
854 ///
855 /// * `request` - No description provided.
856 /// * `surveyUrlId` - External URL ID for the survey.
857 pub fn get(&self, request: ResultsGetRequest, survey_url_id: &str) -> ResultGetCall<'a, C> {
858 ResultGetCall {
859 hub: self.hub,
860 _request: request,
861 _survey_url_id: survey_url_id.to_string(),
862 _delegate: Default::default(),
863 _additional_params: Default::default(),
864 _scopes: Default::default(),
865 }
866 }
867}
868
869/// A builder providing access to all methods supported on *survey* resources.
870/// It is not used directly, but through the [`ConsumerSurveys`] hub.
871///
872/// # Example
873///
874/// Instantiate a resource builder
875///
876/// ```test_harness,no_run
877/// extern crate hyper;
878/// extern crate hyper_rustls;
879/// extern crate google_consumersurveys2 as consumersurveys2;
880///
881/// # async fn dox() {
882/// use consumersurveys2::{ConsumerSurveys, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
883///
884/// let secret: yup_oauth2::ApplicationSecret = Default::default();
885/// let connector = hyper_rustls::HttpsConnectorBuilder::new()
886/// .with_native_roots()
887/// .unwrap()
888/// .https_only()
889/// .enable_http2()
890/// .build();
891///
892/// let executor = hyper_util::rt::TokioExecutor::new();
893/// let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
894/// secret,
895/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
896/// yup_oauth2::client::CustomHyperClientBuilder::from(
897/// hyper_util::client::legacy::Client::builder(executor).build(connector),
898/// ),
899/// ).build().await.unwrap();
900///
901/// let client = hyper_util::client::legacy::Client::builder(
902/// hyper_util::rt::TokioExecutor::new()
903/// )
904/// .build(
905/// hyper_rustls::HttpsConnectorBuilder::new()
906/// .with_native_roots()
907/// .unwrap()
908/// .https_or_http()
909/// .enable_http2()
910/// .build()
911/// );
912/// let mut hub = ConsumerSurveys::new(client, auth);
913/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
914/// // like `delete(...)`, `get(...)`, `insert(...)`, `list(...)`, `start(...)`, `stop(...)` and `update(...)`
915/// // to build up your call.
916/// let rb = hub.surveys();
917/// # }
918/// ```
919pub struct SurveyMethods<'a, C>
920where
921 C: 'a,
922{
923 hub: &'a ConsumerSurveys<C>,
924}
925
926impl<'a, C> common::MethodsBuilder for SurveyMethods<'a, C> {}
927
928impl<'a, C> SurveyMethods<'a, C> {
929 /// Create a builder to help you perform the following task:
930 ///
931 /// Removes a survey from view in all user GET requests.
932 ///
933 /// # Arguments
934 ///
935 /// * `surveyUrlId` - External URL ID for the survey.
936 pub fn delete(&self, survey_url_id: &str) -> SurveyDeleteCall<'a, C> {
937 SurveyDeleteCall {
938 hub: self.hub,
939 _survey_url_id: survey_url_id.to_string(),
940 _delegate: Default::default(),
941 _additional_params: Default::default(),
942 _scopes: Default::default(),
943 }
944 }
945
946 /// Create a builder to help you perform the following task:
947 ///
948 /// Retrieves information about the specified survey.
949 ///
950 /// # Arguments
951 ///
952 /// * `surveyUrlId` - External URL ID for the survey.
953 pub fn get(&self, survey_url_id: &str) -> SurveyGetCall<'a, C> {
954 SurveyGetCall {
955 hub: self.hub,
956 _survey_url_id: survey_url_id.to_string(),
957 _delegate: Default::default(),
958 _additional_params: Default::default(),
959 _scopes: Default::default(),
960 }
961 }
962
963 /// Create a builder to help you perform the following task:
964 ///
965 /// Creates a survey.
966 ///
967 /// # Arguments
968 ///
969 /// * `request` - No description provided.
970 pub fn insert(&self, request: Survey) -> SurveyInsertCall<'a, C> {
971 SurveyInsertCall {
972 hub: self.hub,
973 _request: request,
974 _delegate: Default::default(),
975 _additional_params: Default::default(),
976 _scopes: Default::default(),
977 }
978 }
979
980 /// Create a builder to help you perform the following task:
981 ///
982 /// Lists the surveys owned by the authenticated user.
983 pub fn list(&self) -> SurveyListCall<'a, C> {
984 SurveyListCall {
985 hub: self.hub,
986 _token: Default::default(),
987 _start_index: Default::default(),
988 _max_results: Default::default(),
989 _delegate: Default::default(),
990 _additional_params: Default::default(),
991 _scopes: Default::default(),
992 }
993 }
994
995 /// Create a builder to help you perform the following task:
996 ///
997 /// Begins running a survey.
998 ///
999 /// # Arguments
1000 ///
1001 /// * `request` - No description provided.
1002 /// * `resourceId` - No description provided.
1003 pub fn start(&self, request: SurveysStartRequest, resource_id: &str) -> SurveyStartCall<'a, C> {
1004 SurveyStartCall {
1005 hub: self.hub,
1006 _request: request,
1007 _resource_id: resource_id.to_string(),
1008 _delegate: Default::default(),
1009 _additional_params: Default::default(),
1010 _scopes: Default::default(),
1011 }
1012 }
1013
1014 /// Create a builder to help you perform the following task:
1015 ///
1016 /// Stops a running survey.
1017 ///
1018 /// # Arguments
1019 ///
1020 /// * `resourceId` - No description provided.
1021 pub fn stop(&self, resource_id: &str) -> SurveyStopCall<'a, C> {
1022 SurveyStopCall {
1023 hub: self.hub,
1024 _resource_id: resource_id.to_string(),
1025 _delegate: Default::default(),
1026 _additional_params: Default::default(),
1027 _scopes: Default::default(),
1028 }
1029 }
1030
1031 /// Create a builder to help you perform the following task:
1032 ///
1033 /// Updates a survey. Currently the only property that can be updated is the owners property.
1034 ///
1035 /// # Arguments
1036 ///
1037 /// * `request` - No description provided.
1038 /// * `surveyUrlId` - External URL ID for the survey.
1039 pub fn update(&self, request: Survey, survey_url_id: &str) -> SurveyUpdateCall<'a, C> {
1040 SurveyUpdateCall {
1041 hub: self.hub,
1042 _request: request,
1043 _survey_url_id: survey_url_id.to_string(),
1044 _delegate: Default::default(),
1045 _additional_params: Default::default(),
1046 _scopes: Default::default(),
1047 }
1048 }
1049}
1050
1051// ###################
1052// CallBuilders ###
1053// #################
1054
1055/// Retrieves a MobileAppPanel that is available to the authenticated user.
1056///
1057/// A builder for the *get* method supported by a *mobileapppanel* resource.
1058/// It is not used directly, but through a [`MobileapppanelMethods`] instance.
1059///
1060/// # Example
1061///
1062/// Instantiate a resource method builder
1063///
1064/// ```test_harness,no_run
1065/// # extern crate hyper;
1066/// # extern crate hyper_rustls;
1067/// # extern crate google_consumersurveys2 as consumersurveys2;
1068/// # async fn dox() {
1069/// # use consumersurveys2::{ConsumerSurveys, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1070///
1071/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1072/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
1073/// # .with_native_roots()
1074/// # .unwrap()
1075/// # .https_only()
1076/// # .enable_http2()
1077/// # .build();
1078///
1079/// # let executor = hyper_util::rt::TokioExecutor::new();
1080/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
1081/// # secret,
1082/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1083/// # yup_oauth2::client::CustomHyperClientBuilder::from(
1084/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
1085/// # ),
1086/// # ).build().await.unwrap();
1087///
1088/// # let client = hyper_util::client::legacy::Client::builder(
1089/// # hyper_util::rt::TokioExecutor::new()
1090/// # )
1091/// # .build(
1092/// # hyper_rustls::HttpsConnectorBuilder::new()
1093/// # .with_native_roots()
1094/// # .unwrap()
1095/// # .https_or_http()
1096/// # .enable_http2()
1097/// # .build()
1098/// # );
1099/// # let mut hub = ConsumerSurveys::new(client, auth);
1100/// // You can configure optional parameters by calling the respective setters at will, and
1101/// // execute the final call using `doit()`.
1102/// // Values shown here are possibly random and not representative !
1103/// let result = hub.mobileapppanels().get("panelId")
1104/// .doit().await;
1105/// # }
1106/// ```
1107pub struct MobileapppanelGetCall<'a, C>
1108where
1109 C: 'a,
1110{
1111 hub: &'a ConsumerSurveys<C>,
1112 _panel_id: String,
1113 _delegate: Option<&'a mut dyn common::Delegate>,
1114 _additional_params: HashMap<String, String>,
1115 _scopes: BTreeSet<String>,
1116}
1117
1118impl<'a, C> common::CallBuilder for MobileapppanelGetCall<'a, C> {}
1119
1120impl<'a, C> MobileapppanelGetCall<'a, C>
1121where
1122 C: common::Connector,
1123{
1124 /// Perform the operation you have build so far.
1125 pub async fn doit(mut self) -> common::Result<(common::Response, MobileAppPanel)> {
1126 use std::borrow::Cow;
1127 use std::io::{Read, Seek};
1128
1129 use common::{url::Params, ToParts};
1130 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1131
1132 let mut dd = common::DefaultDelegate;
1133 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1134 dlg.begin(common::MethodInfo {
1135 id: "consumersurveys.mobileapppanels.get",
1136 http_method: hyper::Method::GET,
1137 });
1138
1139 for &field in ["alt", "panelId"].iter() {
1140 if self._additional_params.contains_key(field) {
1141 dlg.finished(false);
1142 return Err(common::Error::FieldClash(field));
1143 }
1144 }
1145
1146 let mut params = Params::with_capacity(3 + self._additional_params.len());
1147 params.push("panelId", self._panel_id);
1148
1149 params.extend(self._additional_params.iter());
1150
1151 params.push("alt", "json");
1152 let mut url = self.hub._base_url.clone() + "mobileAppPanels/{panelId}";
1153 if self._scopes.is_empty() {
1154 self._scopes.insert(Scope::Readonly.as_ref().to_string());
1155 }
1156
1157 #[allow(clippy::single_element_loop)]
1158 for &(find_this, param_name) in [("{panelId}", "panelId")].iter() {
1159 url = params.uri_replacement(url, param_name, find_this, false);
1160 }
1161 {
1162 let to_remove = ["panelId"];
1163 params.remove_params(&to_remove);
1164 }
1165
1166 let url = params.parse_with_url(&url);
1167
1168 loop {
1169 let token = match self
1170 .hub
1171 .auth
1172 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1173 .await
1174 {
1175 Ok(token) => token,
1176 Err(e) => match dlg.token(e) {
1177 Ok(token) => token,
1178 Err(e) => {
1179 dlg.finished(false);
1180 return Err(common::Error::MissingToken(e));
1181 }
1182 },
1183 };
1184 let mut req_result = {
1185 let client = &self.hub.client;
1186 dlg.pre_request();
1187 let mut req_builder = hyper::Request::builder()
1188 .method(hyper::Method::GET)
1189 .uri(url.as_str())
1190 .header(USER_AGENT, self.hub._user_agent.clone());
1191
1192 if let Some(token) = token.as_ref() {
1193 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1194 }
1195
1196 let request = req_builder
1197 .header(CONTENT_LENGTH, 0_u64)
1198 .body(common::to_body::<String>(None));
1199
1200 client.request(request.unwrap()).await
1201 };
1202
1203 match req_result {
1204 Err(err) => {
1205 if let common::Retry::After(d) = dlg.http_error(&err) {
1206 sleep(d).await;
1207 continue;
1208 }
1209 dlg.finished(false);
1210 return Err(common::Error::HttpError(err));
1211 }
1212 Ok(res) => {
1213 let (mut parts, body) = res.into_parts();
1214 let mut body = common::Body::new(body);
1215 if !parts.status.is_success() {
1216 let bytes = common::to_bytes(body).await.unwrap_or_default();
1217 let error = serde_json::from_str(&common::to_string(&bytes));
1218 let response = common::to_response(parts, bytes.into());
1219
1220 if let common::Retry::After(d) =
1221 dlg.http_failure(&response, error.as_ref().ok())
1222 {
1223 sleep(d).await;
1224 continue;
1225 }
1226
1227 dlg.finished(false);
1228
1229 return Err(match error {
1230 Ok(value) => common::Error::BadRequest(value),
1231 _ => common::Error::Failure(response),
1232 });
1233 }
1234 let response = {
1235 let bytes = common::to_bytes(body).await.unwrap_or_default();
1236 let encoded = common::to_string(&bytes);
1237 match serde_json::from_str(&encoded) {
1238 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1239 Err(error) => {
1240 dlg.response_json_decode_error(&encoded, &error);
1241 return Err(common::Error::JsonDecodeError(
1242 encoded.to_string(),
1243 error,
1244 ));
1245 }
1246 }
1247 };
1248
1249 dlg.finished(true);
1250 return Ok(response);
1251 }
1252 }
1253 }
1254 }
1255
1256 /// External URL ID for the panel.
1257 ///
1258 /// Sets the *panel id* path property to the given value.
1259 ///
1260 /// Even though the property as already been set when instantiating this call,
1261 /// we provide this method for API completeness.
1262 pub fn panel_id(mut self, new_value: &str) -> MobileapppanelGetCall<'a, C> {
1263 self._panel_id = new_value.to_string();
1264 self
1265 }
1266 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1267 /// while executing the actual API request.
1268 ///
1269 /// ````text
1270 /// It should be used to handle progress information, and to implement a certain level of resilience.
1271 /// ````
1272 ///
1273 /// Sets the *delegate* property to the given value.
1274 pub fn delegate(
1275 mut self,
1276 new_value: &'a mut dyn common::Delegate,
1277 ) -> MobileapppanelGetCall<'a, C> {
1278 self._delegate = Some(new_value);
1279 self
1280 }
1281
1282 /// Set any additional parameter of the query string used in the request.
1283 /// It should be used to set parameters which are not yet available through their own
1284 /// setters.
1285 ///
1286 /// Please note that this method must not be used to set any of the known parameters
1287 /// which have their own setter method. If done anyway, the request will fail.
1288 ///
1289 /// # Additional Parameters
1290 ///
1291 /// * *alt* (query-string) - Data format for the response.
1292 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1293 /// * *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.
1294 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1295 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1296 /// * *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.
1297 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
1298 pub fn param<T>(mut self, name: T, value: T) -> MobileapppanelGetCall<'a, C>
1299 where
1300 T: AsRef<str>,
1301 {
1302 self._additional_params
1303 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1304 self
1305 }
1306
1307 /// Identifies the authorization scope for the method you are building.
1308 ///
1309 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1310 /// [`Scope::Readonly`].
1311 ///
1312 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1313 /// tokens for more than one scope.
1314 ///
1315 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1316 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1317 /// sufficient, a read-write scope will do as well.
1318 pub fn add_scope<St>(mut self, scope: St) -> MobileapppanelGetCall<'a, C>
1319 where
1320 St: AsRef<str>,
1321 {
1322 self._scopes.insert(String::from(scope.as_ref()));
1323 self
1324 }
1325 /// Identifies the authorization scope(s) for the method you are building.
1326 ///
1327 /// See [`Self::add_scope()`] for details.
1328 pub fn add_scopes<I, St>(mut self, scopes: I) -> MobileapppanelGetCall<'a, C>
1329 where
1330 I: IntoIterator<Item = St>,
1331 St: AsRef<str>,
1332 {
1333 self._scopes
1334 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1335 self
1336 }
1337
1338 /// Removes all scopes, and no default scope will be used either.
1339 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1340 /// for details).
1341 pub fn clear_scopes(mut self) -> MobileapppanelGetCall<'a, C> {
1342 self._scopes.clear();
1343 self
1344 }
1345}
1346
1347/// Lists the MobileAppPanels available to the authenticated user.
1348///
1349/// A builder for the *list* method supported by a *mobileapppanel* resource.
1350/// It is not used directly, but through a [`MobileapppanelMethods`] instance.
1351///
1352/// # Example
1353///
1354/// Instantiate a resource method builder
1355///
1356/// ```test_harness,no_run
1357/// # extern crate hyper;
1358/// # extern crate hyper_rustls;
1359/// # extern crate google_consumersurveys2 as consumersurveys2;
1360/// # async fn dox() {
1361/// # use consumersurveys2::{ConsumerSurveys, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1362///
1363/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1364/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
1365/// # .with_native_roots()
1366/// # .unwrap()
1367/// # .https_only()
1368/// # .enable_http2()
1369/// # .build();
1370///
1371/// # let executor = hyper_util::rt::TokioExecutor::new();
1372/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
1373/// # secret,
1374/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1375/// # yup_oauth2::client::CustomHyperClientBuilder::from(
1376/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
1377/// # ),
1378/// # ).build().await.unwrap();
1379///
1380/// # let client = hyper_util::client::legacy::Client::builder(
1381/// # hyper_util::rt::TokioExecutor::new()
1382/// # )
1383/// # .build(
1384/// # hyper_rustls::HttpsConnectorBuilder::new()
1385/// # .with_native_roots()
1386/// # .unwrap()
1387/// # .https_or_http()
1388/// # .enable_http2()
1389/// # .build()
1390/// # );
1391/// # let mut hub = ConsumerSurveys::new(client, auth);
1392/// // You can configure optional parameters by calling the respective setters at will, and
1393/// // execute the final call using `doit()`.
1394/// // Values shown here are possibly random and not representative !
1395/// let result = hub.mobileapppanels().list()
1396/// .token("amet.")
1397/// .start_index(81)
1398/// .max_results(46)
1399/// .doit().await;
1400/// # }
1401/// ```
1402pub struct MobileapppanelListCall<'a, C>
1403where
1404 C: 'a,
1405{
1406 hub: &'a ConsumerSurveys<C>,
1407 _token: Option<String>,
1408 _start_index: Option<u32>,
1409 _max_results: Option<u32>,
1410 _delegate: Option<&'a mut dyn common::Delegate>,
1411 _additional_params: HashMap<String, String>,
1412 _scopes: BTreeSet<String>,
1413}
1414
1415impl<'a, C> common::CallBuilder for MobileapppanelListCall<'a, C> {}
1416
1417impl<'a, C> MobileapppanelListCall<'a, C>
1418where
1419 C: common::Connector,
1420{
1421 /// Perform the operation you have build so far.
1422 pub async fn doit(mut self) -> common::Result<(common::Response, MobileAppPanelsListResponse)> {
1423 use std::borrow::Cow;
1424 use std::io::{Read, Seek};
1425
1426 use common::{url::Params, ToParts};
1427 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1428
1429 let mut dd = common::DefaultDelegate;
1430 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1431 dlg.begin(common::MethodInfo {
1432 id: "consumersurveys.mobileapppanels.list",
1433 http_method: hyper::Method::GET,
1434 });
1435
1436 for &field in ["alt", "token", "startIndex", "maxResults"].iter() {
1437 if self._additional_params.contains_key(field) {
1438 dlg.finished(false);
1439 return Err(common::Error::FieldClash(field));
1440 }
1441 }
1442
1443 let mut params = Params::with_capacity(5 + self._additional_params.len());
1444 if let Some(value) = self._token.as_ref() {
1445 params.push("token", value);
1446 }
1447 if let Some(value) = self._start_index.as_ref() {
1448 params.push("startIndex", value.to_string());
1449 }
1450 if let Some(value) = self._max_results.as_ref() {
1451 params.push("maxResults", value.to_string());
1452 }
1453
1454 params.extend(self._additional_params.iter());
1455
1456 params.push("alt", "json");
1457 let mut url = self.hub._base_url.clone() + "mobileAppPanels";
1458 if self._scopes.is_empty() {
1459 self._scopes.insert(Scope::Readonly.as_ref().to_string());
1460 }
1461
1462 let url = params.parse_with_url(&url);
1463
1464 loop {
1465 let token = match self
1466 .hub
1467 .auth
1468 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1469 .await
1470 {
1471 Ok(token) => token,
1472 Err(e) => match dlg.token(e) {
1473 Ok(token) => token,
1474 Err(e) => {
1475 dlg.finished(false);
1476 return Err(common::Error::MissingToken(e));
1477 }
1478 },
1479 };
1480 let mut req_result = {
1481 let client = &self.hub.client;
1482 dlg.pre_request();
1483 let mut req_builder = hyper::Request::builder()
1484 .method(hyper::Method::GET)
1485 .uri(url.as_str())
1486 .header(USER_AGENT, self.hub._user_agent.clone());
1487
1488 if let Some(token) = token.as_ref() {
1489 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1490 }
1491
1492 let request = req_builder
1493 .header(CONTENT_LENGTH, 0_u64)
1494 .body(common::to_body::<String>(None));
1495
1496 client.request(request.unwrap()).await
1497 };
1498
1499 match req_result {
1500 Err(err) => {
1501 if let common::Retry::After(d) = dlg.http_error(&err) {
1502 sleep(d).await;
1503 continue;
1504 }
1505 dlg.finished(false);
1506 return Err(common::Error::HttpError(err));
1507 }
1508 Ok(res) => {
1509 let (mut parts, body) = res.into_parts();
1510 let mut body = common::Body::new(body);
1511 if !parts.status.is_success() {
1512 let bytes = common::to_bytes(body).await.unwrap_or_default();
1513 let error = serde_json::from_str(&common::to_string(&bytes));
1514 let response = common::to_response(parts, bytes.into());
1515
1516 if let common::Retry::After(d) =
1517 dlg.http_failure(&response, error.as_ref().ok())
1518 {
1519 sleep(d).await;
1520 continue;
1521 }
1522
1523 dlg.finished(false);
1524
1525 return Err(match error {
1526 Ok(value) => common::Error::BadRequest(value),
1527 _ => common::Error::Failure(response),
1528 });
1529 }
1530 let response = {
1531 let bytes = common::to_bytes(body).await.unwrap_or_default();
1532 let encoded = common::to_string(&bytes);
1533 match serde_json::from_str(&encoded) {
1534 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1535 Err(error) => {
1536 dlg.response_json_decode_error(&encoded, &error);
1537 return Err(common::Error::JsonDecodeError(
1538 encoded.to_string(),
1539 error,
1540 ));
1541 }
1542 }
1543 };
1544
1545 dlg.finished(true);
1546 return Ok(response);
1547 }
1548 }
1549 }
1550 }
1551
1552 ///
1553 /// Sets the *token* query property to the given value.
1554 pub fn token(mut self, new_value: &str) -> MobileapppanelListCall<'a, C> {
1555 self._token = Some(new_value.to_string());
1556 self
1557 }
1558 ///
1559 /// Sets the *start index* query property to the given value.
1560 pub fn start_index(mut self, new_value: u32) -> MobileapppanelListCall<'a, C> {
1561 self._start_index = Some(new_value);
1562 self
1563 }
1564 ///
1565 /// Sets the *max results* query property to the given value.
1566 pub fn max_results(mut self, new_value: u32) -> MobileapppanelListCall<'a, C> {
1567 self._max_results = Some(new_value);
1568 self
1569 }
1570 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1571 /// while executing the actual API request.
1572 ///
1573 /// ````text
1574 /// It should be used to handle progress information, and to implement a certain level of resilience.
1575 /// ````
1576 ///
1577 /// Sets the *delegate* property to the given value.
1578 pub fn delegate(
1579 mut self,
1580 new_value: &'a mut dyn common::Delegate,
1581 ) -> MobileapppanelListCall<'a, C> {
1582 self._delegate = Some(new_value);
1583 self
1584 }
1585
1586 /// Set any additional parameter of the query string used in the request.
1587 /// It should be used to set parameters which are not yet available through their own
1588 /// setters.
1589 ///
1590 /// Please note that this method must not be used to set any of the known parameters
1591 /// which have their own setter method. If done anyway, the request will fail.
1592 ///
1593 /// # Additional Parameters
1594 ///
1595 /// * *alt* (query-string) - Data format for the response.
1596 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1597 /// * *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.
1598 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1599 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1600 /// * *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.
1601 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
1602 pub fn param<T>(mut self, name: T, value: T) -> MobileapppanelListCall<'a, C>
1603 where
1604 T: AsRef<str>,
1605 {
1606 self._additional_params
1607 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1608 self
1609 }
1610
1611 /// Identifies the authorization scope for the method you are building.
1612 ///
1613 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1614 /// [`Scope::Readonly`].
1615 ///
1616 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1617 /// tokens for more than one scope.
1618 ///
1619 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1620 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1621 /// sufficient, a read-write scope will do as well.
1622 pub fn add_scope<St>(mut self, scope: St) -> MobileapppanelListCall<'a, C>
1623 where
1624 St: AsRef<str>,
1625 {
1626 self._scopes.insert(String::from(scope.as_ref()));
1627 self
1628 }
1629 /// Identifies the authorization scope(s) for the method you are building.
1630 ///
1631 /// See [`Self::add_scope()`] for details.
1632 pub fn add_scopes<I, St>(mut self, scopes: I) -> MobileapppanelListCall<'a, C>
1633 where
1634 I: IntoIterator<Item = St>,
1635 St: AsRef<str>,
1636 {
1637 self._scopes
1638 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1639 self
1640 }
1641
1642 /// Removes all scopes, and no default scope will be used either.
1643 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1644 /// for details).
1645 pub fn clear_scopes(mut self) -> MobileapppanelListCall<'a, C> {
1646 self._scopes.clear();
1647 self
1648 }
1649}
1650
1651/// Updates a MobileAppPanel. Currently the only property that can be updated is the owners property.
1652///
1653/// A builder for the *update* method supported by a *mobileapppanel* resource.
1654/// It is not used directly, but through a [`MobileapppanelMethods`] instance.
1655///
1656/// # Example
1657///
1658/// Instantiate a resource method builder
1659///
1660/// ```test_harness,no_run
1661/// # extern crate hyper;
1662/// # extern crate hyper_rustls;
1663/// # extern crate google_consumersurveys2 as consumersurveys2;
1664/// use consumersurveys2::api::MobileAppPanel;
1665/// # async fn dox() {
1666/// # use consumersurveys2::{ConsumerSurveys, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1667///
1668/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1669/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
1670/// # .with_native_roots()
1671/// # .unwrap()
1672/// # .https_only()
1673/// # .enable_http2()
1674/// # .build();
1675///
1676/// # let executor = hyper_util::rt::TokioExecutor::new();
1677/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
1678/// # secret,
1679/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1680/// # yup_oauth2::client::CustomHyperClientBuilder::from(
1681/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
1682/// # ),
1683/// # ).build().await.unwrap();
1684///
1685/// # let client = hyper_util::client::legacy::Client::builder(
1686/// # hyper_util::rt::TokioExecutor::new()
1687/// # )
1688/// # .build(
1689/// # hyper_rustls::HttpsConnectorBuilder::new()
1690/// # .with_native_roots()
1691/// # .unwrap()
1692/// # .https_or_http()
1693/// # .enable_http2()
1694/// # .build()
1695/// # );
1696/// # let mut hub = ConsumerSurveys::new(client, auth);
1697/// // As the method needs a request, you would usually fill it with the desired information
1698/// // into the respective structure. Some of the parts shown here might not be applicable !
1699/// // Values shown here are possibly random and not representative !
1700/// let mut req = MobileAppPanel::default();
1701///
1702/// // You can configure optional parameters by calling the respective setters at will, and
1703/// // execute the final call using `doit()`.
1704/// // Values shown here are possibly random and not representative !
1705/// let result = hub.mobileapppanels().update(req, "panelId")
1706/// .doit().await;
1707/// # }
1708/// ```
1709pub struct MobileapppanelUpdateCall<'a, C>
1710where
1711 C: 'a,
1712{
1713 hub: &'a ConsumerSurveys<C>,
1714 _request: MobileAppPanel,
1715 _panel_id: String,
1716 _delegate: Option<&'a mut dyn common::Delegate>,
1717 _additional_params: HashMap<String, String>,
1718 _scopes: BTreeSet<String>,
1719}
1720
1721impl<'a, C> common::CallBuilder for MobileapppanelUpdateCall<'a, C> {}
1722
1723impl<'a, C> MobileapppanelUpdateCall<'a, C>
1724where
1725 C: common::Connector,
1726{
1727 /// Perform the operation you have build so far.
1728 pub async fn doit(mut self) -> common::Result<(common::Response, MobileAppPanel)> {
1729 use std::borrow::Cow;
1730 use std::io::{Read, Seek};
1731
1732 use common::{url::Params, ToParts};
1733 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1734
1735 let mut dd = common::DefaultDelegate;
1736 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1737 dlg.begin(common::MethodInfo {
1738 id: "consumersurveys.mobileapppanels.update",
1739 http_method: hyper::Method::PUT,
1740 });
1741
1742 for &field in ["alt", "panelId"].iter() {
1743 if self._additional_params.contains_key(field) {
1744 dlg.finished(false);
1745 return Err(common::Error::FieldClash(field));
1746 }
1747 }
1748
1749 let mut params = Params::with_capacity(4 + self._additional_params.len());
1750 params.push("panelId", self._panel_id);
1751
1752 params.extend(self._additional_params.iter());
1753
1754 params.push("alt", "json");
1755 let mut url = self.hub._base_url.clone() + "mobileAppPanels/{panelId}";
1756 if self._scopes.is_empty() {
1757 self._scopes.insert(Scope::Full.as_ref().to_string());
1758 }
1759
1760 #[allow(clippy::single_element_loop)]
1761 for &(find_this, param_name) in [("{panelId}", "panelId")].iter() {
1762 url = params.uri_replacement(url, param_name, find_this, false);
1763 }
1764 {
1765 let to_remove = ["panelId"];
1766 params.remove_params(&to_remove);
1767 }
1768
1769 let url = params.parse_with_url(&url);
1770
1771 let mut json_mime_type = mime::APPLICATION_JSON;
1772 let mut request_value_reader = {
1773 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
1774 common::remove_json_null_values(&mut value);
1775 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
1776 serde_json::to_writer(&mut dst, &value).unwrap();
1777 dst
1778 };
1779 let request_size = request_value_reader
1780 .seek(std::io::SeekFrom::End(0))
1781 .unwrap();
1782 request_value_reader
1783 .seek(std::io::SeekFrom::Start(0))
1784 .unwrap();
1785
1786 loop {
1787 let token = match self
1788 .hub
1789 .auth
1790 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1791 .await
1792 {
1793 Ok(token) => token,
1794 Err(e) => match dlg.token(e) {
1795 Ok(token) => token,
1796 Err(e) => {
1797 dlg.finished(false);
1798 return Err(common::Error::MissingToken(e));
1799 }
1800 },
1801 };
1802 request_value_reader
1803 .seek(std::io::SeekFrom::Start(0))
1804 .unwrap();
1805 let mut req_result = {
1806 let client = &self.hub.client;
1807 dlg.pre_request();
1808 let mut req_builder = hyper::Request::builder()
1809 .method(hyper::Method::PUT)
1810 .uri(url.as_str())
1811 .header(USER_AGENT, self.hub._user_agent.clone());
1812
1813 if let Some(token) = token.as_ref() {
1814 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1815 }
1816
1817 let request = req_builder
1818 .header(CONTENT_TYPE, json_mime_type.to_string())
1819 .header(CONTENT_LENGTH, request_size as u64)
1820 .body(common::to_body(
1821 request_value_reader.get_ref().clone().into(),
1822 ));
1823
1824 client.request(request.unwrap()).await
1825 };
1826
1827 match req_result {
1828 Err(err) => {
1829 if let common::Retry::After(d) = dlg.http_error(&err) {
1830 sleep(d).await;
1831 continue;
1832 }
1833 dlg.finished(false);
1834 return Err(common::Error::HttpError(err));
1835 }
1836 Ok(res) => {
1837 let (mut parts, body) = res.into_parts();
1838 let mut body = common::Body::new(body);
1839 if !parts.status.is_success() {
1840 let bytes = common::to_bytes(body).await.unwrap_or_default();
1841 let error = serde_json::from_str(&common::to_string(&bytes));
1842 let response = common::to_response(parts, bytes.into());
1843
1844 if let common::Retry::After(d) =
1845 dlg.http_failure(&response, error.as_ref().ok())
1846 {
1847 sleep(d).await;
1848 continue;
1849 }
1850
1851 dlg.finished(false);
1852
1853 return Err(match error {
1854 Ok(value) => common::Error::BadRequest(value),
1855 _ => common::Error::Failure(response),
1856 });
1857 }
1858 let response = {
1859 let bytes = common::to_bytes(body).await.unwrap_or_default();
1860 let encoded = common::to_string(&bytes);
1861 match serde_json::from_str(&encoded) {
1862 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1863 Err(error) => {
1864 dlg.response_json_decode_error(&encoded, &error);
1865 return Err(common::Error::JsonDecodeError(
1866 encoded.to_string(),
1867 error,
1868 ));
1869 }
1870 }
1871 };
1872
1873 dlg.finished(true);
1874 return Ok(response);
1875 }
1876 }
1877 }
1878 }
1879
1880 ///
1881 /// Sets the *request* property to the given value.
1882 ///
1883 /// Even though the property as already been set when instantiating this call,
1884 /// we provide this method for API completeness.
1885 pub fn request(mut self, new_value: MobileAppPanel) -> MobileapppanelUpdateCall<'a, C> {
1886 self._request = new_value;
1887 self
1888 }
1889 /// External URL ID for the panel.
1890 ///
1891 /// Sets the *panel id* path property to the given value.
1892 ///
1893 /// Even though the property as already been set when instantiating this call,
1894 /// we provide this method for API completeness.
1895 pub fn panel_id(mut self, new_value: &str) -> MobileapppanelUpdateCall<'a, C> {
1896 self._panel_id = new_value.to_string();
1897 self
1898 }
1899 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1900 /// while executing the actual API request.
1901 ///
1902 /// ````text
1903 /// It should be used to handle progress information, and to implement a certain level of resilience.
1904 /// ````
1905 ///
1906 /// Sets the *delegate* property to the given value.
1907 pub fn delegate(
1908 mut self,
1909 new_value: &'a mut dyn common::Delegate,
1910 ) -> MobileapppanelUpdateCall<'a, C> {
1911 self._delegate = Some(new_value);
1912 self
1913 }
1914
1915 /// Set any additional parameter of the query string used in the request.
1916 /// It should be used to set parameters which are not yet available through their own
1917 /// setters.
1918 ///
1919 /// Please note that this method must not be used to set any of the known parameters
1920 /// which have their own setter method. If done anyway, the request will fail.
1921 ///
1922 /// # Additional Parameters
1923 ///
1924 /// * *alt* (query-string) - Data format for the response.
1925 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1926 /// * *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.
1927 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1928 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1929 /// * *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.
1930 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
1931 pub fn param<T>(mut self, name: T, value: T) -> MobileapppanelUpdateCall<'a, C>
1932 where
1933 T: AsRef<str>,
1934 {
1935 self._additional_params
1936 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1937 self
1938 }
1939
1940 /// Identifies the authorization scope for the method you are building.
1941 ///
1942 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1943 /// [`Scope::Full`].
1944 ///
1945 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1946 /// tokens for more than one scope.
1947 ///
1948 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1949 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1950 /// sufficient, a read-write scope will do as well.
1951 pub fn add_scope<St>(mut self, scope: St) -> MobileapppanelUpdateCall<'a, C>
1952 where
1953 St: AsRef<str>,
1954 {
1955 self._scopes.insert(String::from(scope.as_ref()));
1956 self
1957 }
1958 /// Identifies the authorization scope(s) for the method you are building.
1959 ///
1960 /// See [`Self::add_scope()`] for details.
1961 pub fn add_scopes<I, St>(mut self, scopes: I) -> MobileapppanelUpdateCall<'a, C>
1962 where
1963 I: IntoIterator<Item = St>,
1964 St: AsRef<str>,
1965 {
1966 self._scopes
1967 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1968 self
1969 }
1970
1971 /// Removes all scopes, and no default scope will be used either.
1972 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1973 /// for details).
1974 pub fn clear_scopes(mut self) -> MobileapppanelUpdateCall<'a, C> {
1975 self._scopes.clear();
1976 self
1977 }
1978}
1979
1980/// Retrieves any survey results that have been produced so far. Results are formatted as an Excel file. You must add "?alt=media" to the URL as an argument to get results.
1981///
1982/// This method supports **media download**. To enable it, adjust the builder like this:
1983/// `.param("alt", "media")`.
1984/// Please note that due to missing multi-part support on the server side, you will only receive the media,
1985/// but not the `SurveyResults` structure that you would usually get. The latter will be a default value.
1986///
1987/// A builder for the *get* method supported by a *result* resource.
1988/// It is not used directly, but through a [`ResultMethods`] instance.
1989///
1990/// # Example
1991///
1992/// Instantiate a resource method builder
1993///
1994/// ```test_harness,no_run
1995/// # extern crate hyper;
1996/// # extern crate hyper_rustls;
1997/// # extern crate google_consumersurveys2 as consumersurveys2;
1998/// use consumersurveys2::api::ResultsGetRequest;
1999/// # async fn dox() {
2000/// # use consumersurveys2::{ConsumerSurveys, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2001///
2002/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2003/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
2004/// # .with_native_roots()
2005/// # .unwrap()
2006/// # .https_only()
2007/// # .enable_http2()
2008/// # .build();
2009///
2010/// # let executor = hyper_util::rt::TokioExecutor::new();
2011/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
2012/// # secret,
2013/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2014/// # yup_oauth2::client::CustomHyperClientBuilder::from(
2015/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
2016/// # ),
2017/// # ).build().await.unwrap();
2018///
2019/// # let client = hyper_util::client::legacy::Client::builder(
2020/// # hyper_util::rt::TokioExecutor::new()
2021/// # )
2022/// # .build(
2023/// # hyper_rustls::HttpsConnectorBuilder::new()
2024/// # .with_native_roots()
2025/// # .unwrap()
2026/// # .https_or_http()
2027/// # .enable_http2()
2028/// # .build()
2029/// # );
2030/// # let mut hub = ConsumerSurveys::new(client, auth);
2031/// // As the method needs a request, you would usually fill it with the desired information
2032/// // into the respective structure. Some of the parts shown here might not be applicable !
2033/// // Values shown here are possibly random and not representative !
2034/// let mut req = ResultsGetRequest::default();
2035///
2036/// // You can configure optional parameters by calling the respective setters at will, and
2037/// // execute the final call using `doit()`.
2038/// // Values shown here are possibly random and not representative !
2039/// let result = hub.results().get(req, "surveyUrlId")
2040/// .doit().await;
2041/// # }
2042/// ```
2043pub struct ResultGetCall<'a, C>
2044where
2045 C: 'a,
2046{
2047 hub: &'a ConsumerSurveys<C>,
2048 _request: ResultsGetRequest,
2049 _survey_url_id: String,
2050 _delegate: Option<&'a mut dyn common::Delegate>,
2051 _additional_params: HashMap<String, String>,
2052 _scopes: BTreeSet<String>,
2053}
2054
2055impl<'a, C> common::CallBuilder for ResultGetCall<'a, C> {}
2056
2057impl<'a, C> ResultGetCall<'a, C>
2058where
2059 C: common::Connector,
2060{
2061 /// Perform the operation you have build so far.
2062 pub async fn doit(mut self) -> common::Result<(common::Response, SurveyResults)> {
2063 use std::borrow::Cow;
2064 use std::io::{Read, Seek};
2065
2066 use common::{url::Params, ToParts};
2067 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2068
2069 let mut dd = common::DefaultDelegate;
2070 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2071 dlg.begin(common::MethodInfo {
2072 id: "consumersurveys.results.get",
2073 http_method: hyper::Method::GET,
2074 });
2075
2076 for &field in ["surveyUrlId"].iter() {
2077 if self._additional_params.contains_key(field) {
2078 dlg.finished(false);
2079 return Err(common::Error::FieldClash(field));
2080 }
2081 }
2082
2083 let mut params = Params::with_capacity(3 + self._additional_params.len());
2084 params.push("surveyUrlId", self._survey_url_id);
2085
2086 params.extend(self._additional_params.iter());
2087
2088 let (alt_field_missing, enable_resource_parsing) = {
2089 if let Some(value) = params.get("alt") {
2090 (false, value == "json")
2091 } else {
2092 (true, true)
2093 }
2094 };
2095 if alt_field_missing {
2096 params.push("alt", "json");
2097 }
2098 let mut url = self.hub._base_url.clone() + "surveys/{surveyUrlId}/results";
2099 if self._scopes.is_empty() {
2100 self._scopes.insert(Scope::Readonly.as_ref().to_string());
2101 }
2102
2103 #[allow(clippy::single_element_loop)]
2104 for &(find_this, param_name) in [("{surveyUrlId}", "surveyUrlId")].iter() {
2105 url = params.uri_replacement(url, param_name, find_this, false);
2106 }
2107 {
2108 let to_remove = ["surveyUrlId"];
2109 params.remove_params(&to_remove);
2110 }
2111
2112 let url = params.parse_with_url(&url);
2113
2114 let mut json_mime_type = mime::APPLICATION_JSON;
2115 let mut request_value_reader = {
2116 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
2117 common::remove_json_null_values(&mut value);
2118 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
2119 serde_json::to_writer(&mut dst, &value).unwrap();
2120 dst
2121 };
2122 let request_size = request_value_reader
2123 .seek(std::io::SeekFrom::End(0))
2124 .unwrap();
2125 request_value_reader
2126 .seek(std::io::SeekFrom::Start(0))
2127 .unwrap();
2128
2129 loop {
2130 let token = match self
2131 .hub
2132 .auth
2133 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2134 .await
2135 {
2136 Ok(token) => token,
2137 Err(e) => match dlg.token(e) {
2138 Ok(token) => token,
2139 Err(e) => {
2140 dlg.finished(false);
2141 return Err(common::Error::MissingToken(e));
2142 }
2143 },
2144 };
2145 request_value_reader
2146 .seek(std::io::SeekFrom::Start(0))
2147 .unwrap();
2148 let mut req_result = {
2149 let client = &self.hub.client;
2150 dlg.pre_request();
2151 let mut req_builder = hyper::Request::builder()
2152 .method(hyper::Method::GET)
2153 .uri(url.as_str())
2154 .header(USER_AGENT, self.hub._user_agent.clone());
2155
2156 if let Some(token) = token.as_ref() {
2157 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2158 }
2159
2160 let request = req_builder
2161 .header(CONTENT_TYPE, json_mime_type.to_string())
2162 .header(CONTENT_LENGTH, request_size as u64)
2163 .body(common::to_body(
2164 request_value_reader.get_ref().clone().into(),
2165 ));
2166
2167 client.request(request.unwrap()).await
2168 };
2169
2170 match req_result {
2171 Err(err) => {
2172 if let common::Retry::After(d) = dlg.http_error(&err) {
2173 sleep(d).await;
2174 continue;
2175 }
2176 dlg.finished(false);
2177 return Err(common::Error::HttpError(err));
2178 }
2179 Ok(res) => {
2180 let (mut parts, body) = res.into_parts();
2181 let mut body = common::Body::new(body);
2182 if !parts.status.is_success() {
2183 let bytes = common::to_bytes(body).await.unwrap_or_default();
2184 let error = serde_json::from_str(&common::to_string(&bytes));
2185 let response = common::to_response(parts, bytes.into());
2186
2187 if let common::Retry::After(d) =
2188 dlg.http_failure(&response, error.as_ref().ok())
2189 {
2190 sleep(d).await;
2191 continue;
2192 }
2193
2194 dlg.finished(false);
2195
2196 return Err(match error {
2197 Ok(value) => common::Error::BadRequest(value),
2198 _ => common::Error::Failure(response),
2199 });
2200 }
2201 let response = if enable_resource_parsing {
2202 let bytes = common::to_bytes(body).await.unwrap_or_default();
2203 let encoded = common::to_string(&bytes);
2204 match serde_json::from_str(&encoded) {
2205 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
2206 Err(error) => {
2207 dlg.response_json_decode_error(&encoded, &error);
2208 return Err(common::Error::JsonDecodeError(
2209 encoded.to_string(),
2210 error,
2211 ));
2212 }
2213 }
2214 } else {
2215 (
2216 common::Response::from_parts(parts, body),
2217 Default::default(),
2218 )
2219 };
2220
2221 dlg.finished(true);
2222 return Ok(response);
2223 }
2224 }
2225 }
2226 }
2227
2228 ///
2229 /// Sets the *request* property to the given value.
2230 ///
2231 /// Even though the property as already been set when instantiating this call,
2232 /// we provide this method for API completeness.
2233 pub fn request(mut self, new_value: ResultsGetRequest) -> ResultGetCall<'a, C> {
2234 self._request = new_value;
2235 self
2236 }
2237 /// External URL ID for the survey.
2238 ///
2239 /// Sets the *survey url id* path property to the given value.
2240 ///
2241 /// Even though the property as already been set when instantiating this call,
2242 /// we provide this method for API completeness.
2243 pub fn survey_url_id(mut self, new_value: &str) -> ResultGetCall<'a, C> {
2244 self._survey_url_id = new_value.to_string();
2245 self
2246 }
2247 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2248 /// while executing the actual API request.
2249 ///
2250 /// ````text
2251 /// It should be used to handle progress information, and to implement a certain level of resilience.
2252 /// ````
2253 ///
2254 /// Sets the *delegate* property to the given value.
2255 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> ResultGetCall<'a, C> {
2256 self._delegate = Some(new_value);
2257 self
2258 }
2259
2260 /// Set any additional parameter of the query string used in the request.
2261 /// It should be used to set parameters which are not yet available through their own
2262 /// setters.
2263 ///
2264 /// Please note that this method must not be used to set any of the known parameters
2265 /// which have their own setter method. If done anyway, the request will fail.
2266 ///
2267 /// # Additional Parameters
2268 ///
2269 /// * *alt* (query-string) - Data format for the response.
2270 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2271 /// * *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.
2272 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2273 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2274 /// * *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.
2275 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
2276 pub fn param<T>(mut self, name: T, value: T) -> ResultGetCall<'a, C>
2277 where
2278 T: AsRef<str>,
2279 {
2280 self._additional_params
2281 .insert(name.as_ref().to_string(), value.as_ref().to_string());
2282 self
2283 }
2284
2285 /// Identifies the authorization scope for the method you are building.
2286 ///
2287 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2288 /// [`Scope::Readonly`].
2289 ///
2290 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2291 /// tokens for more than one scope.
2292 ///
2293 /// Usually there is more than one suitable scope to authorize an operation, some of which may
2294 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2295 /// sufficient, a read-write scope will do as well.
2296 pub fn add_scope<St>(mut self, scope: St) -> ResultGetCall<'a, C>
2297 where
2298 St: AsRef<str>,
2299 {
2300 self._scopes.insert(String::from(scope.as_ref()));
2301 self
2302 }
2303 /// Identifies the authorization scope(s) for the method you are building.
2304 ///
2305 /// See [`Self::add_scope()`] for details.
2306 pub fn add_scopes<I, St>(mut self, scopes: I) -> ResultGetCall<'a, C>
2307 where
2308 I: IntoIterator<Item = St>,
2309 St: AsRef<str>,
2310 {
2311 self._scopes
2312 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2313 self
2314 }
2315
2316 /// Removes all scopes, and no default scope will be used either.
2317 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2318 /// for details).
2319 pub fn clear_scopes(mut self) -> ResultGetCall<'a, C> {
2320 self._scopes.clear();
2321 self
2322 }
2323}
2324
2325/// Removes a survey from view in all user GET requests.
2326///
2327/// A builder for the *delete* method supported by a *survey* resource.
2328/// It is not used directly, but through a [`SurveyMethods`] instance.
2329///
2330/// # Example
2331///
2332/// Instantiate a resource method builder
2333///
2334/// ```test_harness,no_run
2335/// # extern crate hyper;
2336/// # extern crate hyper_rustls;
2337/// # extern crate google_consumersurveys2 as consumersurveys2;
2338/// # async fn dox() {
2339/// # use consumersurveys2::{ConsumerSurveys, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2340///
2341/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2342/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
2343/// # .with_native_roots()
2344/// # .unwrap()
2345/// # .https_only()
2346/// # .enable_http2()
2347/// # .build();
2348///
2349/// # let executor = hyper_util::rt::TokioExecutor::new();
2350/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
2351/// # secret,
2352/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2353/// # yup_oauth2::client::CustomHyperClientBuilder::from(
2354/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
2355/// # ),
2356/// # ).build().await.unwrap();
2357///
2358/// # let client = hyper_util::client::legacy::Client::builder(
2359/// # hyper_util::rt::TokioExecutor::new()
2360/// # )
2361/// # .build(
2362/// # hyper_rustls::HttpsConnectorBuilder::new()
2363/// # .with_native_roots()
2364/// # .unwrap()
2365/// # .https_or_http()
2366/// # .enable_http2()
2367/// # .build()
2368/// # );
2369/// # let mut hub = ConsumerSurveys::new(client, auth);
2370/// // You can configure optional parameters by calling the respective setters at will, and
2371/// // execute the final call using `doit()`.
2372/// // Values shown here are possibly random and not representative !
2373/// let result = hub.surveys().delete("surveyUrlId")
2374/// .doit().await;
2375/// # }
2376/// ```
2377pub struct SurveyDeleteCall<'a, C>
2378where
2379 C: 'a,
2380{
2381 hub: &'a ConsumerSurveys<C>,
2382 _survey_url_id: String,
2383 _delegate: Option<&'a mut dyn common::Delegate>,
2384 _additional_params: HashMap<String, String>,
2385 _scopes: BTreeSet<String>,
2386}
2387
2388impl<'a, C> common::CallBuilder for SurveyDeleteCall<'a, C> {}
2389
2390impl<'a, C> SurveyDeleteCall<'a, C>
2391where
2392 C: common::Connector,
2393{
2394 /// Perform the operation you have build so far.
2395 pub async fn doit(mut self) -> common::Result<(common::Response, SurveysDeleteResponse)> {
2396 use std::borrow::Cow;
2397 use std::io::{Read, Seek};
2398
2399 use common::{url::Params, ToParts};
2400 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2401
2402 let mut dd = common::DefaultDelegate;
2403 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2404 dlg.begin(common::MethodInfo {
2405 id: "consumersurveys.surveys.delete",
2406 http_method: hyper::Method::DELETE,
2407 });
2408
2409 for &field in ["alt", "surveyUrlId"].iter() {
2410 if self._additional_params.contains_key(field) {
2411 dlg.finished(false);
2412 return Err(common::Error::FieldClash(field));
2413 }
2414 }
2415
2416 let mut params = Params::with_capacity(3 + self._additional_params.len());
2417 params.push("surveyUrlId", self._survey_url_id);
2418
2419 params.extend(self._additional_params.iter());
2420
2421 params.push("alt", "json");
2422 let mut url = self.hub._base_url.clone() + "surveys/{surveyUrlId}";
2423 if self._scopes.is_empty() {
2424 self._scopes.insert(Scope::Full.as_ref().to_string());
2425 }
2426
2427 #[allow(clippy::single_element_loop)]
2428 for &(find_this, param_name) in [("{surveyUrlId}", "surveyUrlId")].iter() {
2429 url = params.uri_replacement(url, param_name, find_this, false);
2430 }
2431 {
2432 let to_remove = ["surveyUrlId"];
2433 params.remove_params(&to_remove);
2434 }
2435
2436 let url = params.parse_with_url(&url);
2437
2438 loop {
2439 let token = match self
2440 .hub
2441 .auth
2442 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2443 .await
2444 {
2445 Ok(token) => token,
2446 Err(e) => match dlg.token(e) {
2447 Ok(token) => token,
2448 Err(e) => {
2449 dlg.finished(false);
2450 return Err(common::Error::MissingToken(e));
2451 }
2452 },
2453 };
2454 let mut req_result = {
2455 let client = &self.hub.client;
2456 dlg.pre_request();
2457 let mut req_builder = hyper::Request::builder()
2458 .method(hyper::Method::DELETE)
2459 .uri(url.as_str())
2460 .header(USER_AGENT, self.hub._user_agent.clone());
2461
2462 if let Some(token) = token.as_ref() {
2463 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2464 }
2465
2466 let request = req_builder
2467 .header(CONTENT_LENGTH, 0_u64)
2468 .body(common::to_body::<String>(None));
2469
2470 client.request(request.unwrap()).await
2471 };
2472
2473 match req_result {
2474 Err(err) => {
2475 if let common::Retry::After(d) = dlg.http_error(&err) {
2476 sleep(d).await;
2477 continue;
2478 }
2479 dlg.finished(false);
2480 return Err(common::Error::HttpError(err));
2481 }
2482 Ok(res) => {
2483 let (mut parts, body) = res.into_parts();
2484 let mut body = common::Body::new(body);
2485 if !parts.status.is_success() {
2486 let bytes = common::to_bytes(body).await.unwrap_or_default();
2487 let error = serde_json::from_str(&common::to_string(&bytes));
2488 let response = common::to_response(parts, bytes.into());
2489
2490 if let common::Retry::After(d) =
2491 dlg.http_failure(&response, error.as_ref().ok())
2492 {
2493 sleep(d).await;
2494 continue;
2495 }
2496
2497 dlg.finished(false);
2498
2499 return Err(match error {
2500 Ok(value) => common::Error::BadRequest(value),
2501 _ => common::Error::Failure(response),
2502 });
2503 }
2504 let response = {
2505 let bytes = common::to_bytes(body).await.unwrap_or_default();
2506 let encoded = common::to_string(&bytes);
2507 match serde_json::from_str(&encoded) {
2508 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
2509 Err(error) => {
2510 dlg.response_json_decode_error(&encoded, &error);
2511 return Err(common::Error::JsonDecodeError(
2512 encoded.to_string(),
2513 error,
2514 ));
2515 }
2516 }
2517 };
2518
2519 dlg.finished(true);
2520 return Ok(response);
2521 }
2522 }
2523 }
2524 }
2525
2526 /// External URL ID for the survey.
2527 ///
2528 /// Sets the *survey url id* path property to the given value.
2529 ///
2530 /// Even though the property as already been set when instantiating this call,
2531 /// we provide this method for API completeness.
2532 pub fn survey_url_id(mut self, new_value: &str) -> SurveyDeleteCall<'a, C> {
2533 self._survey_url_id = new_value.to_string();
2534 self
2535 }
2536 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2537 /// while executing the actual API request.
2538 ///
2539 /// ````text
2540 /// It should be used to handle progress information, and to implement a certain level of resilience.
2541 /// ````
2542 ///
2543 /// Sets the *delegate* property to the given value.
2544 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> SurveyDeleteCall<'a, C> {
2545 self._delegate = Some(new_value);
2546 self
2547 }
2548
2549 /// Set any additional parameter of the query string used in the request.
2550 /// It should be used to set parameters which are not yet available through their own
2551 /// setters.
2552 ///
2553 /// Please note that this method must not be used to set any of the known parameters
2554 /// which have their own setter method. If done anyway, the request will fail.
2555 ///
2556 /// # Additional Parameters
2557 ///
2558 /// * *alt* (query-string) - Data format for the response.
2559 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2560 /// * *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.
2561 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2562 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2563 /// * *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.
2564 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
2565 pub fn param<T>(mut self, name: T, value: T) -> SurveyDeleteCall<'a, C>
2566 where
2567 T: AsRef<str>,
2568 {
2569 self._additional_params
2570 .insert(name.as_ref().to_string(), value.as_ref().to_string());
2571 self
2572 }
2573
2574 /// Identifies the authorization scope for the method you are building.
2575 ///
2576 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2577 /// [`Scope::Full`].
2578 ///
2579 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2580 /// tokens for more than one scope.
2581 ///
2582 /// Usually there is more than one suitable scope to authorize an operation, some of which may
2583 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2584 /// sufficient, a read-write scope will do as well.
2585 pub fn add_scope<St>(mut self, scope: St) -> SurveyDeleteCall<'a, C>
2586 where
2587 St: AsRef<str>,
2588 {
2589 self._scopes.insert(String::from(scope.as_ref()));
2590 self
2591 }
2592 /// Identifies the authorization scope(s) for the method you are building.
2593 ///
2594 /// See [`Self::add_scope()`] for details.
2595 pub fn add_scopes<I, St>(mut self, scopes: I) -> SurveyDeleteCall<'a, C>
2596 where
2597 I: IntoIterator<Item = St>,
2598 St: AsRef<str>,
2599 {
2600 self._scopes
2601 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2602 self
2603 }
2604
2605 /// Removes all scopes, and no default scope will be used either.
2606 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2607 /// for details).
2608 pub fn clear_scopes(mut self) -> SurveyDeleteCall<'a, C> {
2609 self._scopes.clear();
2610 self
2611 }
2612}
2613
2614/// Retrieves information about the specified survey.
2615///
2616/// A builder for the *get* method supported by a *survey* resource.
2617/// It is not used directly, but through a [`SurveyMethods`] instance.
2618///
2619/// # Example
2620///
2621/// Instantiate a resource method builder
2622///
2623/// ```test_harness,no_run
2624/// # extern crate hyper;
2625/// # extern crate hyper_rustls;
2626/// # extern crate google_consumersurveys2 as consumersurveys2;
2627/// # async fn dox() {
2628/// # use consumersurveys2::{ConsumerSurveys, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2629///
2630/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2631/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
2632/// # .with_native_roots()
2633/// # .unwrap()
2634/// # .https_only()
2635/// # .enable_http2()
2636/// # .build();
2637///
2638/// # let executor = hyper_util::rt::TokioExecutor::new();
2639/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
2640/// # secret,
2641/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2642/// # yup_oauth2::client::CustomHyperClientBuilder::from(
2643/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
2644/// # ),
2645/// # ).build().await.unwrap();
2646///
2647/// # let client = hyper_util::client::legacy::Client::builder(
2648/// # hyper_util::rt::TokioExecutor::new()
2649/// # )
2650/// # .build(
2651/// # hyper_rustls::HttpsConnectorBuilder::new()
2652/// # .with_native_roots()
2653/// # .unwrap()
2654/// # .https_or_http()
2655/// # .enable_http2()
2656/// # .build()
2657/// # );
2658/// # let mut hub = ConsumerSurveys::new(client, auth);
2659/// // You can configure optional parameters by calling the respective setters at will, and
2660/// // execute the final call using `doit()`.
2661/// // Values shown here are possibly random and not representative !
2662/// let result = hub.surveys().get("surveyUrlId")
2663/// .doit().await;
2664/// # }
2665/// ```
2666pub struct SurveyGetCall<'a, C>
2667where
2668 C: 'a,
2669{
2670 hub: &'a ConsumerSurveys<C>,
2671 _survey_url_id: String,
2672 _delegate: Option<&'a mut dyn common::Delegate>,
2673 _additional_params: HashMap<String, String>,
2674 _scopes: BTreeSet<String>,
2675}
2676
2677impl<'a, C> common::CallBuilder for SurveyGetCall<'a, C> {}
2678
2679impl<'a, C> SurveyGetCall<'a, C>
2680where
2681 C: common::Connector,
2682{
2683 /// Perform the operation you have build so far.
2684 pub async fn doit(mut self) -> common::Result<(common::Response, Survey)> {
2685 use std::borrow::Cow;
2686 use std::io::{Read, Seek};
2687
2688 use common::{url::Params, ToParts};
2689 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2690
2691 let mut dd = common::DefaultDelegate;
2692 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2693 dlg.begin(common::MethodInfo {
2694 id: "consumersurveys.surveys.get",
2695 http_method: hyper::Method::GET,
2696 });
2697
2698 for &field in ["alt", "surveyUrlId"].iter() {
2699 if self._additional_params.contains_key(field) {
2700 dlg.finished(false);
2701 return Err(common::Error::FieldClash(field));
2702 }
2703 }
2704
2705 let mut params = Params::with_capacity(3 + self._additional_params.len());
2706 params.push("surveyUrlId", self._survey_url_id);
2707
2708 params.extend(self._additional_params.iter());
2709
2710 params.push("alt", "json");
2711 let mut url = self.hub._base_url.clone() + "surveys/{surveyUrlId}";
2712 if self._scopes.is_empty() {
2713 self._scopes.insert(Scope::Readonly.as_ref().to_string());
2714 }
2715
2716 #[allow(clippy::single_element_loop)]
2717 for &(find_this, param_name) in [("{surveyUrlId}", "surveyUrlId")].iter() {
2718 url = params.uri_replacement(url, param_name, find_this, false);
2719 }
2720 {
2721 let to_remove = ["surveyUrlId"];
2722 params.remove_params(&to_remove);
2723 }
2724
2725 let url = params.parse_with_url(&url);
2726
2727 loop {
2728 let token = match self
2729 .hub
2730 .auth
2731 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2732 .await
2733 {
2734 Ok(token) => token,
2735 Err(e) => match dlg.token(e) {
2736 Ok(token) => token,
2737 Err(e) => {
2738 dlg.finished(false);
2739 return Err(common::Error::MissingToken(e));
2740 }
2741 },
2742 };
2743 let mut req_result = {
2744 let client = &self.hub.client;
2745 dlg.pre_request();
2746 let mut req_builder = hyper::Request::builder()
2747 .method(hyper::Method::GET)
2748 .uri(url.as_str())
2749 .header(USER_AGENT, self.hub._user_agent.clone());
2750
2751 if let Some(token) = token.as_ref() {
2752 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2753 }
2754
2755 let request = req_builder
2756 .header(CONTENT_LENGTH, 0_u64)
2757 .body(common::to_body::<String>(None));
2758
2759 client.request(request.unwrap()).await
2760 };
2761
2762 match req_result {
2763 Err(err) => {
2764 if let common::Retry::After(d) = dlg.http_error(&err) {
2765 sleep(d).await;
2766 continue;
2767 }
2768 dlg.finished(false);
2769 return Err(common::Error::HttpError(err));
2770 }
2771 Ok(res) => {
2772 let (mut parts, body) = res.into_parts();
2773 let mut body = common::Body::new(body);
2774 if !parts.status.is_success() {
2775 let bytes = common::to_bytes(body).await.unwrap_or_default();
2776 let error = serde_json::from_str(&common::to_string(&bytes));
2777 let response = common::to_response(parts, bytes.into());
2778
2779 if let common::Retry::After(d) =
2780 dlg.http_failure(&response, error.as_ref().ok())
2781 {
2782 sleep(d).await;
2783 continue;
2784 }
2785
2786 dlg.finished(false);
2787
2788 return Err(match error {
2789 Ok(value) => common::Error::BadRequest(value),
2790 _ => common::Error::Failure(response),
2791 });
2792 }
2793 let response = {
2794 let bytes = common::to_bytes(body).await.unwrap_or_default();
2795 let encoded = common::to_string(&bytes);
2796 match serde_json::from_str(&encoded) {
2797 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
2798 Err(error) => {
2799 dlg.response_json_decode_error(&encoded, &error);
2800 return Err(common::Error::JsonDecodeError(
2801 encoded.to_string(),
2802 error,
2803 ));
2804 }
2805 }
2806 };
2807
2808 dlg.finished(true);
2809 return Ok(response);
2810 }
2811 }
2812 }
2813 }
2814
2815 /// External URL ID for the survey.
2816 ///
2817 /// Sets the *survey url id* path property to the given value.
2818 ///
2819 /// Even though the property as already been set when instantiating this call,
2820 /// we provide this method for API completeness.
2821 pub fn survey_url_id(mut self, new_value: &str) -> SurveyGetCall<'a, C> {
2822 self._survey_url_id = new_value.to_string();
2823 self
2824 }
2825 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2826 /// while executing the actual API request.
2827 ///
2828 /// ````text
2829 /// It should be used to handle progress information, and to implement a certain level of resilience.
2830 /// ````
2831 ///
2832 /// Sets the *delegate* property to the given value.
2833 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> SurveyGetCall<'a, C> {
2834 self._delegate = Some(new_value);
2835 self
2836 }
2837
2838 /// Set any additional parameter of the query string used in the request.
2839 /// It should be used to set parameters which are not yet available through their own
2840 /// setters.
2841 ///
2842 /// Please note that this method must not be used to set any of the known parameters
2843 /// which have their own setter method. If done anyway, the request will fail.
2844 ///
2845 /// # Additional Parameters
2846 ///
2847 /// * *alt* (query-string) - Data format for the response.
2848 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2849 /// * *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.
2850 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2851 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2852 /// * *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.
2853 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
2854 pub fn param<T>(mut self, name: T, value: T) -> SurveyGetCall<'a, C>
2855 where
2856 T: AsRef<str>,
2857 {
2858 self._additional_params
2859 .insert(name.as_ref().to_string(), value.as_ref().to_string());
2860 self
2861 }
2862
2863 /// Identifies the authorization scope for the method you are building.
2864 ///
2865 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2866 /// [`Scope::Readonly`].
2867 ///
2868 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2869 /// tokens for more than one scope.
2870 ///
2871 /// Usually there is more than one suitable scope to authorize an operation, some of which may
2872 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2873 /// sufficient, a read-write scope will do as well.
2874 pub fn add_scope<St>(mut self, scope: St) -> SurveyGetCall<'a, C>
2875 where
2876 St: AsRef<str>,
2877 {
2878 self._scopes.insert(String::from(scope.as_ref()));
2879 self
2880 }
2881 /// Identifies the authorization scope(s) for the method you are building.
2882 ///
2883 /// See [`Self::add_scope()`] for details.
2884 pub fn add_scopes<I, St>(mut self, scopes: I) -> SurveyGetCall<'a, C>
2885 where
2886 I: IntoIterator<Item = St>,
2887 St: AsRef<str>,
2888 {
2889 self._scopes
2890 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2891 self
2892 }
2893
2894 /// Removes all scopes, and no default scope will be used either.
2895 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2896 /// for details).
2897 pub fn clear_scopes(mut self) -> SurveyGetCall<'a, C> {
2898 self._scopes.clear();
2899 self
2900 }
2901}
2902
2903/// Creates a survey.
2904///
2905/// A builder for the *insert* method supported by a *survey* resource.
2906/// It is not used directly, but through a [`SurveyMethods`] instance.
2907///
2908/// # Example
2909///
2910/// Instantiate a resource method builder
2911///
2912/// ```test_harness,no_run
2913/// # extern crate hyper;
2914/// # extern crate hyper_rustls;
2915/// # extern crate google_consumersurveys2 as consumersurveys2;
2916/// use consumersurveys2::api::Survey;
2917/// # async fn dox() {
2918/// # use consumersurveys2::{ConsumerSurveys, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2919///
2920/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2921/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
2922/// # .with_native_roots()
2923/// # .unwrap()
2924/// # .https_only()
2925/// # .enable_http2()
2926/// # .build();
2927///
2928/// # let executor = hyper_util::rt::TokioExecutor::new();
2929/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
2930/// # secret,
2931/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2932/// # yup_oauth2::client::CustomHyperClientBuilder::from(
2933/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
2934/// # ),
2935/// # ).build().await.unwrap();
2936///
2937/// # let client = hyper_util::client::legacy::Client::builder(
2938/// # hyper_util::rt::TokioExecutor::new()
2939/// # )
2940/// # .build(
2941/// # hyper_rustls::HttpsConnectorBuilder::new()
2942/// # .with_native_roots()
2943/// # .unwrap()
2944/// # .https_or_http()
2945/// # .enable_http2()
2946/// # .build()
2947/// # );
2948/// # let mut hub = ConsumerSurveys::new(client, auth);
2949/// // As the method needs a request, you would usually fill it with the desired information
2950/// // into the respective structure. Some of the parts shown here might not be applicable !
2951/// // Values shown here are possibly random and not representative !
2952/// let mut req = Survey::default();
2953///
2954/// // You can configure optional parameters by calling the respective setters at will, and
2955/// // execute the final call using `doit()`.
2956/// // Values shown here are possibly random and not representative !
2957/// let result = hub.surveys().insert(req)
2958/// .doit().await;
2959/// # }
2960/// ```
2961pub struct SurveyInsertCall<'a, C>
2962where
2963 C: 'a,
2964{
2965 hub: &'a ConsumerSurveys<C>,
2966 _request: Survey,
2967 _delegate: Option<&'a mut dyn common::Delegate>,
2968 _additional_params: HashMap<String, String>,
2969 _scopes: BTreeSet<String>,
2970}
2971
2972impl<'a, C> common::CallBuilder for SurveyInsertCall<'a, C> {}
2973
2974impl<'a, C> SurveyInsertCall<'a, C>
2975where
2976 C: common::Connector,
2977{
2978 /// Perform the operation you have build so far.
2979 pub async fn doit(mut self) -> common::Result<(common::Response, Survey)> {
2980 use std::borrow::Cow;
2981 use std::io::{Read, Seek};
2982
2983 use common::{url::Params, ToParts};
2984 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2985
2986 let mut dd = common::DefaultDelegate;
2987 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2988 dlg.begin(common::MethodInfo {
2989 id: "consumersurveys.surveys.insert",
2990 http_method: hyper::Method::POST,
2991 });
2992
2993 for &field in ["alt"].iter() {
2994 if self._additional_params.contains_key(field) {
2995 dlg.finished(false);
2996 return Err(common::Error::FieldClash(field));
2997 }
2998 }
2999
3000 let mut params = Params::with_capacity(3 + self._additional_params.len());
3001
3002 params.extend(self._additional_params.iter());
3003
3004 params.push("alt", "json");
3005 let mut url = self.hub._base_url.clone() + "surveys";
3006 if self._scopes.is_empty() {
3007 self._scopes.insert(Scope::Full.as_ref().to_string());
3008 }
3009
3010 let url = params.parse_with_url(&url);
3011
3012 let mut json_mime_type = mime::APPLICATION_JSON;
3013 let mut request_value_reader = {
3014 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
3015 common::remove_json_null_values(&mut value);
3016 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
3017 serde_json::to_writer(&mut dst, &value).unwrap();
3018 dst
3019 };
3020 let request_size = request_value_reader
3021 .seek(std::io::SeekFrom::End(0))
3022 .unwrap();
3023 request_value_reader
3024 .seek(std::io::SeekFrom::Start(0))
3025 .unwrap();
3026
3027 loop {
3028 let token = match self
3029 .hub
3030 .auth
3031 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
3032 .await
3033 {
3034 Ok(token) => token,
3035 Err(e) => match dlg.token(e) {
3036 Ok(token) => token,
3037 Err(e) => {
3038 dlg.finished(false);
3039 return Err(common::Error::MissingToken(e));
3040 }
3041 },
3042 };
3043 request_value_reader
3044 .seek(std::io::SeekFrom::Start(0))
3045 .unwrap();
3046 let mut req_result = {
3047 let client = &self.hub.client;
3048 dlg.pre_request();
3049 let mut req_builder = hyper::Request::builder()
3050 .method(hyper::Method::POST)
3051 .uri(url.as_str())
3052 .header(USER_AGENT, self.hub._user_agent.clone());
3053
3054 if let Some(token) = token.as_ref() {
3055 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
3056 }
3057
3058 let request = req_builder
3059 .header(CONTENT_TYPE, json_mime_type.to_string())
3060 .header(CONTENT_LENGTH, request_size as u64)
3061 .body(common::to_body(
3062 request_value_reader.get_ref().clone().into(),
3063 ));
3064
3065 client.request(request.unwrap()).await
3066 };
3067
3068 match req_result {
3069 Err(err) => {
3070 if let common::Retry::After(d) = dlg.http_error(&err) {
3071 sleep(d).await;
3072 continue;
3073 }
3074 dlg.finished(false);
3075 return Err(common::Error::HttpError(err));
3076 }
3077 Ok(res) => {
3078 let (mut parts, body) = res.into_parts();
3079 let mut body = common::Body::new(body);
3080 if !parts.status.is_success() {
3081 let bytes = common::to_bytes(body).await.unwrap_or_default();
3082 let error = serde_json::from_str(&common::to_string(&bytes));
3083 let response = common::to_response(parts, bytes.into());
3084
3085 if let common::Retry::After(d) =
3086 dlg.http_failure(&response, error.as_ref().ok())
3087 {
3088 sleep(d).await;
3089 continue;
3090 }
3091
3092 dlg.finished(false);
3093
3094 return Err(match error {
3095 Ok(value) => common::Error::BadRequest(value),
3096 _ => common::Error::Failure(response),
3097 });
3098 }
3099 let response = {
3100 let bytes = common::to_bytes(body).await.unwrap_or_default();
3101 let encoded = common::to_string(&bytes);
3102 match serde_json::from_str(&encoded) {
3103 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
3104 Err(error) => {
3105 dlg.response_json_decode_error(&encoded, &error);
3106 return Err(common::Error::JsonDecodeError(
3107 encoded.to_string(),
3108 error,
3109 ));
3110 }
3111 }
3112 };
3113
3114 dlg.finished(true);
3115 return Ok(response);
3116 }
3117 }
3118 }
3119 }
3120
3121 ///
3122 /// Sets the *request* property to the given value.
3123 ///
3124 /// Even though the property as already been set when instantiating this call,
3125 /// we provide this method for API completeness.
3126 pub fn request(mut self, new_value: Survey) -> SurveyInsertCall<'a, C> {
3127 self._request = new_value;
3128 self
3129 }
3130 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
3131 /// while executing the actual API request.
3132 ///
3133 /// ````text
3134 /// It should be used to handle progress information, and to implement a certain level of resilience.
3135 /// ````
3136 ///
3137 /// Sets the *delegate* property to the given value.
3138 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> SurveyInsertCall<'a, C> {
3139 self._delegate = Some(new_value);
3140 self
3141 }
3142
3143 /// Set any additional parameter of the query string used in the request.
3144 /// It should be used to set parameters which are not yet available through their own
3145 /// setters.
3146 ///
3147 /// Please note that this method must not be used to set any of the known parameters
3148 /// which have their own setter method. If done anyway, the request will fail.
3149 ///
3150 /// # Additional Parameters
3151 ///
3152 /// * *alt* (query-string) - Data format for the response.
3153 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
3154 /// * *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.
3155 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
3156 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
3157 /// * *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.
3158 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
3159 pub fn param<T>(mut self, name: T, value: T) -> SurveyInsertCall<'a, C>
3160 where
3161 T: AsRef<str>,
3162 {
3163 self._additional_params
3164 .insert(name.as_ref().to_string(), value.as_ref().to_string());
3165 self
3166 }
3167
3168 /// Identifies the authorization scope for the method you are building.
3169 ///
3170 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
3171 /// [`Scope::Full`].
3172 ///
3173 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
3174 /// tokens for more than one scope.
3175 ///
3176 /// Usually there is more than one suitable scope to authorize an operation, some of which may
3177 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
3178 /// sufficient, a read-write scope will do as well.
3179 pub fn add_scope<St>(mut self, scope: St) -> SurveyInsertCall<'a, C>
3180 where
3181 St: AsRef<str>,
3182 {
3183 self._scopes.insert(String::from(scope.as_ref()));
3184 self
3185 }
3186 /// Identifies the authorization scope(s) for the method you are building.
3187 ///
3188 /// See [`Self::add_scope()`] for details.
3189 pub fn add_scopes<I, St>(mut self, scopes: I) -> SurveyInsertCall<'a, C>
3190 where
3191 I: IntoIterator<Item = St>,
3192 St: AsRef<str>,
3193 {
3194 self._scopes
3195 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
3196 self
3197 }
3198
3199 /// Removes all scopes, and no default scope will be used either.
3200 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
3201 /// for details).
3202 pub fn clear_scopes(mut self) -> SurveyInsertCall<'a, C> {
3203 self._scopes.clear();
3204 self
3205 }
3206}
3207
3208/// Lists the surveys owned by the authenticated user.
3209///
3210/// A builder for the *list* method supported by a *survey* resource.
3211/// It is not used directly, but through a [`SurveyMethods`] instance.
3212///
3213/// # Example
3214///
3215/// Instantiate a resource method builder
3216///
3217/// ```test_harness,no_run
3218/// # extern crate hyper;
3219/// # extern crate hyper_rustls;
3220/// # extern crate google_consumersurveys2 as consumersurveys2;
3221/// # async fn dox() {
3222/// # use consumersurveys2::{ConsumerSurveys, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
3223///
3224/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
3225/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
3226/// # .with_native_roots()
3227/// # .unwrap()
3228/// # .https_only()
3229/// # .enable_http2()
3230/// # .build();
3231///
3232/// # let executor = hyper_util::rt::TokioExecutor::new();
3233/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
3234/// # secret,
3235/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
3236/// # yup_oauth2::client::CustomHyperClientBuilder::from(
3237/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
3238/// # ),
3239/// # ).build().await.unwrap();
3240///
3241/// # let client = hyper_util::client::legacy::Client::builder(
3242/// # hyper_util::rt::TokioExecutor::new()
3243/// # )
3244/// # .build(
3245/// # hyper_rustls::HttpsConnectorBuilder::new()
3246/// # .with_native_roots()
3247/// # .unwrap()
3248/// # .https_or_http()
3249/// # .enable_http2()
3250/// # .build()
3251/// # );
3252/// # let mut hub = ConsumerSurveys::new(client, auth);
3253/// // You can configure optional parameters by calling the respective setters at will, and
3254/// // execute the final call using `doit()`.
3255/// // Values shown here are possibly random and not representative !
3256/// let result = hub.surveys().list()
3257/// .token("dolor")
3258/// .start_index(84)
3259/// .max_results(46)
3260/// .doit().await;
3261/// # }
3262/// ```
3263pub struct SurveyListCall<'a, C>
3264where
3265 C: 'a,
3266{
3267 hub: &'a ConsumerSurveys<C>,
3268 _token: Option<String>,
3269 _start_index: Option<u32>,
3270 _max_results: Option<u32>,
3271 _delegate: Option<&'a mut dyn common::Delegate>,
3272 _additional_params: HashMap<String, String>,
3273 _scopes: BTreeSet<String>,
3274}
3275
3276impl<'a, C> common::CallBuilder for SurveyListCall<'a, C> {}
3277
3278impl<'a, C> SurveyListCall<'a, C>
3279where
3280 C: common::Connector,
3281{
3282 /// Perform the operation you have build so far.
3283 pub async fn doit(mut self) -> common::Result<(common::Response, SurveysListResponse)> {
3284 use std::borrow::Cow;
3285 use std::io::{Read, Seek};
3286
3287 use common::{url::Params, ToParts};
3288 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
3289
3290 let mut dd = common::DefaultDelegate;
3291 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
3292 dlg.begin(common::MethodInfo {
3293 id: "consumersurveys.surveys.list",
3294 http_method: hyper::Method::GET,
3295 });
3296
3297 for &field in ["alt", "token", "startIndex", "maxResults"].iter() {
3298 if self._additional_params.contains_key(field) {
3299 dlg.finished(false);
3300 return Err(common::Error::FieldClash(field));
3301 }
3302 }
3303
3304 let mut params = Params::with_capacity(5 + self._additional_params.len());
3305 if let Some(value) = self._token.as_ref() {
3306 params.push("token", value);
3307 }
3308 if let Some(value) = self._start_index.as_ref() {
3309 params.push("startIndex", value.to_string());
3310 }
3311 if let Some(value) = self._max_results.as_ref() {
3312 params.push("maxResults", value.to_string());
3313 }
3314
3315 params.extend(self._additional_params.iter());
3316
3317 params.push("alt", "json");
3318 let mut url = self.hub._base_url.clone() + "surveys";
3319 if self._scopes.is_empty() {
3320 self._scopes.insert(Scope::Readonly.as_ref().to_string());
3321 }
3322
3323 let url = params.parse_with_url(&url);
3324
3325 loop {
3326 let token = match self
3327 .hub
3328 .auth
3329 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
3330 .await
3331 {
3332 Ok(token) => token,
3333 Err(e) => match dlg.token(e) {
3334 Ok(token) => token,
3335 Err(e) => {
3336 dlg.finished(false);
3337 return Err(common::Error::MissingToken(e));
3338 }
3339 },
3340 };
3341 let mut req_result = {
3342 let client = &self.hub.client;
3343 dlg.pre_request();
3344 let mut req_builder = hyper::Request::builder()
3345 .method(hyper::Method::GET)
3346 .uri(url.as_str())
3347 .header(USER_AGENT, self.hub._user_agent.clone());
3348
3349 if let Some(token) = token.as_ref() {
3350 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
3351 }
3352
3353 let request = req_builder
3354 .header(CONTENT_LENGTH, 0_u64)
3355 .body(common::to_body::<String>(None));
3356
3357 client.request(request.unwrap()).await
3358 };
3359
3360 match req_result {
3361 Err(err) => {
3362 if let common::Retry::After(d) = dlg.http_error(&err) {
3363 sleep(d).await;
3364 continue;
3365 }
3366 dlg.finished(false);
3367 return Err(common::Error::HttpError(err));
3368 }
3369 Ok(res) => {
3370 let (mut parts, body) = res.into_parts();
3371 let mut body = common::Body::new(body);
3372 if !parts.status.is_success() {
3373 let bytes = common::to_bytes(body).await.unwrap_or_default();
3374 let error = serde_json::from_str(&common::to_string(&bytes));
3375 let response = common::to_response(parts, bytes.into());
3376
3377 if let common::Retry::After(d) =
3378 dlg.http_failure(&response, error.as_ref().ok())
3379 {
3380 sleep(d).await;
3381 continue;
3382 }
3383
3384 dlg.finished(false);
3385
3386 return Err(match error {
3387 Ok(value) => common::Error::BadRequest(value),
3388 _ => common::Error::Failure(response),
3389 });
3390 }
3391 let response = {
3392 let bytes = common::to_bytes(body).await.unwrap_or_default();
3393 let encoded = common::to_string(&bytes);
3394 match serde_json::from_str(&encoded) {
3395 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
3396 Err(error) => {
3397 dlg.response_json_decode_error(&encoded, &error);
3398 return Err(common::Error::JsonDecodeError(
3399 encoded.to_string(),
3400 error,
3401 ));
3402 }
3403 }
3404 };
3405
3406 dlg.finished(true);
3407 return Ok(response);
3408 }
3409 }
3410 }
3411 }
3412
3413 ///
3414 /// Sets the *token* query property to the given value.
3415 pub fn token(mut self, new_value: &str) -> SurveyListCall<'a, C> {
3416 self._token = Some(new_value.to_string());
3417 self
3418 }
3419 ///
3420 /// Sets the *start index* query property to the given value.
3421 pub fn start_index(mut self, new_value: u32) -> SurveyListCall<'a, C> {
3422 self._start_index = Some(new_value);
3423 self
3424 }
3425 ///
3426 /// Sets the *max results* query property to the given value.
3427 pub fn max_results(mut self, new_value: u32) -> SurveyListCall<'a, C> {
3428 self._max_results = Some(new_value);
3429 self
3430 }
3431 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
3432 /// while executing the actual API request.
3433 ///
3434 /// ````text
3435 /// It should be used to handle progress information, and to implement a certain level of resilience.
3436 /// ````
3437 ///
3438 /// Sets the *delegate* property to the given value.
3439 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> SurveyListCall<'a, C> {
3440 self._delegate = Some(new_value);
3441 self
3442 }
3443
3444 /// Set any additional parameter of the query string used in the request.
3445 /// It should be used to set parameters which are not yet available through their own
3446 /// setters.
3447 ///
3448 /// Please note that this method must not be used to set any of the known parameters
3449 /// which have their own setter method. If done anyway, the request will fail.
3450 ///
3451 /// # Additional Parameters
3452 ///
3453 /// * *alt* (query-string) - Data format for the response.
3454 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
3455 /// * *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.
3456 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
3457 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
3458 /// * *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.
3459 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
3460 pub fn param<T>(mut self, name: T, value: T) -> SurveyListCall<'a, C>
3461 where
3462 T: AsRef<str>,
3463 {
3464 self._additional_params
3465 .insert(name.as_ref().to_string(), value.as_ref().to_string());
3466 self
3467 }
3468
3469 /// Identifies the authorization scope for the method you are building.
3470 ///
3471 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
3472 /// [`Scope::Readonly`].
3473 ///
3474 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
3475 /// tokens for more than one scope.
3476 ///
3477 /// Usually there is more than one suitable scope to authorize an operation, some of which may
3478 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
3479 /// sufficient, a read-write scope will do as well.
3480 pub fn add_scope<St>(mut self, scope: St) -> SurveyListCall<'a, C>
3481 where
3482 St: AsRef<str>,
3483 {
3484 self._scopes.insert(String::from(scope.as_ref()));
3485 self
3486 }
3487 /// Identifies the authorization scope(s) for the method you are building.
3488 ///
3489 /// See [`Self::add_scope()`] for details.
3490 pub fn add_scopes<I, St>(mut self, scopes: I) -> SurveyListCall<'a, C>
3491 where
3492 I: IntoIterator<Item = St>,
3493 St: AsRef<str>,
3494 {
3495 self._scopes
3496 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
3497 self
3498 }
3499
3500 /// Removes all scopes, and no default scope will be used either.
3501 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
3502 /// for details).
3503 pub fn clear_scopes(mut self) -> SurveyListCall<'a, C> {
3504 self._scopes.clear();
3505 self
3506 }
3507}
3508
3509/// Begins running a survey.
3510///
3511/// A builder for the *start* method supported by a *survey* resource.
3512/// It is not used directly, but through a [`SurveyMethods`] instance.
3513///
3514/// # Example
3515///
3516/// Instantiate a resource method builder
3517///
3518/// ```test_harness,no_run
3519/// # extern crate hyper;
3520/// # extern crate hyper_rustls;
3521/// # extern crate google_consumersurveys2 as consumersurveys2;
3522/// use consumersurveys2::api::SurveysStartRequest;
3523/// # async fn dox() {
3524/// # use consumersurveys2::{ConsumerSurveys, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
3525///
3526/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
3527/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
3528/// # .with_native_roots()
3529/// # .unwrap()
3530/// # .https_only()
3531/// # .enable_http2()
3532/// # .build();
3533///
3534/// # let executor = hyper_util::rt::TokioExecutor::new();
3535/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
3536/// # secret,
3537/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
3538/// # yup_oauth2::client::CustomHyperClientBuilder::from(
3539/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
3540/// # ),
3541/// # ).build().await.unwrap();
3542///
3543/// # let client = hyper_util::client::legacy::Client::builder(
3544/// # hyper_util::rt::TokioExecutor::new()
3545/// # )
3546/// # .build(
3547/// # hyper_rustls::HttpsConnectorBuilder::new()
3548/// # .with_native_roots()
3549/// # .unwrap()
3550/// # .https_or_http()
3551/// # .enable_http2()
3552/// # .build()
3553/// # );
3554/// # let mut hub = ConsumerSurveys::new(client, auth);
3555/// // As the method needs a request, you would usually fill it with the desired information
3556/// // into the respective structure. Some of the parts shown here might not be applicable !
3557/// // Values shown here are possibly random and not representative !
3558/// let mut req = SurveysStartRequest::default();
3559///
3560/// // You can configure optional parameters by calling the respective setters at will, and
3561/// // execute the final call using `doit()`.
3562/// // Values shown here are possibly random and not representative !
3563/// let result = hub.surveys().start(req, "resourceId")
3564/// .doit().await;
3565/// # }
3566/// ```
3567pub struct SurveyStartCall<'a, C>
3568where
3569 C: 'a,
3570{
3571 hub: &'a ConsumerSurveys<C>,
3572 _request: SurveysStartRequest,
3573 _resource_id: String,
3574 _delegate: Option<&'a mut dyn common::Delegate>,
3575 _additional_params: HashMap<String, String>,
3576 _scopes: BTreeSet<String>,
3577}
3578
3579impl<'a, C> common::CallBuilder for SurveyStartCall<'a, C> {}
3580
3581impl<'a, C> SurveyStartCall<'a, C>
3582where
3583 C: common::Connector,
3584{
3585 /// Perform the operation you have build so far.
3586 pub async fn doit(mut self) -> common::Result<(common::Response, SurveysStartResponse)> {
3587 use std::borrow::Cow;
3588 use std::io::{Read, Seek};
3589
3590 use common::{url::Params, ToParts};
3591 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
3592
3593 let mut dd = common::DefaultDelegate;
3594 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
3595 dlg.begin(common::MethodInfo {
3596 id: "consumersurveys.surveys.start",
3597 http_method: hyper::Method::POST,
3598 });
3599
3600 for &field in ["alt", "resourceId"].iter() {
3601 if self._additional_params.contains_key(field) {
3602 dlg.finished(false);
3603 return Err(common::Error::FieldClash(field));
3604 }
3605 }
3606
3607 let mut params = Params::with_capacity(4 + self._additional_params.len());
3608 params.push("resourceId", self._resource_id);
3609
3610 params.extend(self._additional_params.iter());
3611
3612 params.push("alt", "json");
3613 let mut url = self.hub._base_url.clone() + "surveys/{resourceId}/start";
3614 if self._scopes.is_empty() {
3615 self._scopes.insert(Scope::Full.as_ref().to_string());
3616 }
3617
3618 #[allow(clippy::single_element_loop)]
3619 for &(find_this, param_name) in [("{resourceId}", "resourceId")].iter() {
3620 url = params.uri_replacement(url, param_name, find_this, false);
3621 }
3622 {
3623 let to_remove = ["resourceId"];
3624 params.remove_params(&to_remove);
3625 }
3626
3627 let url = params.parse_with_url(&url);
3628
3629 let mut json_mime_type = mime::APPLICATION_JSON;
3630 let mut request_value_reader = {
3631 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
3632 common::remove_json_null_values(&mut value);
3633 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
3634 serde_json::to_writer(&mut dst, &value).unwrap();
3635 dst
3636 };
3637 let request_size = request_value_reader
3638 .seek(std::io::SeekFrom::End(0))
3639 .unwrap();
3640 request_value_reader
3641 .seek(std::io::SeekFrom::Start(0))
3642 .unwrap();
3643
3644 loop {
3645 let token = match self
3646 .hub
3647 .auth
3648 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
3649 .await
3650 {
3651 Ok(token) => token,
3652 Err(e) => match dlg.token(e) {
3653 Ok(token) => token,
3654 Err(e) => {
3655 dlg.finished(false);
3656 return Err(common::Error::MissingToken(e));
3657 }
3658 },
3659 };
3660 request_value_reader
3661 .seek(std::io::SeekFrom::Start(0))
3662 .unwrap();
3663 let mut req_result = {
3664 let client = &self.hub.client;
3665 dlg.pre_request();
3666 let mut req_builder = hyper::Request::builder()
3667 .method(hyper::Method::POST)
3668 .uri(url.as_str())
3669 .header(USER_AGENT, self.hub._user_agent.clone());
3670
3671 if let Some(token) = token.as_ref() {
3672 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
3673 }
3674
3675 let request = req_builder
3676 .header(CONTENT_TYPE, json_mime_type.to_string())
3677 .header(CONTENT_LENGTH, request_size as u64)
3678 .body(common::to_body(
3679 request_value_reader.get_ref().clone().into(),
3680 ));
3681
3682 client.request(request.unwrap()).await
3683 };
3684
3685 match req_result {
3686 Err(err) => {
3687 if let common::Retry::After(d) = dlg.http_error(&err) {
3688 sleep(d).await;
3689 continue;
3690 }
3691 dlg.finished(false);
3692 return Err(common::Error::HttpError(err));
3693 }
3694 Ok(res) => {
3695 let (mut parts, body) = res.into_parts();
3696 let mut body = common::Body::new(body);
3697 if !parts.status.is_success() {
3698 let bytes = common::to_bytes(body).await.unwrap_or_default();
3699 let error = serde_json::from_str(&common::to_string(&bytes));
3700 let response = common::to_response(parts, bytes.into());
3701
3702 if let common::Retry::After(d) =
3703 dlg.http_failure(&response, error.as_ref().ok())
3704 {
3705 sleep(d).await;
3706 continue;
3707 }
3708
3709 dlg.finished(false);
3710
3711 return Err(match error {
3712 Ok(value) => common::Error::BadRequest(value),
3713 _ => common::Error::Failure(response),
3714 });
3715 }
3716 let response = {
3717 let bytes = common::to_bytes(body).await.unwrap_or_default();
3718 let encoded = common::to_string(&bytes);
3719 match serde_json::from_str(&encoded) {
3720 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
3721 Err(error) => {
3722 dlg.response_json_decode_error(&encoded, &error);
3723 return Err(common::Error::JsonDecodeError(
3724 encoded.to_string(),
3725 error,
3726 ));
3727 }
3728 }
3729 };
3730
3731 dlg.finished(true);
3732 return Ok(response);
3733 }
3734 }
3735 }
3736 }
3737
3738 ///
3739 /// Sets the *request* property to the given value.
3740 ///
3741 /// Even though the property as already been set when instantiating this call,
3742 /// we provide this method for API completeness.
3743 pub fn request(mut self, new_value: SurveysStartRequest) -> SurveyStartCall<'a, C> {
3744 self._request = new_value;
3745 self
3746 }
3747 ///
3748 /// Sets the *resource id* path property to the given value.
3749 ///
3750 /// Even though the property as already been set when instantiating this call,
3751 /// we provide this method for API completeness.
3752 pub fn resource_id(mut self, new_value: &str) -> SurveyStartCall<'a, C> {
3753 self._resource_id = new_value.to_string();
3754 self
3755 }
3756 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
3757 /// while executing the actual API request.
3758 ///
3759 /// ````text
3760 /// It should be used to handle progress information, and to implement a certain level of resilience.
3761 /// ````
3762 ///
3763 /// Sets the *delegate* property to the given value.
3764 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> SurveyStartCall<'a, C> {
3765 self._delegate = Some(new_value);
3766 self
3767 }
3768
3769 /// Set any additional parameter of the query string used in the request.
3770 /// It should be used to set parameters which are not yet available through their own
3771 /// setters.
3772 ///
3773 /// Please note that this method must not be used to set any of the known parameters
3774 /// which have their own setter method. If done anyway, the request will fail.
3775 ///
3776 /// # Additional Parameters
3777 ///
3778 /// * *alt* (query-string) - Data format for the response.
3779 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
3780 /// * *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.
3781 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
3782 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
3783 /// * *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.
3784 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
3785 pub fn param<T>(mut self, name: T, value: T) -> SurveyStartCall<'a, C>
3786 where
3787 T: AsRef<str>,
3788 {
3789 self._additional_params
3790 .insert(name.as_ref().to_string(), value.as_ref().to_string());
3791 self
3792 }
3793
3794 /// Identifies the authorization scope for the method you are building.
3795 ///
3796 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
3797 /// [`Scope::Full`].
3798 ///
3799 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
3800 /// tokens for more than one scope.
3801 ///
3802 /// Usually there is more than one suitable scope to authorize an operation, some of which may
3803 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
3804 /// sufficient, a read-write scope will do as well.
3805 pub fn add_scope<St>(mut self, scope: St) -> SurveyStartCall<'a, C>
3806 where
3807 St: AsRef<str>,
3808 {
3809 self._scopes.insert(String::from(scope.as_ref()));
3810 self
3811 }
3812 /// Identifies the authorization scope(s) for the method you are building.
3813 ///
3814 /// See [`Self::add_scope()`] for details.
3815 pub fn add_scopes<I, St>(mut self, scopes: I) -> SurveyStartCall<'a, C>
3816 where
3817 I: IntoIterator<Item = St>,
3818 St: AsRef<str>,
3819 {
3820 self._scopes
3821 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
3822 self
3823 }
3824
3825 /// Removes all scopes, and no default scope will be used either.
3826 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
3827 /// for details).
3828 pub fn clear_scopes(mut self) -> SurveyStartCall<'a, C> {
3829 self._scopes.clear();
3830 self
3831 }
3832}
3833
3834/// Stops a running survey.
3835///
3836/// A builder for the *stop* method supported by a *survey* resource.
3837/// It is not used directly, but through a [`SurveyMethods`] instance.
3838///
3839/// # Example
3840///
3841/// Instantiate a resource method builder
3842///
3843/// ```test_harness,no_run
3844/// # extern crate hyper;
3845/// # extern crate hyper_rustls;
3846/// # extern crate google_consumersurveys2 as consumersurveys2;
3847/// # async fn dox() {
3848/// # use consumersurveys2::{ConsumerSurveys, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
3849///
3850/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
3851/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
3852/// # .with_native_roots()
3853/// # .unwrap()
3854/// # .https_only()
3855/// # .enable_http2()
3856/// # .build();
3857///
3858/// # let executor = hyper_util::rt::TokioExecutor::new();
3859/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
3860/// # secret,
3861/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
3862/// # yup_oauth2::client::CustomHyperClientBuilder::from(
3863/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
3864/// # ),
3865/// # ).build().await.unwrap();
3866///
3867/// # let client = hyper_util::client::legacy::Client::builder(
3868/// # hyper_util::rt::TokioExecutor::new()
3869/// # )
3870/// # .build(
3871/// # hyper_rustls::HttpsConnectorBuilder::new()
3872/// # .with_native_roots()
3873/// # .unwrap()
3874/// # .https_or_http()
3875/// # .enable_http2()
3876/// # .build()
3877/// # );
3878/// # let mut hub = ConsumerSurveys::new(client, auth);
3879/// // You can configure optional parameters by calling the respective setters at will, and
3880/// // execute the final call using `doit()`.
3881/// // Values shown here are possibly random and not representative !
3882/// let result = hub.surveys().stop("resourceId")
3883/// .doit().await;
3884/// # }
3885/// ```
3886pub struct SurveyStopCall<'a, C>
3887where
3888 C: 'a,
3889{
3890 hub: &'a ConsumerSurveys<C>,
3891 _resource_id: String,
3892 _delegate: Option<&'a mut dyn common::Delegate>,
3893 _additional_params: HashMap<String, String>,
3894 _scopes: BTreeSet<String>,
3895}
3896
3897impl<'a, C> common::CallBuilder for SurveyStopCall<'a, C> {}
3898
3899impl<'a, C> SurveyStopCall<'a, C>
3900where
3901 C: common::Connector,
3902{
3903 /// Perform the operation you have build so far.
3904 pub async fn doit(mut self) -> common::Result<(common::Response, SurveysStopResponse)> {
3905 use std::borrow::Cow;
3906 use std::io::{Read, Seek};
3907
3908 use common::{url::Params, ToParts};
3909 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
3910
3911 let mut dd = common::DefaultDelegate;
3912 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
3913 dlg.begin(common::MethodInfo {
3914 id: "consumersurveys.surveys.stop",
3915 http_method: hyper::Method::POST,
3916 });
3917
3918 for &field in ["alt", "resourceId"].iter() {
3919 if self._additional_params.contains_key(field) {
3920 dlg.finished(false);
3921 return Err(common::Error::FieldClash(field));
3922 }
3923 }
3924
3925 let mut params = Params::with_capacity(3 + self._additional_params.len());
3926 params.push("resourceId", self._resource_id);
3927
3928 params.extend(self._additional_params.iter());
3929
3930 params.push("alt", "json");
3931 let mut url = self.hub._base_url.clone() + "surveys/{resourceId}/stop";
3932 if self._scopes.is_empty() {
3933 self._scopes.insert(Scope::Full.as_ref().to_string());
3934 }
3935
3936 #[allow(clippy::single_element_loop)]
3937 for &(find_this, param_name) in [("{resourceId}", "resourceId")].iter() {
3938 url = params.uri_replacement(url, param_name, find_this, false);
3939 }
3940 {
3941 let to_remove = ["resourceId"];
3942 params.remove_params(&to_remove);
3943 }
3944
3945 let url = params.parse_with_url(&url);
3946
3947 loop {
3948 let token = match self
3949 .hub
3950 .auth
3951 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
3952 .await
3953 {
3954 Ok(token) => token,
3955 Err(e) => match dlg.token(e) {
3956 Ok(token) => token,
3957 Err(e) => {
3958 dlg.finished(false);
3959 return Err(common::Error::MissingToken(e));
3960 }
3961 },
3962 };
3963 let mut req_result = {
3964 let client = &self.hub.client;
3965 dlg.pre_request();
3966 let mut req_builder = hyper::Request::builder()
3967 .method(hyper::Method::POST)
3968 .uri(url.as_str())
3969 .header(USER_AGENT, self.hub._user_agent.clone());
3970
3971 if let Some(token) = token.as_ref() {
3972 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
3973 }
3974
3975 let request = req_builder
3976 .header(CONTENT_LENGTH, 0_u64)
3977 .body(common::to_body::<String>(None));
3978
3979 client.request(request.unwrap()).await
3980 };
3981
3982 match req_result {
3983 Err(err) => {
3984 if let common::Retry::After(d) = dlg.http_error(&err) {
3985 sleep(d).await;
3986 continue;
3987 }
3988 dlg.finished(false);
3989 return Err(common::Error::HttpError(err));
3990 }
3991 Ok(res) => {
3992 let (mut parts, body) = res.into_parts();
3993 let mut body = common::Body::new(body);
3994 if !parts.status.is_success() {
3995 let bytes = common::to_bytes(body).await.unwrap_or_default();
3996 let error = serde_json::from_str(&common::to_string(&bytes));
3997 let response = common::to_response(parts, bytes.into());
3998
3999 if let common::Retry::After(d) =
4000 dlg.http_failure(&response, error.as_ref().ok())
4001 {
4002 sleep(d).await;
4003 continue;
4004 }
4005
4006 dlg.finished(false);
4007
4008 return Err(match error {
4009 Ok(value) => common::Error::BadRequest(value),
4010 _ => common::Error::Failure(response),
4011 });
4012 }
4013 let response = {
4014 let bytes = common::to_bytes(body).await.unwrap_or_default();
4015 let encoded = common::to_string(&bytes);
4016 match serde_json::from_str(&encoded) {
4017 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
4018 Err(error) => {
4019 dlg.response_json_decode_error(&encoded, &error);
4020 return Err(common::Error::JsonDecodeError(
4021 encoded.to_string(),
4022 error,
4023 ));
4024 }
4025 }
4026 };
4027
4028 dlg.finished(true);
4029 return Ok(response);
4030 }
4031 }
4032 }
4033 }
4034
4035 ///
4036 /// Sets the *resource id* path property to the given value.
4037 ///
4038 /// Even though the property as already been set when instantiating this call,
4039 /// we provide this method for API completeness.
4040 pub fn resource_id(mut self, new_value: &str) -> SurveyStopCall<'a, C> {
4041 self._resource_id = new_value.to_string();
4042 self
4043 }
4044 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
4045 /// while executing the actual API request.
4046 ///
4047 /// ````text
4048 /// It should be used to handle progress information, and to implement a certain level of resilience.
4049 /// ````
4050 ///
4051 /// Sets the *delegate* property to the given value.
4052 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> SurveyStopCall<'a, C> {
4053 self._delegate = Some(new_value);
4054 self
4055 }
4056
4057 /// Set any additional parameter of the query string used in the request.
4058 /// It should be used to set parameters which are not yet available through their own
4059 /// setters.
4060 ///
4061 /// Please note that this method must not be used to set any of the known parameters
4062 /// which have their own setter method. If done anyway, the request will fail.
4063 ///
4064 /// # Additional Parameters
4065 ///
4066 /// * *alt* (query-string) - Data format for the response.
4067 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
4068 /// * *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.
4069 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
4070 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
4071 /// * *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.
4072 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
4073 pub fn param<T>(mut self, name: T, value: T) -> SurveyStopCall<'a, C>
4074 where
4075 T: AsRef<str>,
4076 {
4077 self._additional_params
4078 .insert(name.as_ref().to_string(), value.as_ref().to_string());
4079 self
4080 }
4081
4082 /// Identifies the authorization scope for the method you are building.
4083 ///
4084 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
4085 /// [`Scope::Full`].
4086 ///
4087 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
4088 /// tokens for more than one scope.
4089 ///
4090 /// Usually there is more than one suitable scope to authorize an operation, some of which may
4091 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
4092 /// sufficient, a read-write scope will do as well.
4093 pub fn add_scope<St>(mut self, scope: St) -> SurveyStopCall<'a, C>
4094 where
4095 St: AsRef<str>,
4096 {
4097 self._scopes.insert(String::from(scope.as_ref()));
4098 self
4099 }
4100 /// Identifies the authorization scope(s) for the method you are building.
4101 ///
4102 /// See [`Self::add_scope()`] for details.
4103 pub fn add_scopes<I, St>(mut self, scopes: I) -> SurveyStopCall<'a, C>
4104 where
4105 I: IntoIterator<Item = St>,
4106 St: AsRef<str>,
4107 {
4108 self._scopes
4109 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
4110 self
4111 }
4112
4113 /// Removes all scopes, and no default scope will be used either.
4114 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
4115 /// for details).
4116 pub fn clear_scopes(mut self) -> SurveyStopCall<'a, C> {
4117 self._scopes.clear();
4118 self
4119 }
4120}
4121
4122/// Updates a survey. Currently the only property that can be updated is the owners property.
4123///
4124/// A builder for the *update* method supported by a *survey* resource.
4125/// It is not used directly, but through a [`SurveyMethods`] instance.
4126///
4127/// # Example
4128///
4129/// Instantiate a resource method builder
4130///
4131/// ```test_harness,no_run
4132/// # extern crate hyper;
4133/// # extern crate hyper_rustls;
4134/// # extern crate google_consumersurveys2 as consumersurveys2;
4135/// use consumersurveys2::api::Survey;
4136/// # async fn dox() {
4137/// # use consumersurveys2::{ConsumerSurveys, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
4138///
4139/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
4140/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
4141/// # .with_native_roots()
4142/// # .unwrap()
4143/// # .https_only()
4144/// # .enable_http2()
4145/// # .build();
4146///
4147/// # let executor = hyper_util::rt::TokioExecutor::new();
4148/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
4149/// # secret,
4150/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
4151/// # yup_oauth2::client::CustomHyperClientBuilder::from(
4152/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
4153/// # ),
4154/// # ).build().await.unwrap();
4155///
4156/// # let client = hyper_util::client::legacy::Client::builder(
4157/// # hyper_util::rt::TokioExecutor::new()
4158/// # )
4159/// # .build(
4160/// # hyper_rustls::HttpsConnectorBuilder::new()
4161/// # .with_native_roots()
4162/// # .unwrap()
4163/// # .https_or_http()
4164/// # .enable_http2()
4165/// # .build()
4166/// # );
4167/// # let mut hub = ConsumerSurveys::new(client, auth);
4168/// // As the method needs a request, you would usually fill it with the desired information
4169/// // into the respective structure. Some of the parts shown here might not be applicable !
4170/// // Values shown here are possibly random and not representative !
4171/// let mut req = Survey::default();
4172///
4173/// // You can configure optional parameters by calling the respective setters at will, and
4174/// // execute the final call using `doit()`.
4175/// // Values shown here are possibly random and not representative !
4176/// let result = hub.surveys().update(req, "surveyUrlId")
4177/// .doit().await;
4178/// # }
4179/// ```
4180pub struct SurveyUpdateCall<'a, C>
4181where
4182 C: 'a,
4183{
4184 hub: &'a ConsumerSurveys<C>,
4185 _request: Survey,
4186 _survey_url_id: String,
4187 _delegate: Option<&'a mut dyn common::Delegate>,
4188 _additional_params: HashMap<String, String>,
4189 _scopes: BTreeSet<String>,
4190}
4191
4192impl<'a, C> common::CallBuilder for SurveyUpdateCall<'a, C> {}
4193
4194impl<'a, C> SurveyUpdateCall<'a, C>
4195where
4196 C: common::Connector,
4197{
4198 /// Perform the operation you have build so far.
4199 pub async fn doit(mut self) -> common::Result<(common::Response, Survey)> {
4200 use std::borrow::Cow;
4201 use std::io::{Read, Seek};
4202
4203 use common::{url::Params, ToParts};
4204 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
4205
4206 let mut dd = common::DefaultDelegate;
4207 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
4208 dlg.begin(common::MethodInfo {
4209 id: "consumersurveys.surveys.update",
4210 http_method: hyper::Method::PUT,
4211 });
4212
4213 for &field in ["alt", "surveyUrlId"].iter() {
4214 if self._additional_params.contains_key(field) {
4215 dlg.finished(false);
4216 return Err(common::Error::FieldClash(field));
4217 }
4218 }
4219
4220 let mut params = Params::with_capacity(4 + self._additional_params.len());
4221 params.push("surveyUrlId", self._survey_url_id);
4222
4223 params.extend(self._additional_params.iter());
4224
4225 params.push("alt", "json");
4226 let mut url = self.hub._base_url.clone() + "surveys/{surveyUrlId}";
4227 if self._scopes.is_empty() {
4228 self._scopes.insert(Scope::Full.as_ref().to_string());
4229 }
4230
4231 #[allow(clippy::single_element_loop)]
4232 for &(find_this, param_name) in [("{surveyUrlId}", "surveyUrlId")].iter() {
4233 url = params.uri_replacement(url, param_name, find_this, false);
4234 }
4235 {
4236 let to_remove = ["surveyUrlId"];
4237 params.remove_params(&to_remove);
4238 }
4239
4240 let url = params.parse_with_url(&url);
4241
4242 let mut json_mime_type = mime::APPLICATION_JSON;
4243 let mut request_value_reader = {
4244 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
4245 common::remove_json_null_values(&mut value);
4246 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
4247 serde_json::to_writer(&mut dst, &value).unwrap();
4248 dst
4249 };
4250 let request_size = request_value_reader
4251 .seek(std::io::SeekFrom::End(0))
4252 .unwrap();
4253 request_value_reader
4254 .seek(std::io::SeekFrom::Start(0))
4255 .unwrap();
4256
4257 loop {
4258 let token = match self
4259 .hub
4260 .auth
4261 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
4262 .await
4263 {
4264 Ok(token) => token,
4265 Err(e) => match dlg.token(e) {
4266 Ok(token) => token,
4267 Err(e) => {
4268 dlg.finished(false);
4269 return Err(common::Error::MissingToken(e));
4270 }
4271 },
4272 };
4273 request_value_reader
4274 .seek(std::io::SeekFrom::Start(0))
4275 .unwrap();
4276 let mut req_result = {
4277 let client = &self.hub.client;
4278 dlg.pre_request();
4279 let mut req_builder = hyper::Request::builder()
4280 .method(hyper::Method::PUT)
4281 .uri(url.as_str())
4282 .header(USER_AGENT, self.hub._user_agent.clone());
4283
4284 if let Some(token) = token.as_ref() {
4285 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
4286 }
4287
4288 let request = req_builder
4289 .header(CONTENT_TYPE, json_mime_type.to_string())
4290 .header(CONTENT_LENGTH, request_size as u64)
4291 .body(common::to_body(
4292 request_value_reader.get_ref().clone().into(),
4293 ));
4294
4295 client.request(request.unwrap()).await
4296 };
4297
4298 match req_result {
4299 Err(err) => {
4300 if let common::Retry::After(d) = dlg.http_error(&err) {
4301 sleep(d).await;
4302 continue;
4303 }
4304 dlg.finished(false);
4305 return Err(common::Error::HttpError(err));
4306 }
4307 Ok(res) => {
4308 let (mut parts, body) = res.into_parts();
4309 let mut body = common::Body::new(body);
4310 if !parts.status.is_success() {
4311 let bytes = common::to_bytes(body).await.unwrap_or_default();
4312 let error = serde_json::from_str(&common::to_string(&bytes));
4313 let response = common::to_response(parts, bytes.into());
4314
4315 if let common::Retry::After(d) =
4316 dlg.http_failure(&response, error.as_ref().ok())
4317 {
4318 sleep(d).await;
4319 continue;
4320 }
4321
4322 dlg.finished(false);
4323
4324 return Err(match error {
4325 Ok(value) => common::Error::BadRequest(value),
4326 _ => common::Error::Failure(response),
4327 });
4328 }
4329 let response = {
4330 let bytes = common::to_bytes(body).await.unwrap_or_default();
4331 let encoded = common::to_string(&bytes);
4332 match serde_json::from_str(&encoded) {
4333 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
4334 Err(error) => {
4335 dlg.response_json_decode_error(&encoded, &error);
4336 return Err(common::Error::JsonDecodeError(
4337 encoded.to_string(),
4338 error,
4339 ));
4340 }
4341 }
4342 };
4343
4344 dlg.finished(true);
4345 return Ok(response);
4346 }
4347 }
4348 }
4349 }
4350
4351 ///
4352 /// Sets the *request* property to the given value.
4353 ///
4354 /// Even though the property as already been set when instantiating this call,
4355 /// we provide this method for API completeness.
4356 pub fn request(mut self, new_value: Survey) -> SurveyUpdateCall<'a, C> {
4357 self._request = new_value;
4358 self
4359 }
4360 /// External URL ID for the survey.
4361 ///
4362 /// Sets the *survey url id* path property to the given value.
4363 ///
4364 /// Even though the property as already been set when instantiating this call,
4365 /// we provide this method for API completeness.
4366 pub fn survey_url_id(mut self, new_value: &str) -> SurveyUpdateCall<'a, C> {
4367 self._survey_url_id = new_value.to_string();
4368 self
4369 }
4370 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
4371 /// while executing the actual API request.
4372 ///
4373 /// ````text
4374 /// It should be used to handle progress information, and to implement a certain level of resilience.
4375 /// ````
4376 ///
4377 /// Sets the *delegate* property to the given value.
4378 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> SurveyUpdateCall<'a, C> {
4379 self._delegate = Some(new_value);
4380 self
4381 }
4382
4383 /// Set any additional parameter of the query string used in the request.
4384 /// It should be used to set parameters which are not yet available through their own
4385 /// setters.
4386 ///
4387 /// Please note that this method must not be used to set any of the known parameters
4388 /// which have their own setter method. If done anyway, the request will fail.
4389 ///
4390 /// # Additional Parameters
4391 ///
4392 /// * *alt* (query-string) - Data format for the response.
4393 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
4394 /// * *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.
4395 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
4396 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
4397 /// * *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.
4398 /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
4399 pub fn param<T>(mut self, name: T, value: T) -> SurveyUpdateCall<'a, C>
4400 where
4401 T: AsRef<str>,
4402 {
4403 self._additional_params
4404 .insert(name.as_ref().to_string(), value.as_ref().to_string());
4405 self
4406 }
4407
4408 /// Identifies the authorization scope for the method you are building.
4409 ///
4410 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
4411 /// [`Scope::Full`].
4412 ///
4413 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
4414 /// tokens for more than one scope.
4415 ///
4416 /// Usually there is more than one suitable scope to authorize an operation, some of which may
4417 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
4418 /// sufficient, a read-write scope will do as well.
4419 pub fn add_scope<St>(mut self, scope: St) -> SurveyUpdateCall<'a, C>
4420 where
4421 St: AsRef<str>,
4422 {
4423 self._scopes.insert(String::from(scope.as_ref()));
4424 self
4425 }
4426 /// Identifies the authorization scope(s) for the method you are building.
4427 ///
4428 /// See [`Self::add_scope()`] for details.
4429 pub fn add_scopes<I, St>(mut self, scopes: I) -> SurveyUpdateCall<'a, C>
4430 where
4431 I: IntoIterator<Item = St>,
4432 St: AsRef<str>,
4433 {
4434 self._scopes
4435 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
4436 self
4437 }
4438
4439 /// Removes all scopes, and no default scope will be used either.
4440 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
4441 /// for details).
4442 pub fn clear_scopes(mut self) -> SurveyUpdateCall<'a, C> {
4443 self._scopes.clear();
4444 self
4445 }
4446}