google_developers_knowledge_v1/client.rs
1// Copyright 2026 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 Developer Knowledge API.
22///
23/// # Example
24/// ```
25/// # use google_developers_knowledge_v1::client::DeveloperKnowledge;
26/// async fn sample(
27/// document_id: &str,
28/// ) -> anyhow::Result<()> {
29/// let client = DeveloperKnowledge::builder().build().await?;
30/// let response = client.get_document()
31/// .set_name(format!("documents/{document_id}"))
32/// .send().await?;
33/// println!("response {:?}", response);
34/// Ok(())
35/// }
36/// ```
37///
38/// # Service Description
39///
40/// The Developer Knowledge API provides programmatic access to Google's public
41/// developer documentation, enabling you to integrate this knowledge base into
42/// your own applications and workflows.
43///
44/// The API is designed to be the canonical source for machine-readable access to
45/// Google's developer documentation.
46///
47/// A typical use case is to first use
48/// [DeveloperKnowledge.SearchDocumentChunks][google.developers.knowledge.v1.DeveloperKnowledge.SearchDocumentChunks]
49/// to find relevant page URIs based on a query, and then use
50/// [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument]
51/// or
52/// [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments]
53/// to fetch the full content of the top results.
54///
55/// All document content is provided in Markdown format.
56///
57/// [google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments]: crate::client::DeveloperKnowledge::batch_get_documents
58/// [google.developers.knowledge.v1.DeveloperKnowledge.GetDocument]: crate::client::DeveloperKnowledge::get_document
59/// [google.developers.knowledge.v1.DeveloperKnowledge.SearchDocumentChunks]: crate::client::DeveloperKnowledge::search_document_chunks
60///
61/// # Configuration
62///
63/// To configure `DeveloperKnowledge` use the `with_*` methods in the type returned
64/// by [builder()][DeveloperKnowledge::builder]. The default configuration should
65/// work for most applications. Common configuration changes include
66///
67/// * [with_endpoint()]: by default this client uses the global default endpoint
68/// (`https://developerknowledge.googleapis.com`). Applications using regional
69/// endpoints or running in restricted networks (e.g. a network configured
70/// with [Private Google Access with VPC Service Controls]) may want to
71/// override this default.
72/// * [with_credentials()]: by default this client uses
73/// [Application Default Credentials]. Applications using custom
74/// authentication may need to override this default.
75///
76/// [with_endpoint()]: super::builder::developer_knowledge::ClientBuilder::with_endpoint
77/// [with_credentials()]: super::builder::developer_knowledge::ClientBuilder::with_credentials
78/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
79/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
80///
81/// # Pooling and Cloning
82///
83/// `DeveloperKnowledge` holds a connection pool internally, it is advised to
84/// create one and reuse it. You do not need to wrap `DeveloperKnowledge` in
85/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
86/// already uses an `Arc` internally.
87#[derive(Clone, Debug)]
88pub struct DeveloperKnowledge {
89 inner: std::sync::Arc<dyn super::stub::dynamic::DeveloperKnowledge>,
90}
91
92impl DeveloperKnowledge {
93 /// Returns a builder for [DeveloperKnowledge].
94 ///
95 /// ```
96 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
97 /// # use google_developers_knowledge_v1::client::DeveloperKnowledge;
98 /// let client = DeveloperKnowledge::builder().build().await?;
99 /// # Ok(()) }
100 /// ```
101 pub fn builder() -> super::builder::developer_knowledge::ClientBuilder {
102 crate::new_client_builder(super::builder::developer_knowledge::client::Factory)
103 }
104
105 /// Creates a new client from the provided stub.
106 ///
107 /// The most common case for calling this function is in tests mocking the
108 /// client's behavior.
109 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
110 where
111 T: super::stub::DeveloperKnowledge + 'static,
112 {
113 Self { inner: stub.into() }
114 }
115
116 pub(crate) async fn new(
117 config: gaxi::options::ClientConfig,
118 ) -> crate::ClientBuilderResult<Self> {
119 let inner = Self::build_inner(config).await?;
120 Ok(Self { inner })
121 }
122
123 async fn build_inner(
124 conf: gaxi::options::ClientConfig,
125 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::DeveloperKnowledge>>
126 {
127 if gaxi::options::tracing_enabled(&conf) {
128 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
129 }
130 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
131 }
132
133 async fn build_transport(
134 conf: gaxi::options::ClientConfig,
135 ) -> crate::ClientBuilderResult<impl super::stub::DeveloperKnowledge> {
136 super::transport::DeveloperKnowledge::new(conf).await
137 }
138
139 async fn build_with_tracing(
140 conf: gaxi::options::ClientConfig,
141 ) -> crate::ClientBuilderResult<impl super::stub::DeveloperKnowledge> {
142 Self::build_transport(conf)
143 .await
144 .map(super::tracing::DeveloperKnowledge::new)
145 }
146
147 /// Searches for developer knowledge across Google's developer documentation.
148 /// Returns [DocumentChunk][google.developers.knowledge.v1.DocumentChunk]s
149 /// based on the user's query. There may be many chunks from the same
150 /// [Document][google.developers.knowledge.v1.Document]. To retrieve full
151 /// documents, use
152 /// [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument]
153 /// or
154 /// [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments]
155 /// with the
156 /// [DocumentChunk.parent][google.developers.knowledge.v1.DocumentChunk.parent]
157 /// returned in the
158 /// [SearchDocumentChunksResponse.results][google.developers.knowledge.v1.SearchDocumentChunksResponse.results].
159 ///
160 /// [google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments]: crate::client::DeveloperKnowledge::batch_get_documents
161 /// [google.developers.knowledge.v1.DeveloperKnowledge.GetDocument]: crate::client::DeveloperKnowledge::get_document
162 /// [google.developers.knowledge.v1.Document]: crate::model::Document
163 /// [google.developers.knowledge.v1.DocumentChunk]: crate::model::DocumentChunk
164 /// [google.developers.knowledge.v1.DocumentChunk.parent]: crate::model::DocumentChunk::parent
165 /// [google.developers.knowledge.v1.SearchDocumentChunksResponse.results]: crate::model::SearchDocumentChunksResponse::results
166 ///
167 /// # Example
168 /// ```
169 /// # use google_developers_knowledge_v1::client::DeveloperKnowledge;
170 /// use google_cloud_gax::paginator::ItemPaginator as _;
171 /// use google_developers_knowledge_v1::Result;
172 /// async fn sample(
173 /// client: &DeveloperKnowledge
174 /// ) -> Result<()> {
175 /// let mut list = client.search_document_chunks()
176 /// /* set fields */
177 /// .by_item();
178 /// while let Some(item) = list.next().await.transpose()? {
179 /// println!("{:?}", item);
180 /// }
181 /// Ok(())
182 /// }
183 /// ```
184 pub fn search_document_chunks(
185 &self,
186 ) -> super::builder::developer_knowledge::SearchDocumentChunks {
187 super::builder::developer_knowledge::SearchDocumentChunks::new(self.inner.clone())
188 }
189
190 /// Retrieves a single document with its full Markdown content.
191 ///
192 /// # Example
193 /// ```
194 /// # use google_developers_knowledge_v1::client::DeveloperKnowledge;
195 /// use google_developers_knowledge_v1::Result;
196 /// async fn sample(
197 /// client: &DeveloperKnowledge, document_id: &str
198 /// ) -> Result<()> {
199 /// let response = client.get_document()
200 /// .set_name(format!("documents/{document_id}"))
201 /// .send().await?;
202 /// println!("response {:?}", response);
203 /// Ok(())
204 /// }
205 /// ```
206 pub fn get_document(&self) -> super::builder::developer_knowledge::GetDocument {
207 super::builder::developer_knowledge::GetDocument::new(self.inner.clone())
208 }
209
210 /// Retrieves multiple documents, each with its full Markdown content.
211 ///
212 /// # Example
213 /// ```
214 /// # use google_developers_knowledge_v1::client::DeveloperKnowledge;
215 /// use google_developers_knowledge_v1::Result;
216 /// async fn sample(
217 /// client: &DeveloperKnowledge
218 /// ) -> Result<()> {
219 /// let response = client.batch_get_documents()
220 /// /* set fields */
221 /// .send().await?;
222 /// println!("response {:?}", response);
223 /// Ok(())
224 /// }
225 /// ```
226 pub fn batch_get_documents(&self) -> super::builder::developer_knowledge::BatchGetDocuments {
227 super::builder::developer_knowledge::BatchGetDocuments::new(self.inner.clone())
228 }
229
230 /// Answers a query using grounded generation.
231 ///
232 /// # Example
233 /// ```
234 /// # use google_developers_knowledge_v1::client::DeveloperKnowledge;
235 /// use google_developers_knowledge_v1::Result;
236 /// async fn sample(
237 /// client: &DeveloperKnowledge
238 /// ) -> Result<()> {
239 /// let response = client.answer_query()
240 /// /* set fields */
241 /// .send().await?;
242 /// println!("response {:?}", response);
243 /// Ok(())
244 /// }
245 /// ```
246 pub fn answer_query(&self) -> super::builder::developer_knowledge::AnswerQuery {
247 super::builder::developer_knowledge::AnswerQuery::new(self.inner.clone())
248 }
249}