google_cloud_essentialcontacts_v1/client.rs
1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16#![allow(rustdoc::bare_urls)]
17#![allow(rustdoc::broken_intra_doc_links)]
18#![allow(rustdoc::invalid_html_tags)]
19#![allow(rustdoc::redundant_explicit_links)]
20
21/// Implements a client for the Essential Contacts API.
22///
23/// # Example
24/// ```
25/// # use google_cloud_essentialcontacts_v1::client::EssentialContactsService;
26/// use google_cloud_gax::paginator::ItemPaginator as _;
27/// async fn sample(
28/// project_id: &str,
29/// ) -> anyhow::Result<()> {
30/// let client = EssentialContactsService::builder().build().await?;
31/// let mut list = client.list_contacts()
32/// .set_parent(format!("projects/{project_id}"))
33/// .by_item();
34/// while let Some(item) = list.next().await.transpose()? {
35/// println!("{:?}", item);
36/// }
37/// Ok(())
38/// }
39/// ```
40///
41/// # Service Description
42///
43/// Manages contacts for important Google Cloud notifications.
44///
45/// # Configuration
46///
47/// To configure `EssentialContactsService` use the `with_*` methods in the type returned
48/// by [builder()][EssentialContactsService::builder]. The default configuration should
49/// work for most applications. Common configuration changes include
50///
51/// * [with_endpoint()]: by default this client uses the global default endpoint
52/// (`https://essentialcontacts.googleapis.com`). Applications using regional
53/// endpoints or running in restricted networks (e.g. a network configured
54/// with [Private Google Access with VPC Service Controls]) may want to
55/// override this default.
56/// * [with_credentials()]: by default this client uses
57/// [Application Default Credentials]. Applications using custom
58/// authentication may need to override this default.
59///
60/// [with_endpoint()]: super::builder::essential_contacts_service::ClientBuilder::with_endpoint
61/// [with_credentials()]: super::builder::essential_contacts_service::ClientBuilder::with_credentials
62/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
63/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
64///
65/// # Pooling and Cloning
66///
67/// `EssentialContactsService` holds a connection pool internally, it is advised to
68/// create one and reuse it. You do not need to wrap `EssentialContactsService` in
69/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
70/// already uses an `Arc` internally.
71#[derive(Clone, Debug)]
72pub struct EssentialContactsService {
73 inner: std::sync::Arc<dyn super::stub::dynamic::EssentialContactsService>,
74}
75
76impl EssentialContactsService {
77 /// Returns a builder for [EssentialContactsService].
78 ///
79 /// ```
80 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
81 /// # use google_cloud_essentialcontacts_v1::client::EssentialContactsService;
82 /// let client = EssentialContactsService::builder().build().await?;
83 /// # Ok(()) }
84 /// ```
85 pub fn builder() -> super::builder::essential_contacts_service::ClientBuilder {
86 crate::new_client_builder(super::builder::essential_contacts_service::client::Factory)
87 }
88
89 /// Creates a new client from the provided stub.
90 ///
91 /// The most common case for calling this function is in tests mocking the
92 /// client's behavior.
93 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
94 where
95 T: super::stub::EssentialContactsService + 'static,
96 {
97 Self { inner: stub.into() }
98 }
99
100 pub(crate) async fn new(
101 config: gaxi::options::ClientConfig,
102 ) -> crate::ClientBuilderResult<Self> {
103 let inner = Self::build_inner(config).await?;
104 Ok(Self { inner })
105 }
106
107 async fn build_inner(
108 conf: gaxi::options::ClientConfig,
109 ) -> crate::ClientBuilderResult<
110 std::sync::Arc<dyn super::stub::dynamic::EssentialContactsService>,
111 > {
112 if gaxi::options::tracing_enabled(&conf) {
113 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
114 }
115 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
116 }
117
118 async fn build_transport(
119 conf: gaxi::options::ClientConfig,
120 ) -> crate::ClientBuilderResult<impl super::stub::EssentialContactsService> {
121 super::transport::EssentialContactsService::new(conf).await
122 }
123
124 async fn build_with_tracing(
125 conf: gaxi::options::ClientConfig,
126 ) -> crate::ClientBuilderResult<impl super::stub::EssentialContactsService> {
127 Self::build_transport(conf)
128 .await
129 .map(super::tracing::EssentialContactsService::new)
130 }
131
132 /// Adds a new contact for a resource.
133 ///
134 /// # Example
135 /// ```
136 /// # use google_cloud_essentialcontacts_v1::client::EssentialContactsService;
137 /// use google_cloud_essentialcontacts_v1::model::Contact;
138 /// use google_cloud_essentialcontacts_v1::Result;
139 /// async fn sample(
140 /// client: &EssentialContactsService, project_id: &str
141 /// ) -> Result<()> {
142 /// let response = client.create_contact()
143 /// .set_parent(format!("projects/{project_id}"))
144 /// .set_contact(
145 /// Contact::new()/* set fields */
146 /// )
147 /// .send().await?;
148 /// println!("response {:?}", response);
149 /// Ok(())
150 /// }
151 /// ```
152 pub fn create_contact(&self) -> super::builder::essential_contacts_service::CreateContact {
153 super::builder::essential_contacts_service::CreateContact::new(self.inner.clone())
154 }
155
156 /// Updates a contact.
157 /// Note: A contact's email address cannot be changed.
158 ///
159 /// # Example
160 /// ```
161 /// # use google_cloud_essentialcontacts_v1::client::EssentialContactsService;
162 /// # extern crate wkt as google_cloud_wkt;
163 /// use google_cloud_wkt::FieldMask;
164 /// use google_cloud_essentialcontacts_v1::model::Contact;
165 /// use google_cloud_essentialcontacts_v1::Result;
166 /// async fn sample(
167 /// client: &EssentialContactsService, project_id: &str, contact_id: &str
168 /// ) -> Result<()> {
169 /// let response = client.update_contact()
170 /// .set_contact(
171 /// Contact::new().set_name(format!("projects/{project_id}/contacts/{contact_id}"))/* set fields */
172 /// )
173 /// .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
174 /// .send().await?;
175 /// println!("response {:?}", response);
176 /// Ok(())
177 /// }
178 /// ```
179 pub fn update_contact(&self) -> super::builder::essential_contacts_service::UpdateContact {
180 super::builder::essential_contacts_service::UpdateContact::new(self.inner.clone())
181 }
182
183 /// Lists the contacts that have been set on a resource.
184 ///
185 /// # Example
186 /// ```
187 /// # use google_cloud_essentialcontacts_v1::client::EssentialContactsService;
188 /// use google_cloud_gax::paginator::ItemPaginator as _;
189 /// use google_cloud_essentialcontacts_v1::Result;
190 /// async fn sample(
191 /// client: &EssentialContactsService, project_id: &str
192 /// ) -> Result<()> {
193 /// let mut list = client.list_contacts()
194 /// .set_parent(format!("projects/{project_id}"))
195 /// .by_item();
196 /// while let Some(item) = list.next().await.transpose()? {
197 /// println!("{:?}", item);
198 /// }
199 /// Ok(())
200 /// }
201 /// ```
202 pub fn list_contacts(&self) -> super::builder::essential_contacts_service::ListContacts {
203 super::builder::essential_contacts_service::ListContacts::new(self.inner.clone())
204 }
205
206 /// Gets a single contact.
207 ///
208 /// # Example
209 /// ```
210 /// # use google_cloud_essentialcontacts_v1::client::EssentialContactsService;
211 /// use google_cloud_essentialcontacts_v1::Result;
212 /// async fn sample(
213 /// client: &EssentialContactsService, project_id: &str, contact_id: &str
214 /// ) -> Result<()> {
215 /// let response = client.get_contact()
216 /// .set_name(format!("projects/{project_id}/contacts/{contact_id}"))
217 /// .send().await?;
218 /// println!("response {:?}", response);
219 /// Ok(())
220 /// }
221 /// ```
222 pub fn get_contact(&self) -> super::builder::essential_contacts_service::GetContact {
223 super::builder::essential_contacts_service::GetContact::new(self.inner.clone())
224 }
225
226 /// Deletes a contact.
227 ///
228 /// # Example
229 /// ```
230 /// # use google_cloud_essentialcontacts_v1::client::EssentialContactsService;
231 /// use google_cloud_essentialcontacts_v1::Result;
232 /// async fn sample(
233 /// client: &EssentialContactsService, project_id: &str, contact_id: &str
234 /// ) -> Result<()> {
235 /// client.delete_contact()
236 /// .set_name(format!("projects/{project_id}/contacts/{contact_id}"))
237 /// .send().await?;
238 /// Ok(())
239 /// }
240 /// ```
241 pub fn delete_contact(&self) -> super::builder::essential_contacts_service::DeleteContact {
242 super::builder::essential_contacts_service::DeleteContact::new(self.inner.clone())
243 }
244
245 /// Lists all contacts for the resource that are subscribed to the
246 /// specified notification categories, including contacts inherited from
247 /// any parent resources.
248 ///
249 /// # Example
250 /// ```
251 /// # use google_cloud_essentialcontacts_v1::client::EssentialContactsService;
252 /// use google_cloud_gax::paginator::ItemPaginator as _;
253 /// use google_cloud_essentialcontacts_v1::Result;
254 /// async fn sample(
255 /// client: &EssentialContactsService
256 /// ) -> Result<()> {
257 /// let mut list = client.compute_contacts()
258 /// /* set fields */
259 /// .by_item();
260 /// while let Some(item) = list.next().await.transpose()? {
261 /// println!("{:?}", item);
262 /// }
263 /// Ok(())
264 /// }
265 /// ```
266 pub fn compute_contacts(&self) -> super::builder::essential_contacts_service::ComputeContacts {
267 super::builder::essential_contacts_service::ComputeContacts::new(self.inner.clone())
268 }
269
270 /// Allows a contact admin to send a test message to contact to verify that it
271 /// has been configured correctly.
272 ///
273 /// # Example
274 /// ```
275 /// # use google_cloud_essentialcontacts_v1::client::EssentialContactsService;
276 /// use google_cloud_essentialcontacts_v1::Result;
277 /// async fn sample(
278 /// client: &EssentialContactsService
279 /// ) -> Result<()> {
280 /// client.send_test_message()
281 /// /* set fields */
282 /// .send().await?;
283 /// Ok(())
284 /// }
285 /// ```
286 pub fn send_test_message(&self) -> super::builder::essential_contacts_service::SendTestMessage {
287 super::builder::essential_contacts_service::SendTestMessage::new(self.inner.clone())
288 }
289}