google_language1_beta1/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 /// Apply machine learning models to reveal the structure and meaning of text
17 CloudLanguage,
18
19 /// See, edit, configure, and delete your Google Cloud data and see the email address for your Google Account.
20 CloudPlatform,
21}
22
23impl AsRef<str> for Scope {
24 fn as_ref(&self) -> &str {
25 match *self {
26 Scope::CloudLanguage => "https://www.googleapis.com/auth/cloud-language",
27 Scope::CloudPlatform => "https://www.googleapis.com/auth/cloud-platform",
28 }
29 }
30}
31
32#[allow(clippy::derivable_impls)]
33impl Default for Scope {
34 fn default() -> Scope {
35 Scope::CloudLanguage
36 }
37}
38
39// ########
40// HUB ###
41// ######
42
43/// Central instance to access all CloudNaturalLanguage related resource activities
44///
45/// # Examples
46///
47/// Instantiate a new hub
48///
49/// ```test_harness,no_run
50/// extern crate hyper;
51/// extern crate hyper_rustls;
52/// extern crate google_language1_beta1 as language1_beta1;
53/// use language1_beta1::api::AnalyzeEntitiesRequest;
54/// use language1_beta1::{Result, Error};
55/// # async fn dox() {
56/// use language1_beta1::{CloudNaturalLanguage, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
57///
58/// // Get an ApplicationSecret instance by some means. It contains the `client_id` and
59/// // `client_secret`, among other things.
60/// let secret: yup_oauth2::ApplicationSecret = Default::default();
61/// // Instantiate the authenticator. It will choose a suitable authentication flow for you,
62/// // unless you replace `None` with the desired Flow.
63/// // Provide your own `AuthenticatorDelegate` to adjust the way it operates and get feedback about
64/// // what's going on. You probably want to bring in your own `TokenStorage` to persist tokens and
65/// // retrieve them from storage.
66/// let connector = hyper_rustls::HttpsConnectorBuilder::new()
67/// .with_native_roots()
68/// .unwrap()
69/// .https_only()
70/// .enable_http2()
71/// .build();
72///
73/// let executor = hyper_util::rt::TokioExecutor::new();
74/// let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
75/// secret,
76/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
77/// yup_oauth2::client::CustomHyperClientBuilder::from(
78/// hyper_util::client::legacy::Client::builder(executor).build(connector),
79/// ),
80/// ).build().await.unwrap();
81///
82/// let client = hyper_util::client::legacy::Client::builder(
83/// hyper_util::rt::TokioExecutor::new()
84/// )
85/// .build(
86/// hyper_rustls::HttpsConnectorBuilder::new()
87/// .with_native_roots()
88/// .unwrap()
89/// .https_or_http()
90/// .enable_http2()
91/// .build()
92/// );
93/// let mut hub = CloudNaturalLanguage::new(client, auth);
94/// // As the method needs a request, you would usually fill it with the desired information
95/// // into the respective structure. Some of the parts shown here might not be applicable !
96/// // Values shown here are possibly random and not representative !
97/// let mut req = AnalyzeEntitiesRequest::default();
98///
99/// // You can configure optional parameters by calling the respective setters at will, and
100/// // execute the final call using `doit()`.
101/// // Values shown here are possibly random and not representative !
102/// let result = hub.documents().analyze_entities(req)
103/// .doit().await;
104///
105/// match result {
106/// Err(e) => match e {
107/// // The Error enum provides details about what exactly happened.
108/// // You can also just use its `Debug`, `Display` or `Error` traits
109/// Error::HttpError(_)
110/// |Error::Io(_)
111/// |Error::MissingAPIKey
112/// |Error::MissingToken(_)
113/// |Error::Cancelled
114/// |Error::UploadSizeLimitExceeded(_, _)
115/// |Error::Failure(_)
116/// |Error::BadRequest(_)
117/// |Error::FieldClash(_)
118/// |Error::JsonDecodeError(_, _) => println!("{}", e),
119/// },
120/// Ok(res) => println!("Success: {:?}", res),
121/// }
122/// # }
123/// ```
124#[derive(Clone)]
125pub struct CloudNaturalLanguage<C> {
126 pub client: common::Client<C>,
127 pub auth: Box<dyn common::GetToken>,
128 _user_agent: String,
129 _base_url: String,
130 _root_url: String,
131}
132
133impl<C> common::Hub for CloudNaturalLanguage<C> {}
134
135impl<'a, C> CloudNaturalLanguage<C> {
136 pub fn new<A: 'static + common::GetToken>(
137 client: common::Client<C>,
138 auth: A,
139 ) -> CloudNaturalLanguage<C> {
140 CloudNaturalLanguage {
141 client,
142 auth: Box::new(auth),
143 _user_agent: "google-api-rust-client/7.0.0".to_string(),
144 _base_url: "https://language.googleapis.com/".to_string(),
145 _root_url: "https://language.googleapis.com/".to_string(),
146 }
147 }
148
149 pub fn documents(&'a self) -> DocumentMethods<'a, C> {
150 DocumentMethods { hub: self }
151 }
152
153 /// Set the user-agent header field to use in all requests to the server.
154 /// It defaults to `google-api-rust-client/7.0.0`.
155 ///
156 /// Returns the previously set user-agent.
157 pub fn user_agent(&mut self, agent_name: String) -> String {
158 std::mem::replace(&mut self._user_agent, agent_name)
159 }
160
161 /// Set the base url to use in all requests to the server.
162 /// It defaults to `https://language.googleapis.com/`.
163 ///
164 /// Returns the previously set base url.
165 pub fn base_url(&mut self, new_base_url: String) -> String {
166 std::mem::replace(&mut self._base_url, new_base_url)
167 }
168
169 /// Set the root url to use in all requests to the server.
170 /// It defaults to `https://language.googleapis.com/`.
171 ///
172 /// Returns the previously set root url.
173 pub fn root_url(&mut self, new_root_url: String) -> String {
174 std::mem::replace(&mut self._root_url, new_root_url)
175 }
176}
177
178// ############
179// SCHEMAS ###
180// ##########
181/// The entity analysis request message.
182///
183/// # Activities
184///
185/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
186/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
187///
188/// * [analyze entities documents](DocumentAnalyzeEntityCall) (request)
189#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
190#[serde_with::serde_as]
191#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
192pub struct AnalyzeEntitiesRequest {
193 /// Input document.
194 pub document: Option<Document>,
195 /// The encoding type used by the API to calculate offsets.
196 #[serde(rename = "encodingType")]
197 pub encoding_type: Option<String>,
198}
199
200impl common::RequestValue for AnalyzeEntitiesRequest {}
201
202/// The entity analysis response message.
203///
204/// # Activities
205///
206/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
207/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
208///
209/// * [analyze entities documents](DocumentAnalyzeEntityCall) (response)
210#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
211#[serde_with::serde_as]
212#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
213pub struct AnalyzeEntitiesResponse {
214 /// The recognized entities in the input document.
215 pub entities: Option<Vec<Entity>>,
216 /// The language of the text, which will be the same as the language specified in the request or, if not specified, the automatically-detected language. See Document.language field for more details.
217 pub language: Option<String>,
218}
219
220impl common::ResponseResult for AnalyzeEntitiesResponse {}
221
222/// The sentiment analysis request message.
223///
224/// # Activities
225///
226/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
227/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
228///
229/// * [analyze sentiment documents](DocumentAnalyzeSentimentCall) (request)
230#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
231#[serde_with::serde_as]
232#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
233pub struct AnalyzeSentimentRequest {
234 /// Input document.
235 pub document: Option<Document>,
236 /// The encoding type used by the API to calculate sentence offsets for the sentence sentiment.
237 #[serde(rename = "encodingType")]
238 pub encoding_type: Option<String>,
239}
240
241impl common::RequestValue for AnalyzeSentimentRequest {}
242
243/// The sentiment analysis response message.
244///
245/// # Activities
246///
247/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
248/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
249///
250/// * [analyze sentiment documents](DocumentAnalyzeSentimentCall) (response)
251#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
252#[serde_with::serde_as]
253#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
254pub struct AnalyzeSentimentResponse {
255 /// The overall sentiment of the input document.
256 #[serde(rename = "documentSentiment")]
257 pub document_sentiment: Option<Sentiment>,
258 /// The language of the text, which will be the same as the language specified in the request or, if not specified, the automatically-detected language. See Document.language field for more details.
259 pub language: Option<String>,
260 /// The sentiment for all the sentences in the document.
261 pub sentences: Option<Vec<Sentence>>,
262}
263
264impl common::ResponseResult for AnalyzeSentimentResponse {}
265
266/// The syntax analysis request message.
267///
268/// # Activities
269///
270/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
271/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
272///
273/// * [analyze syntax documents](DocumentAnalyzeSyntaxCall) (request)
274#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
275#[serde_with::serde_as]
276#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
277pub struct AnalyzeSyntaxRequest {
278 /// Input document.
279 pub document: Option<Document>,
280 /// The encoding type used by the API to calculate offsets.
281 #[serde(rename = "encodingType")]
282 pub encoding_type: Option<String>,
283}
284
285impl common::RequestValue for AnalyzeSyntaxRequest {}
286
287/// The syntax analysis response message.
288///
289/// # Activities
290///
291/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
292/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
293///
294/// * [analyze syntax documents](DocumentAnalyzeSyntaxCall) (response)
295#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
296#[serde_with::serde_as]
297#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
298pub struct AnalyzeSyntaxResponse {
299 /// The language of the text, which will be the same as the language specified in the request or, if not specified, the automatically-detected language. See Document.language field for more details.
300 pub language: Option<String>,
301 /// Sentences in the input document.
302 pub sentences: Option<Vec<Sentence>>,
303 /// Tokens, along with their syntactic information, in the input document.
304 pub tokens: Option<Vec<Token>>,
305}
306
307impl common::ResponseResult for AnalyzeSyntaxResponse {}
308
309/// The request message for the text annotation API, which can perform multiple analysis types (sentiment, entities, and syntax) in one call.
310///
311/// # Activities
312///
313/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
314/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
315///
316/// * [annotate text documents](DocumentAnnotateTextCall) (request)
317#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
318#[serde_with::serde_as]
319#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
320pub struct AnnotateTextRequest {
321 /// Input document.
322 pub document: Option<Document>,
323 /// The encoding type used by the API to calculate offsets.
324 #[serde(rename = "encodingType")]
325 pub encoding_type: Option<String>,
326 /// The enabled features.
327 pub features: Option<Features>,
328}
329
330impl common::RequestValue for AnnotateTextRequest {}
331
332/// The text annotations response message.
333///
334/// # Activities
335///
336/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
337/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
338///
339/// * [annotate text documents](DocumentAnnotateTextCall) (response)
340#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
341#[serde_with::serde_as]
342#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
343pub struct AnnotateTextResponse {
344 /// The overall sentiment for the document. Populated if the user enables AnnotateTextRequest.Features.extract_document_sentiment.
345 #[serde(rename = "documentSentiment")]
346 pub document_sentiment: Option<Sentiment>,
347 /// Entities, along with their semantic information, in the input document. Populated if the user enables AnnotateTextRequest.Features.extract_entities.
348 pub entities: Option<Vec<Entity>>,
349 /// The language of the text, which will be the same as the language specified in the request or, if not specified, the automatically-detected language. See Document.language field for more details.
350 pub language: Option<String>,
351 /// Sentences in the input document. Populated if the user enables AnnotateTextRequest.Features.extract_syntax.
352 pub sentences: Option<Vec<Sentence>>,
353 /// Tokens, along with their syntactic information, in the input document. Populated if the user enables AnnotateTextRequest.Features.extract_syntax.
354 pub tokens: Option<Vec<Token>>,
355}
356
357impl common::ResponseResult for AnnotateTextResponse {}
358
359/// Represents dependency parse tree information for a token.
360///
361/// This type is not used in any activity, and only used as *part* of another schema.
362///
363#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
364#[serde_with::serde_as]
365#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
366pub struct DependencyEdge {
367 /// Represents the head of this token in the dependency tree. This is the index of the token which has an arc going to this token. The index is the position of the token in the array of tokens returned by the API method. If this token is a root token, then the `head_token_index` is its own index.
368 #[serde(rename = "headTokenIndex")]
369 pub head_token_index: Option<i32>,
370 /// The parse label for the token.
371 pub label: Option<String>,
372}
373
374impl common::Part for DependencyEdge {}
375
376/// \################################################################ # Represents the input to API methods.
377///
378/// # Activities
379///
380/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
381/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
382///
383/// * [analyze entities documents](DocumentAnalyzeEntityCall) (none)
384/// * [analyze sentiment documents](DocumentAnalyzeSentimentCall) (none)
385/// * [analyze syntax documents](DocumentAnalyzeSyntaxCall) (none)
386/// * [annotate text documents](DocumentAnnotateTextCall) (none)
387#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
388#[serde_with::serde_as]
389#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
390pub struct Document {
391 /// The content of the input in string format. Cloud audit logging exempt since it is based on user data.
392 pub content: Option<String>,
393 /// The Google Cloud Storage URI where the file content is located. This URI must be of the form: gs://bucket_name/object_name. For more details, see https://cloud.google.com/storage/docs/reference-uris. NOTE: Cloud Storage object versioning is not supported.
394 #[serde(rename = "gcsContentUri")]
395 pub gcs_content_uri: Option<String>,
396 /// The language of the document (if not specified, the language is automatically detected). Both ISO and BCP-47 language codes are accepted. [Language Support](https://cloud.google.com/natural-language/docs/languages) lists currently supported languages for each API method. If the language (either specified by the caller or automatically detected) is not supported by the called API method, an `INVALID_ARGUMENT` error is returned.
397 pub language: Option<String>,
398 /// Required. If the type is not set or is `TYPE_UNSPECIFIED`, returns an `INVALID_ARGUMENT` error.
399 #[serde(rename = "type")]
400 pub type_: Option<String>,
401}
402
403impl common::Resource for Document {}
404
405/// Represents a phrase in the text that is a known entity, such as a person, an organization, or location. The API associates information, such as salience and mentions, with entities.
406///
407/// This type is not used in any activity, and only used as *part* of another schema.
408///
409#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
410#[serde_with::serde_as]
411#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
412pub struct Entity {
413 /// The mentions of this entity in the input document. The API currently supports proper noun mentions.
414 pub mentions: Option<Vec<EntityMention>>,
415 /// Metadata associated with the entity. Currently, Wikipedia URLs and Knowledge Graph MIDs are provided, if available. The associated keys are "wikipedia_url" and "mid", respectively.
416 pub metadata: Option<HashMap<String, String>>,
417 /// The representative name for the entity.
418 pub name: Option<String>,
419 /// The salience score associated with the entity in the [0, 1.0] range. The salience score for an entity provides information about the importance or centrality of that entity to the entire document text. Scores closer to 0 are less salient, while scores closer to 1.0 are highly salient.
420 pub salience: Option<f32>,
421 /// The entity type.
422 #[serde(rename = "type")]
423 pub type_: Option<String>,
424}
425
426impl common::Part for Entity {}
427
428/// Represents a mention for an entity in the text. Currently, proper noun mentions are supported.
429///
430/// This type is not used in any activity, and only used as *part* of another schema.
431///
432#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
433#[serde_with::serde_as]
434#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
435pub struct EntityMention {
436 /// The mention text.
437 pub text: Option<TextSpan>,
438 /// The type of the entity mention.
439 #[serde(rename = "type")]
440 pub type_: Option<String>,
441}
442
443impl common::Part for EntityMention {}
444
445/// All available features for sentiment, syntax, and semantic analysis. Setting each one to true will enable that specific analysis for the input.
446///
447/// This type is not used in any activity, and only used as *part* of another schema.
448///
449#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
450#[serde_with::serde_as]
451#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
452pub struct Features {
453 /// Extract document-level sentiment.
454 #[serde(rename = "extractDocumentSentiment")]
455 pub extract_document_sentiment: Option<bool>,
456 /// Extract entities.
457 #[serde(rename = "extractEntities")]
458 pub extract_entities: Option<bool>,
459 /// Extract syntax information.
460 #[serde(rename = "extractSyntax")]
461 pub extract_syntax: Option<bool>,
462}
463
464impl common::Part for Features {}
465
466/// Represents part of speech information for a token.
467///
468/// This type is not used in any activity, and only used as *part* of another schema.
469///
470#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
471#[serde_with::serde_as]
472#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
473pub struct PartOfSpeech {
474 /// The grammatical aspect.
475 pub aspect: Option<String>,
476 /// The grammatical case.
477 pub case: Option<String>,
478 /// The grammatical form.
479 pub form: Option<String>,
480 /// The grammatical gender.
481 pub gender: Option<String>,
482 /// The grammatical mood.
483 pub mood: Option<String>,
484 /// The grammatical number.
485 pub number: Option<String>,
486 /// The grammatical person.
487 pub person: Option<String>,
488 /// The grammatical properness.
489 pub proper: Option<String>,
490 /// The grammatical reciprocity.
491 pub reciprocity: Option<String>,
492 /// The part of speech tag.
493 pub tag: Option<String>,
494 /// The grammatical tense.
495 pub tense: Option<String>,
496 /// The grammatical voice.
497 pub voice: Option<String>,
498}
499
500impl common::Part for PartOfSpeech {}
501
502/// Represents a sentence in the input document.
503///
504/// This type is not used in any activity, and only used as *part* of another schema.
505///
506#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
507#[serde_with::serde_as]
508#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
509pub struct Sentence {
510 /// For calls to AnalyzeSentiment or if AnnotateTextRequest.Features.extract_document_sentiment is set to true, this field will contain the sentiment for the sentence.
511 pub sentiment: Option<Sentiment>,
512 /// The sentence text.
513 pub text: Option<TextSpan>,
514}
515
516impl common::Part for Sentence {}
517
518/// Represents the feeling associated with the entire text or entities in the text.
519///
520/// This type is not used in any activity, and only used as *part* of another schema.
521///
522#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
523#[serde_with::serde_as]
524#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
525pub struct Sentiment {
526 /// A non-negative number in the [0, +inf) range, which represents the absolute magnitude of sentiment regardless of score (positive or negative).
527 pub magnitude: Option<f32>,
528 /// DEPRECATED FIELD - This field is being deprecated in favor of score. Please refer to our documentation at https://cloud.google.com/natural-language/docs for more information.
529 pub polarity: Option<f32>,
530 /// Sentiment score between -1.0 (negative sentiment) and 1.0 (positive sentiment).
531 pub score: Option<f32>,
532}
533
534impl common::Part for Sentiment {}
535
536/// Represents an output piece of text.
537///
538/// This type is not used in any activity, and only used as *part* of another schema.
539///
540#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
541#[serde_with::serde_as]
542#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
543pub struct TextSpan {
544 /// The API calculates the beginning offset of the content in the original document according to the EncodingType specified in the API request.
545 #[serde(rename = "beginOffset")]
546 pub begin_offset: Option<i32>,
547 /// The content of the output text.
548 pub content: Option<String>,
549}
550
551impl common::Part for TextSpan {}
552
553/// Represents the smallest syntactic building block of the text.
554///
555/// This type is not used in any activity, and only used as *part* of another schema.
556///
557#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
558#[serde_with::serde_as]
559#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
560pub struct Token {
561 /// Dependency tree parse for this token.
562 #[serde(rename = "dependencyEdge")]
563 pub dependency_edge: Option<DependencyEdge>,
564 /// [Lemma](https://en.wikipedia.org/wiki/Lemma_%28morphology%29) of the token.
565 pub lemma: Option<String>,
566 /// Parts of speech tag for this token.
567 #[serde(rename = "partOfSpeech")]
568 pub part_of_speech: Option<PartOfSpeech>,
569 /// The token text.
570 pub text: Option<TextSpan>,
571}
572
573impl common::Part for Token {}
574
575// ###################
576// MethodBuilders ###
577// #################
578
579/// A builder providing access to all methods supported on *document* resources.
580/// It is not used directly, but through the [`CloudNaturalLanguage`] hub.
581///
582/// # Example
583///
584/// Instantiate a resource builder
585///
586/// ```test_harness,no_run
587/// extern crate hyper;
588/// extern crate hyper_rustls;
589/// extern crate google_language1_beta1 as language1_beta1;
590///
591/// # async fn dox() {
592/// use language1_beta1::{CloudNaturalLanguage, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
593///
594/// let secret: yup_oauth2::ApplicationSecret = Default::default();
595/// let connector = hyper_rustls::HttpsConnectorBuilder::new()
596/// .with_native_roots()
597/// .unwrap()
598/// .https_only()
599/// .enable_http2()
600/// .build();
601///
602/// let executor = hyper_util::rt::TokioExecutor::new();
603/// let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
604/// secret,
605/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
606/// yup_oauth2::client::CustomHyperClientBuilder::from(
607/// hyper_util::client::legacy::Client::builder(executor).build(connector),
608/// ),
609/// ).build().await.unwrap();
610///
611/// let client = hyper_util::client::legacy::Client::builder(
612/// hyper_util::rt::TokioExecutor::new()
613/// )
614/// .build(
615/// hyper_rustls::HttpsConnectorBuilder::new()
616/// .with_native_roots()
617/// .unwrap()
618/// .https_or_http()
619/// .enable_http2()
620/// .build()
621/// );
622/// let mut hub = CloudNaturalLanguage::new(client, auth);
623/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
624/// // like `analyze_entities(...)`, `analyze_sentiment(...)`, `analyze_syntax(...)` and `annotate_text(...)`
625/// // to build up your call.
626/// let rb = hub.documents();
627/// # }
628/// ```
629pub struct DocumentMethods<'a, C>
630where
631 C: 'a,
632{
633 hub: &'a CloudNaturalLanguage<C>,
634}
635
636impl<'a, C> common::MethodsBuilder for DocumentMethods<'a, C> {}
637
638impl<'a, C> DocumentMethods<'a, C> {
639 /// Create a builder to help you perform the following task:
640 ///
641 /// Finds named entities (currently proper names and common nouns) in the text along with entity types, salience, mentions for each entity, and other properties.
642 ///
643 /// # Arguments
644 ///
645 /// * `request` - No description provided.
646 pub fn analyze_entities(
647 &self,
648 request: AnalyzeEntitiesRequest,
649 ) -> DocumentAnalyzeEntityCall<'a, C> {
650 DocumentAnalyzeEntityCall {
651 hub: self.hub,
652 _request: request,
653 _delegate: Default::default(),
654 _additional_params: Default::default(),
655 _scopes: Default::default(),
656 }
657 }
658
659 /// Create a builder to help you perform the following task:
660 ///
661 /// Analyzes the sentiment of the provided text.
662 ///
663 /// # Arguments
664 ///
665 /// * `request` - No description provided.
666 pub fn analyze_sentiment(
667 &self,
668 request: AnalyzeSentimentRequest,
669 ) -> DocumentAnalyzeSentimentCall<'a, C> {
670 DocumentAnalyzeSentimentCall {
671 hub: self.hub,
672 _request: request,
673 _delegate: Default::default(),
674 _additional_params: Default::default(),
675 _scopes: Default::default(),
676 }
677 }
678
679 /// Create a builder to help you perform the following task:
680 ///
681 /// Analyzes the syntax of the text and provides sentence boundaries and tokenization along with part of speech tags, dependency trees, and other properties.
682 ///
683 /// # Arguments
684 ///
685 /// * `request` - No description provided.
686 pub fn analyze_syntax(
687 &self,
688 request: AnalyzeSyntaxRequest,
689 ) -> DocumentAnalyzeSyntaxCall<'a, C> {
690 DocumentAnalyzeSyntaxCall {
691 hub: self.hub,
692 _request: request,
693 _delegate: Default::default(),
694 _additional_params: Default::default(),
695 _scopes: Default::default(),
696 }
697 }
698
699 /// Create a builder to help you perform the following task:
700 ///
701 /// A convenience method that provides all the features that analyzeSentiment, analyzeEntities, and analyzeSyntax provide in one call.
702 ///
703 /// # Arguments
704 ///
705 /// * `request` - No description provided.
706 pub fn annotate_text(&self, request: AnnotateTextRequest) -> DocumentAnnotateTextCall<'a, C> {
707 DocumentAnnotateTextCall {
708 hub: self.hub,
709 _request: request,
710 _delegate: Default::default(),
711 _additional_params: Default::default(),
712 _scopes: Default::default(),
713 }
714 }
715}
716
717// ###################
718// CallBuilders ###
719// #################
720
721/// Finds named entities (currently proper names and common nouns) in the text along with entity types, salience, mentions for each entity, and other properties.
722///
723/// A builder for the *analyzeEntities* method supported by a *document* resource.
724/// It is not used directly, but through a [`DocumentMethods`] instance.
725///
726/// # Example
727///
728/// Instantiate a resource method builder
729///
730/// ```test_harness,no_run
731/// # extern crate hyper;
732/// # extern crate hyper_rustls;
733/// # extern crate google_language1_beta1 as language1_beta1;
734/// use language1_beta1::api::AnalyzeEntitiesRequest;
735/// # async fn dox() {
736/// # use language1_beta1::{CloudNaturalLanguage, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
737///
738/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
739/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
740/// # .with_native_roots()
741/// # .unwrap()
742/// # .https_only()
743/// # .enable_http2()
744/// # .build();
745///
746/// # let executor = hyper_util::rt::TokioExecutor::new();
747/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
748/// # secret,
749/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
750/// # yup_oauth2::client::CustomHyperClientBuilder::from(
751/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
752/// # ),
753/// # ).build().await.unwrap();
754///
755/// # let client = hyper_util::client::legacy::Client::builder(
756/// # hyper_util::rt::TokioExecutor::new()
757/// # )
758/// # .build(
759/// # hyper_rustls::HttpsConnectorBuilder::new()
760/// # .with_native_roots()
761/// # .unwrap()
762/// # .https_or_http()
763/// # .enable_http2()
764/// # .build()
765/// # );
766/// # let mut hub = CloudNaturalLanguage::new(client, auth);
767/// // As the method needs a request, you would usually fill it with the desired information
768/// // into the respective structure. Some of the parts shown here might not be applicable !
769/// // Values shown here are possibly random and not representative !
770/// let mut req = AnalyzeEntitiesRequest::default();
771///
772/// // You can configure optional parameters by calling the respective setters at will, and
773/// // execute the final call using `doit()`.
774/// // Values shown here are possibly random and not representative !
775/// let result = hub.documents().analyze_entities(req)
776/// .doit().await;
777/// # }
778/// ```
779pub struct DocumentAnalyzeEntityCall<'a, C>
780where
781 C: 'a,
782{
783 hub: &'a CloudNaturalLanguage<C>,
784 _request: AnalyzeEntitiesRequest,
785 _delegate: Option<&'a mut dyn common::Delegate>,
786 _additional_params: HashMap<String, String>,
787 _scopes: BTreeSet<String>,
788}
789
790impl<'a, C> common::CallBuilder for DocumentAnalyzeEntityCall<'a, C> {}
791
792impl<'a, C> DocumentAnalyzeEntityCall<'a, C>
793where
794 C: common::Connector,
795{
796 /// Perform the operation you have build so far.
797 pub async fn doit(mut self) -> common::Result<(common::Response, AnalyzeEntitiesResponse)> {
798 use std::borrow::Cow;
799 use std::io::{Read, Seek};
800
801 use common::{url::Params, ToParts};
802 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
803
804 let mut dd = common::DefaultDelegate;
805 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
806 dlg.begin(common::MethodInfo {
807 id: "language.documents.analyzeEntities",
808 http_method: hyper::Method::POST,
809 });
810
811 for &field in ["alt"].iter() {
812 if self._additional_params.contains_key(field) {
813 dlg.finished(false);
814 return Err(common::Error::FieldClash(field));
815 }
816 }
817
818 let mut params = Params::with_capacity(3 + self._additional_params.len());
819
820 params.extend(self._additional_params.iter());
821
822 params.push("alt", "json");
823 let mut url = self.hub._base_url.clone() + "v1beta1/documents:analyzeEntities";
824 if self._scopes.is_empty() {
825 self._scopes
826 .insert(Scope::CloudPlatform.as_ref().to_string());
827 }
828
829 let url = params.parse_with_url(&url);
830
831 let mut json_mime_type = mime::APPLICATION_JSON;
832 let mut request_value_reader = {
833 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
834 common::remove_json_null_values(&mut value);
835 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
836 serde_json::to_writer(&mut dst, &value).unwrap();
837 dst
838 };
839 let request_size = request_value_reader
840 .seek(std::io::SeekFrom::End(0))
841 .unwrap();
842 request_value_reader
843 .seek(std::io::SeekFrom::Start(0))
844 .unwrap();
845
846 loop {
847 let token = match self
848 .hub
849 .auth
850 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
851 .await
852 {
853 Ok(token) => token,
854 Err(e) => match dlg.token(e) {
855 Ok(token) => token,
856 Err(e) => {
857 dlg.finished(false);
858 return Err(common::Error::MissingToken(e));
859 }
860 },
861 };
862 request_value_reader
863 .seek(std::io::SeekFrom::Start(0))
864 .unwrap();
865 let mut req_result = {
866 let client = &self.hub.client;
867 dlg.pre_request();
868 let mut req_builder = hyper::Request::builder()
869 .method(hyper::Method::POST)
870 .uri(url.as_str())
871 .header(USER_AGENT, self.hub._user_agent.clone());
872
873 if let Some(token) = token.as_ref() {
874 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
875 }
876
877 let request = req_builder
878 .header(CONTENT_TYPE, json_mime_type.to_string())
879 .header(CONTENT_LENGTH, request_size as u64)
880 .body(common::to_body(
881 request_value_reader.get_ref().clone().into(),
882 ));
883
884 client.request(request.unwrap()).await
885 };
886
887 match req_result {
888 Err(err) => {
889 if let common::Retry::After(d) = dlg.http_error(&err) {
890 sleep(d).await;
891 continue;
892 }
893 dlg.finished(false);
894 return Err(common::Error::HttpError(err));
895 }
896 Ok(res) => {
897 let (mut parts, body) = res.into_parts();
898 let mut body = common::Body::new(body);
899 if !parts.status.is_success() {
900 let bytes = common::to_bytes(body).await.unwrap_or_default();
901 let error = serde_json::from_str(&common::to_string(&bytes));
902 let response = common::to_response(parts, bytes.into());
903
904 if let common::Retry::After(d) =
905 dlg.http_failure(&response, error.as_ref().ok())
906 {
907 sleep(d).await;
908 continue;
909 }
910
911 dlg.finished(false);
912
913 return Err(match error {
914 Ok(value) => common::Error::BadRequest(value),
915 _ => common::Error::Failure(response),
916 });
917 }
918 let response = {
919 let bytes = common::to_bytes(body).await.unwrap_or_default();
920 let encoded = common::to_string(&bytes);
921 match serde_json::from_str(&encoded) {
922 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
923 Err(error) => {
924 dlg.response_json_decode_error(&encoded, &error);
925 return Err(common::Error::JsonDecodeError(
926 encoded.to_string(),
927 error,
928 ));
929 }
930 }
931 };
932
933 dlg.finished(true);
934 return Ok(response);
935 }
936 }
937 }
938 }
939
940 ///
941 /// Sets the *request* property to the given value.
942 ///
943 /// Even though the property as already been set when instantiating this call,
944 /// we provide this method for API completeness.
945 pub fn request(
946 mut self,
947 new_value: AnalyzeEntitiesRequest,
948 ) -> DocumentAnalyzeEntityCall<'a, C> {
949 self._request = new_value;
950 self
951 }
952 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
953 /// while executing the actual API request.
954 ///
955 /// ````text
956 /// It should be used to handle progress information, and to implement a certain level of resilience.
957 /// ````
958 ///
959 /// Sets the *delegate* property to the given value.
960 pub fn delegate(
961 mut self,
962 new_value: &'a mut dyn common::Delegate,
963 ) -> DocumentAnalyzeEntityCall<'a, C> {
964 self._delegate = Some(new_value);
965 self
966 }
967
968 /// Set any additional parameter of the query string used in the request.
969 /// It should be used to set parameters which are not yet available through their own
970 /// setters.
971 ///
972 /// Please note that this method must not be used to set any of the known parameters
973 /// which have their own setter method. If done anyway, the request will fail.
974 ///
975 /// # Additional Parameters
976 ///
977 /// * *$.xgafv* (query-string) - V1 error format.
978 /// * *access_token* (query-string) - OAuth access token.
979 /// * *alt* (query-string) - Data format for response.
980 /// * *callback* (query-string) - JSONP
981 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
982 /// * *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.
983 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
984 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
985 /// * *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.
986 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
987 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
988 pub fn param<T>(mut self, name: T, value: T) -> DocumentAnalyzeEntityCall<'a, C>
989 where
990 T: AsRef<str>,
991 {
992 self._additional_params
993 .insert(name.as_ref().to_string(), value.as_ref().to_string());
994 self
995 }
996
997 /// Identifies the authorization scope for the method you are building.
998 ///
999 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1000 /// [`Scope::CloudPlatform`].
1001 ///
1002 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1003 /// tokens for more than one scope.
1004 ///
1005 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1006 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1007 /// sufficient, a read-write scope will do as well.
1008 pub fn add_scope<St>(mut self, scope: St) -> DocumentAnalyzeEntityCall<'a, C>
1009 where
1010 St: AsRef<str>,
1011 {
1012 self._scopes.insert(String::from(scope.as_ref()));
1013 self
1014 }
1015 /// Identifies the authorization scope(s) for the method you are building.
1016 ///
1017 /// See [`Self::add_scope()`] for details.
1018 pub fn add_scopes<I, St>(mut self, scopes: I) -> DocumentAnalyzeEntityCall<'a, C>
1019 where
1020 I: IntoIterator<Item = St>,
1021 St: AsRef<str>,
1022 {
1023 self._scopes
1024 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1025 self
1026 }
1027
1028 /// Removes all scopes, and no default scope will be used either.
1029 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1030 /// for details).
1031 pub fn clear_scopes(mut self) -> DocumentAnalyzeEntityCall<'a, C> {
1032 self._scopes.clear();
1033 self
1034 }
1035}
1036
1037/// Analyzes the sentiment of the provided text.
1038///
1039/// A builder for the *analyzeSentiment* method supported by a *document* resource.
1040/// It is not used directly, but through a [`DocumentMethods`] instance.
1041///
1042/// # Example
1043///
1044/// Instantiate a resource method builder
1045///
1046/// ```test_harness,no_run
1047/// # extern crate hyper;
1048/// # extern crate hyper_rustls;
1049/// # extern crate google_language1_beta1 as language1_beta1;
1050/// use language1_beta1::api::AnalyzeSentimentRequest;
1051/// # async fn dox() {
1052/// # use language1_beta1::{CloudNaturalLanguage, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1053///
1054/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1055/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
1056/// # .with_native_roots()
1057/// # .unwrap()
1058/// # .https_only()
1059/// # .enable_http2()
1060/// # .build();
1061///
1062/// # let executor = hyper_util::rt::TokioExecutor::new();
1063/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
1064/// # secret,
1065/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1066/// # yup_oauth2::client::CustomHyperClientBuilder::from(
1067/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
1068/// # ),
1069/// # ).build().await.unwrap();
1070///
1071/// # let client = hyper_util::client::legacy::Client::builder(
1072/// # hyper_util::rt::TokioExecutor::new()
1073/// # )
1074/// # .build(
1075/// # hyper_rustls::HttpsConnectorBuilder::new()
1076/// # .with_native_roots()
1077/// # .unwrap()
1078/// # .https_or_http()
1079/// # .enable_http2()
1080/// # .build()
1081/// # );
1082/// # let mut hub = CloudNaturalLanguage::new(client, auth);
1083/// // As the method needs a request, you would usually fill it with the desired information
1084/// // into the respective structure. Some of the parts shown here might not be applicable !
1085/// // Values shown here are possibly random and not representative !
1086/// let mut req = AnalyzeSentimentRequest::default();
1087///
1088/// // You can configure optional parameters by calling the respective setters at will, and
1089/// // execute the final call using `doit()`.
1090/// // Values shown here are possibly random and not representative !
1091/// let result = hub.documents().analyze_sentiment(req)
1092/// .doit().await;
1093/// # }
1094/// ```
1095pub struct DocumentAnalyzeSentimentCall<'a, C>
1096where
1097 C: 'a,
1098{
1099 hub: &'a CloudNaturalLanguage<C>,
1100 _request: AnalyzeSentimentRequest,
1101 _delegate: Option<&'a mut dyn common::Delegate>,
1102 _additional_params: HashMap<String, String>,
1103 _scopes: BTreeSet<String>,
1104}
1105
1106impl<'a, C> common::CallBuilder for DocumentAnalyzeSentimentCall<'a, C> {}
1107
1108impl<'a, C> DocumentAnalyzeSentimentCall<'a, C>
1109where
1110 C: common::Connector,
1111{
1112 /// Perform the operation you have build so far.
1113 pub async fn doit(mut self) -> common::Result<(common::Response, AnalyzeSentimentResponse)> {
1114 use std::borrow::Cow;
1115 use std::io::{Read, Seek};
1116
1117 use common::{url::Params, ToParts};
1118 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1119
1120 let mut dd = common::DefaultDelegate;
1121 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1122 dlg.begin(common::MethodInfo {
1123 id: "language.documents.analyzeSentiment",
1124 http_method: hyper::Method::POST,
1125 });
1126
1127 for &field in ["alt"].iter() {
1128 if self._additional_params.contains_key(field) {
1129 dlg.finished(false);
1130 return Err(common::Error::FieldClash(field));
1131 }
1132 }
1133
1134 let mut params = Params::with_capacity(3 + self._additional_params.len());
1135
1136 params.extend(self._additional_params.iter());
1137
1138 params.push("alt", "json");
1139 let mut url = self.hub._base_url.clone() + "v1beta1/documents:analyzeSentiment";
1140 if self._scopes.is_empty() {
1141 self._scopes
1142 .insert(Scope::CloudPlatform.as_ref().to_string());
1143 }
1144
1145 let url = params.parse_with_url(&url);
1146
1147 let mut json_mime_type = mime::APPLICATION_JSON;
1148 let mut request_value_reader = {
1149 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
1150 common::remove_json_null_values(&mut value);
1151 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
1152 serde_json::to_writer(&mut dst, &value).unwrap();
1153 dst
1154 };
1155 let request_size = request_value_reader
1156 .seek(std::io::SeekFrom::End(0))
1157 .unwrap();
1158 request_value_reader
1159 .seek(std::io::SeekFrom::Start(0))
1160 .unwrap();
1161
1162 loop {
1163 let token = match self
1164 .hub
1165 .auth
1166 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1167 .await
1168 {
1169 Ok(token) => token,
1170 Err(e) => match dlg.token(e) {
1171 Ok(token) => token,
1172 Err(e) => {
1173 dlg.finished(false);
1174 return Err(common::Error::MissingToken(e));
1175 }
1176 },
1177 };
1178 request_value_reader
1179 .seek(std::io::SeekFrom::Start(0))
1180 .unwrap();
1181 let mut req_result = {
1182 let client = &self.hub.client;
1183 dlg.pre_request();
1184 let mut req_builder = hyper::Request::builder()
1185 .method(hyper::Method::POST)
1186 .uri(url.as_str())
1187 .header(USER_AGENT, self.hub._user_agent.clone());
1188
1189 if let Some(token) = token.as_ref() {
1190 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1191 }
1192
1193 let request = req_builder
1194 .header(CONTENT_TYPE, json_mime_type.to_string())
1195 .header(CONTENT_LENGTH, request_size as u64)
1196 .body(common::to_body(
1197 request_value_reader.get_ref().clone().into(),
1198 ));
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 ///
1257 /// Sets the *request* property to the given value.
1258 ///
1259 /// Even though the property as already been set when instantiating this call,
1260 /// we provide this method for API completeness.
1261 pub fn request(
1262 mut self,
1263 new_value: AnalyzeSentimentRequest,
1264 ) -> DocumentAnalyzeSentimentCall<'a, C> {
1265 self._request = new_value;
1266 self
1267 }
1268 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1269 /// while executing the actual API request.
1270 ///
1271 /// ````text
1272 /// It should be used to handle progress information, and to implement a certain level of resilience.
1273 /// ````
1274 ///
1275 /// Sets the *delegate* property to the given value.
1276 pub fn delegate(
1277 mut self,
1278 new_value: &'a mut dyn common::Delegate,
1279 ) -> DocumentAnalyzeSentimentCall<'a, C> {
1280 self._delegate = Some(new_value);
1281 self
1282 }
1283
1284 /// Set any additional parameter of the query string used in the request.
1285 /// It should be used to set parameters which are not yet available through their own
1286 /// setters.
1287 ///
1288 /// Please note that this method must not be used to set any of the known parameters
1289 /// which have their own setter method. If done anyway, the request will fail.
1290 ///
1291 /// # Additional Parameters
1292 ///
1293 /// * *$.xgafv* (query-string) - V1 error format.
1294 /// * *access_token* (query-string) - OAuth access token.
1295 /// * *alt* (query-string) - Data format for response.
1296 /// * *callback* (query-string) - JSONP
1297 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1298 /// * *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.
1299 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1300 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1301 /// * *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.
1302 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1303 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1304 pub fn param<T>(mut self, name: T, value: T) -> DocumentAnalyzeSentimentCall<'a, C>
1305 where
1306 T: AsRef<str>,
1307 {
1308 self._additional_params
1309 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1310 self
1311 }
1312
1313 /// Identifies the authorization scope for the method you are building.
1314 ///
1315 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1316 /// [`Scope::CloudPlatform`].
1317 ///
1318 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1319 /// tokens for more than one scope.
1320 ///
1321 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1322 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1323 /// sufficient, a read-write scope will do as well.
1324 pub fn add_scope<St>(mut self, scope: St) -> DocumentAnalyzeSentimentCall<'a, C>
1325 where
1326 St: AsRef<str>,
1327 {
1328 self._scopes.insert(String::from(scope.as_ref()));
1329 self
1330 }
1331 /// Identifies the authorization scope(s) for the method you are building.
1332 ///
1333 /// See [`Self::add_scope()`] for details.
1334 pub fn add_scopes<I, St>(mut self, scopes: I) -> DocumentAnalyzeSentimentCall<'a, C>
1335 where
1336 I: IntoIterator<Item = St>,
1337 St: AsRef<str>,
1338 {
1339 self._scopes
1340 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1341 self
1342 }
1343
1344 /// Removes all scopes, and no default scope will be used either.
1345 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1346 /// for details).
1347 pub fn clear_scopes(mut self) -> DocumentAnalyzeSentimentCall<'a, C> {
1348 self._scopes.clear();
1349 self
1350 }
1351}
1352
1353/// Analyzes the syntax of the text and provides sentence boundaries and tokenization along with part of speech tags, dependency trees, and other properties.
1354///
1355/// A builder for the *analyzeSyntax* method supported by a *document* resource.
1356/// It is not used directly, but through a [`DocumentMethods`] instance.
1357///
1358/// # Example
1359///
1360/// Instantiate a resource method builder
1361///
1362/// ```test_harness,no_run
1363/// # extern crate hyper;
1364/// # extern crate hyper_rustls;
1365/// # extern crate google_language1_beta1 as language1_beta1;
1366/// use language1_beta1::api::AnalyzeSyntaxRequest;
1367/// # async fn dox() {
1368/// # use language1_beta1::{CloudNaturalLanguage, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1369///
1370/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1371/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
1372/// # .with_native_roots()
1373/// # .unwrap()
1374/// # .https_only()
1375/// # .enable_http2()
1376/// # .build();
1377///
1378/// # let executor = hyper_util::rt::TokioExecutor::new();
1379/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
1380/// # secret,
1381/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1382/// # yup_oauth2::client::CustomHyperClientBuilder::from(
1383/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
1384/// # ),
1385/// # ).build().await.unwrap();
1386///
1387/// # let client = hyper_util::client::legacy::Client::builder(
1388/// # hyper_util::rt::TokioExecutor::new()
1389/// # )
1390/// # .build(
1391/// # hyper_rustls::HttpsConnectorBuilder::new()
1392/// # .with_native_roots()
1393/// # .unwrap()
1394/// # .https_or_http()
1395/// # .enable_http2()
1396/// # .build()
1397/// # );
1398/// # let mut hub = CloudNaturalLanguage::new(client, auth);
1399/// // As the method needs a request, you would usually fill it with the desired information
1400/// // into the respective structure. Some of the parts shown here might not be applicable !
1401/// // Values shown here are possibly random and not representative !
1402/// let mut req = AnalyzeSyntaxRequest::default();
1403///
1404/// // You can configure optional parameters by calling the respective setters at will, and
1405/// // execute the final call using `doit()`.
1406/// // Values shown here are possibly random and not representative !
1407/// let result = hub.documents().analyze_syntax(req)
1408/// .doit().await;
1409/// # }
1410/// ```
1411pub struct DocumentAnalyzeSyntaxCall<'a, C>
1412where
1413 C: 'a,
1414{
1415 hub: &'a CloudNaturalLanguage<C>,
1416 _request: AnalyzeSyntaxRequest,
1417 _delegate: Option<&'a mut dyn common::Delegate>,
1418 _additional_params: HashMap<String, String>,
1419 _scopes: BTreeSet<String>,
1420}
1421
1422impl<'a, C> common::CallBuilder for DocumentAnalyzeSyntaxCall<'a, C> {}
1423
1424impl<'a, C> DocumentAnalyzeSyntaxCall<'a, C>
1425where
1426 C: common::Connector,
1427{
1428 /// Perform the operation you have build so far.
1429 pub async fn doit(mut self) -> common::Result<(common::Response, AnalyzeSyntaxResponse)> {
1430 use std::borrow::Cow;
1431 use std::io::{Read, Seek};
1432
1433 use common::{url::Params, ToParts};
1434 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1435
1436 let mut dd = common::DefaultDelegate;
1437 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1438 dlg.begin(common::MethodInfo {
1439 id: "language.documents.analyzeSyntax",
1440 http_method: hyper::Method::POST,
1441 });
1442
1443 for &field in ["alt"].iter() {
1444 if self._additional_params.contains_key(field) {
1445 dlg.finished(false);
1446 return Err(common::Error::FieldClash(field));
1447 }
1448 }
1449
1450 let mut params = Params::with_capacity(3 + self._additional_params.len());
1451
1452 params.extend(self._additional_params.iter());
1453
1454 params.push("alt", "json");
1455 let mut url = self.hub._base_url.clone() + "v1beta1/documents:analyzeSyntax";
1456 if self._scopes.is_empty() {
1457 self._scopes
1458 .insert(Scope::CloudPlatform.as_ref().to_string());
1459 }
1460
1461 let url = params.parse_with_url(&url);
1462
1463 let mut json_mime_type = mime::APPLICATION_JSON;
1464 let mut request_value_reader = {
1465 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
1466 common::remove_json_null_values(&mut value);
1467 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
1468 serde_json::to_writer(&mut dst, &value).unwrap();
1469 dst
1470 };
1471 let request_size = request_value_reader
1472 .seek(std::io::SeekFrom::End(0))
1473 .unwrap();
1474 request_value_reader
1475 .seek(std::io::SeekFrom::Start(0))
1476 .unwrap();
1477
1478 loop {
1479 let token = match self
1480 .hub
1481 .auth
1482 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1483 .await
1484 {
1485 Ok(token) => token,
1486 Err(e) => match dlg.token(e) {
1487 Ok(token) => token,
1488 Err(e) => {
1489 dlg.finished(false);
1490 return Err(common::Error::MissingToken(e));
1491 }
1492 },
1493 };
1494 request_value_reader
1495 .seek(std::io::SeekFrom::Start(0))
1496 .unwrap();
1497 let mut req_result = {
1498 let client = &self.hub.client;
1499 dlg.pre_request();
1500 let mut req_builder = hyper::Request::builder()
1501 .method(hyper::Method::POST)
1502 .uri(url.as_str())
1503 .header(USER_AGENT, self.hub._user_agent.clone());
1504
1505 if let Some(token) = token.as_ref() {
1506 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1507 }
1508
1509 let request = req_builder
1510 .header(CONTENT_TYPE, json_mime_type.to_string())
1511 .header(CONTENT_LENGTH, request_size as u64)
1512 .body(common::to_body(
1513 request_value_reader.get_ref().clone().into(),
1514 ));
1515
1516 client.request(request.unwrap()).await
1517 };
1518
1519 match req_result {
1520 Err(err) => {
1521 if let common::Retry::After(d) = dlg.http_error(&err) {
1522 sleep(d).await;
1523 continue;
1524 }
1525 dlg.finished(false);
1526 return Err(common::Error::HttpError(err));
1527 }
1528 Ok(res) => {
1529 let (mut parts, body) = res.into_parts();
1530 let mut body = common::Body::new(body);
1531 if !parts.status.is_success() {
1532 let bytes = common::to_bytes(body).await.unwrap_or_default();
1533 let error = serde_json::from_str(&common::to_string(&bytes));
1534 let response = common::to_response(parts, bytes.into());
1535
1536 if let common::Retry::After(d) =
1537 dlg.http_failure(&response, error.as_ref().ok())
1538 {
1539 sleep(d).await;
1540 continue;
1541 }
1542
1543 dlg.finished(false);
1544
1545 return Err(match error {
1546 Ok(value) => common::Error::BadRequest(value),
1547 _ => common::Error::Failure(response),
1548 });
1549 }
1550 let response = {
1551 let bytes = common::to_bytes(body).await.unwrap_or_default();
1552 let encoded = common::to_string(&bytes);
1553 match serde_json::from_str(&encoded) {
1554 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1555 Err(error) => {
1556 dlg.response_json_decode_error(&encoded, &error);
1557 return Err(common::Error::JsonDecodeError(
1558 encoded.to_string(),
1559 error,
1560 ));
1561 }
1562 }
1563 };
1564
1565 dlg.finished(true);
1566 return Ok(response);
1567 }
1568 }
1569 }
1570 }
1571
1572 ///
1573 /// Sets the *request* property to the given value.
1574 ///
1575 /// Even though the property as already been set when instantiating this call,
1576 /// we provide this method for API completeness.
1577 pub fn request(mut self, new_value: AnalyzeSyntaxRequest) -> DocumentAnalyzeSyntaxCall<'a, C> {
1578 self._request = new_value;
1579 self
1580 }
1581 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1582 /// while executing the actual API request.
1583 ///
1584 /// ````text
1585 /// It should be used to handle progress information, and to implement a certain level of resilience.
1586 /// ````
1587 ///
1588 /// Sets the *delegate* property to the given value.
1589 pub fn delegate(
1590 mut self,
1591 new_value: &'a mut dyn common::Delegate,
1592 ) -> DocumentAnalyzeSyntaxCall<'a, C> {
1593 self._delegate = Some(new_value);
1594 self
1595 }
1596
1597 /// Set any additional parameter of the query string used in the request.
1598 /// It should be used to set parameters which are not yet available through their own
1599 /// setters.
1600 ///
1601 /// Please note that this method must not be used to set any of the known parameters
1602 /// which have their own setter method. If done anyway, the request will fail.
1603 ///
1604 /// # Additional Parameters
1605 ///
1606 /// * *$.xgafv* (query-string) - V1 error format.
1607 /// * *access_token* (query-string) - OAuth access token.
1608 /// * *alt* (query-string) - Data format for response.
1609 /// * *callback* (query-string) - JSONP
1610 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1611 /// * *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.
1612 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1613 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1614 /// * *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.
1615 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1616 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1617 pub fn param<T>(mut self, name: T, value: T) -> DocumentAnalyzeSyntaxCall<'a, C>
1618 where
1619 T: AsRef<str>,
1620 {
1621 self._additional_params
1622 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1623 self
1624 }
1625
1626 /// Identifies the authorization scope for the method you are building.
1627 ///
1628 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1629 /// [`Scope::CloudPlatform`].
1630 ///
1631 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1632 /// tokens for more than one scope.
1633 ///
1634 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1635 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1636 /// sufficient, a read-write scope will do as well.
1637 pub fn add_scope<St>(mut self, scope: St) -> DocumentAnalyzeSyntaxCall<'a, C>
1638 where
1639 St: AsRef<str>,
1640 {
1641 self._scopes.insert(String::from(scope.as_ref()));
1642 self
1643 }
1644 /// Identifies the authorization scope(s) for the method you are building.
1645 ///
1646 /// See [`Self::add_scope()`] for details.
1647 pub fn add_scopes<I, St>(mut self, scopes: I) -> DocumentAnalyzeSyntaxCall<'a, C>
1648 where
1649 I: IntoIterator<Item = St>,
1650 St: AsRef<str>,
1651 {
1652 self._scopes
1653 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1654 self
1655 }
1656
1657 /// Removes all scopes, and no default scope will be used either.
1658 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1659 /// for details).
1660 pub fn clear_scopes(mut self) -> DocumentAnalyzeSyntaxCall<'a, C> {
1661 self._scopes.clear();
1662 self
1663 }
1664}
1665
1666/// A convenience method that provides all the features that analyzeSentiment, analyzeEntities, and analyzeSyntax provide in one call.
1667///
1668/// A builder for the *annotateText* method supported by a *document* resource.
1669/// It is not used directly, but through a [`DocumentMethods`] instance.
1670///
1671/// # Example
1672///
1673/// Instantiate a resource method builder
1674///
1675/// ```test_harness,no_run
1676/// # extern crate hyper;
1677/// # extern crate hyper_rustls;
1678/// # extern crate google_language1_beta1 as language1_beta1;
1679/// use language1_beta1::api::AnnotateTextRequest;
1680/// # async fn dox() {
1681/// # use language1_beta1::{CloudNaturalLanguage, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1682///
1683/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1684/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
1685/// # .with_native_roots()
1686/// # .unwrap()
1687/// # .https_only()
1688/// # .enable_http2()
1689/// # .build();
1690///
1691/// # let executor = hyper_util::rt::TokioExecutor::new();
1692/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
1693/// # secret,
1694/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1695/// # yup_oauth2::client::CustomHyperClientBuilder::from(
1696/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
1697/// # ),
1698/// # ).build().await.unwrap();
1699///
1700/// # let client = hyper_util::client::legacy::Client::builder(
1701/// # hyper_util::rt::TokioExecutor::new()
1702/// # )
1703/// # .build(
1704/// # hyper_rustls::HttpsConnectorBuilder::new()
1705/// # .with_native_roots()
1706/// # .unwrap()
1707/// # .https_or_http()
1708/// # .enable_http2()
1709/// # .build()
1710/// # );
1711/// # let mut hub = CloudNaturalLanguage::new(client, auth);
1712/// // As the method needs a request, you would usually fill it with the desired information
1713/// // into the respective structure. Some of the parts shown here might not be applicable !
1714/// // Values shown here are possibly random and not representative !
1715/// let mut req = AnnotateTextRequest::default();
1716///
1717/// // You can configure optional parameters by calling the respective setters at will, and
1718/// // execute the final call using `doit()`.
1719/// // Values shown here are possibly random and not representative !
1720/// let result = hub.documents().annotate_text(req)
1721/// .doit().await;
1722/// # }
1723/// ```
1724pub struct DocumentAnnotateTextCall<'a, C>
1725where
1726 C: 'a,
1727{
1728 hub: &'a CloudNaturalLanguage<C>,
1729 _request: AnnotateTextRequest,
1730 _delegate: Option<&'a mut dyn common::Delegate>,
1731 _additional_params: HashMap<String, String>,
1732 _scopes: BTreeSet<String>,
1733}
1734
1735impl<'a, C> common::CallBuilder for DocumentAnnotateTextCall<'a, C> {}
1736
1737impl<'a, C> DocumentAnnotateTextCall<'a, C>
1738where
1739 C: common::Connector,
1740{
1741 /// Perform the operation you have build so far.
1742 pub async fn doit(mut self) -> common::Result<(common::Response, AnnotateTextResponse)> {
1743 use std::borrow::Cow;
1744 use std::io::{Read, Seek};
1745
1746 use common::{url::Params, ToParts};
1747 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1748
1749 let mut dd = common::DefaultDelegate;
1750 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1751 dlg.begin(common::MethodInfo {
1752 id: "language.documents.annotateText",
1753 http_method: hyper::Method::POST,
1754 });
1755
1756 for &field in ["alt"].iter() {
1757 if self._additional_params.contains_key(field) {
1758 dlg.finished(false);
1759 return Err(common::Error::FieldClash(field));
1760 }
1761 }
1762
1763 let mut params = Params::with_capacity(3 + self._additional_params.len());
1764
1765 params.extend(self._additional_params.iter());
1766
1767 params.push("alt", "json");
1768 let mut url = self.hub._base_url.clone() + "v1beta1/documents:annotateText";
1769 if self._scopes.is_empty() {
1770 self._scopes
1771 .insert(Scope::CloudPlatform.as_ref().to_string());
1772 }
1773
1774 let url = params.parse_with_url(&url);
1775
1776 let mut json_mime_type = mime::APPLICATION_JSON;
1777 let mut request_value_reader = {
1778 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
1779 common::remove_json_null_values(&mut value);
1780 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
1781 serde_json::to_writer(&mut dst, &value).unwrap();
1782 dst
1783 };
1784 let request_size = request_value_reader
1785 .seek(std::io::SeekFrom::End(0))
1786 .unwrap();
1787 request_value_reader
1788 .seek(std::io::SeekFrom::Start(0))
1789 .unwrap();
1790
1791 loop {
1792 let token = match self
1793 .hub
1794 .auth
1795 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1796 .await
1797 {
1798 Ok(token) => token,
1799 Err(e) => match dlg.token(e) {
1800 Ok(token) => token,
1801 Err(e) => {
1802 dlg.finished(false);
1803 return Err(common::Error::MissingToken(e));
1804 }
1805 },
1806 };
1807 request_value_reader
1808 .seek(std::io::SeekFrom::Start(0))
1809 .unwrap();
1810 let mut req_result = {
1811 let client = &self.hub.client;
1812 dlg.pre_request();
1813 let mut req_builder = hyper::Request::builder()
1814 .method(hyper::Method::POST)
1815 .uri(url.as_str())
1816 .header(USER_AGENT, self.hub._user_agent.clone());
1817
1818 if let Some(token) = token.as_ref() {
1819 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1820 }
1821
1822 let request = req_builder
1823 .header(CONTENT_TYPE, json_mime_type.to_string())
1824 .header(CONTENT_LENGTH, request_size as u64)
1825 .body(common::to_body(
1826 request_value_reader.get_ref().clone().into(),
1827 ));
1828
1829 client.request(request.unwrap()).await
1830 };
1831
1832 match req_result {
1833 Err(err) => {
1834 if let common::Retry::After(d) = dlg.http_error(&err) {
1835 sleep(d).await;
1836 continue;
1837 }
1838 dlg.finished(false);
1839 return Err(common::Error::HttpError(err));
1840 }
1841 Ok(res) => {
1842 let (mut parts, body) = res.into_parts();
1843 let mut body = common::Body::new(body);
1844 if !parts.status.is_success() {
1845 let bytes = common::to_bytes(body).await.unwrap_or_default();
1846 let error = serde_json::from_str(&common::to_string(&bytes));
1847 let response = common::to_response(parts, bytes.into());
1848
1849 if let common::Retry::After(d) =
1850 dlg.http_failure(&response, error.as_ref().ok())
1851 {
1852 sleep(d).await;
1853 continue;
1854 }
1855
1856 dlg.finished(false);
1857
1858 return Err(match error {
1859 Ok(value) => common::Error::BadRequest(value),
1860 _ => common::Error::Failure(response),
1861 });
1862 }
1863 let response = {
1864 let bytes = common::to_bytes(body).await.unwrap_or_default();
1865 let encoded = common::to_string(&bytes);
1866 match serde_json::from_str(&encoded) {
1867 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1868 Err(error) => {
1869 dlg.response_json_decode_error(&encoded, &error);
1870 return Err(common::Error::JsonDecodeError(
1871 encoded.to_string(),
1872 error,
1873 ));
1874 }
1875 }
1876 };
1877
1878 dlg.finished(true);
1879 return Ok(response);
1880 }
1881 }
1882 }
1883 }
1884
1885 ///
1886 /// Sets the *request* property to the given value.
1887 ///
1888 /// Even though the property as already been set when instantiating this call,
1889 /// we provide this method for API completeness.
1890 pub fn request(mut self, new_value: AnnotateTextRequest) -> DocumentAnnotateTextCall<'a, C> {
1891 self._request = new_value;
1892 self
1893 }
1894 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1895 /// while executing the actual API request.
1896 ///
1897 /// ````text
1898 /// It should be used to handle progress information, and to implement a certain level of resilience.
1899 /// ````
1900 ///
1901 /// Sets the *delegate* property to the given value.
1902 pub fn delegate(
1903 mut self,
1904 new_value: &'a mut dyn common::Delegate,
1905 ) -> DocumentAnnotateTextCall<'a, C> {
1906 self._delegate = Some(new_value);
1907 self
1908 }
1909
1910 /// Set any additional parameter of the query string used in the request.
1911 /// It should be used to set parameters which are not yet available through their own
1912 /// setters.
1913 ///
1914 /// Please note that this method must not be used to set any of the known parameters
1915 /// which have their own setter method. If done anyway, the request will fail.
1916 ///
1917 /// # Additional Parameters
1918 ///
1919 /// * *$.xgafv* (query-string) - V1 error format.
1920 /// * *access_token* (query-string) - OAuth access token.
1921 /// * *alt* (query-string) - Data format for response.
1922 /// * *callback* (query-string) - JSONP
1923 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1924 /// * *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.
1925 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1926 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1927 /// * *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.
1928 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1929 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1930 pub fn param<T>(mut self, name: T, value: T) -> DocumentAnnotateTextCall<'a, C>
1931 where
1932 T: AsRef<str>,
1933 {
1934 self._additional_params
1935 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1936 self
1937 }
1938
1939 /// Identifies the authorization scope for the method you are building.
1940 ///
1941 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1942 /// [`Scope::CloudPlatform`].
1943 ///
1944 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1945 /// tokens for more than one scope.
1946 ///
1947 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1948 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1949 /// sufficient, a read-write scope will do as well.
1950 pub fn add_scope<St>(mut self, scope: St) -> DocumentAnnotateTextCall<'a, C>
1951 where
1952 St: AsRef<str>,
1953 {
1954 self._scopes.insert(String::from(scope.as_ref()));
1955 self
1956 }
1957 /// Identifies the authorization scope(s) for the method you are building.
1958 ///
1959 /// See [`Self::add_scope()`] for details.
1960 pub fn add_scopes<I, St>(mut self, scopes: I) -> DocumentAnnotateTextCall<'a, C>
1961 where
1962 I: IntoIterator<Item = St>,
1963 St: AsRef<str>,
1964 {
1965 self._scopes
1966 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1967 self
1968 }
1969
1970 /// Removes all scopes, and no default scope will be used either.
1971 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1972 /// for details).
1973 pub fn clear_scopes(mut self) -> DocumentAnnotateTextCall<'a, C> {
1974 self._scopes.clear();
1975 self
1976 }
1977}