google-cloud-locationfinder-v1 1.10.0

Google Cloud Client Libraries for Rust - Cloud Location Finder API
Documentation
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.

#[allow(unused_imports)]
use crate::Error;
use crate::Result;

/// Implements [CloudLocationFinder](super::stub::CloudLocationFinder) using a [gaxi::http::ReqwestClient].
#[derive(Clone)]
pub struct CloudLocationFinder {
    inner: gaxi::http::ReqwestClient,
}

impl std::fmt::Debug for CloudLocationFinder {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
        f.debug_struct("CloudLocationFinder")
            .field("inner", &self.inner)
            .finish()
    }
}

impl CloudLocationFinder {
    pub async fn new(config: gaxi::options::ClientConfig) -> crate::ClientBuilderResult<Self> {
        let tracing_is_enabled = gaxi::options::tracing_enabled(&config);
        let inner = gaxi::http::ReqwestClient::new(config, crate::DEFAULT_HOST).await?;
        let inner = if tracing_is_enabled {
            inner.with_instrumentation(&super::tracing::info::INSTRUMENTATION_CLIENT_INFO)
        } else {
            inner
        };
        Ok(Self { inner })
    }
}

impl super::stub::CloudLocationFinder for CloudLocationFinder {
    async fn list_cloud_locations(
        &self,
        req: crate::model::ListCloudLocationsRequest,
        options: crate::RequestOptions,
    ) -> Result<crate::Response<crate::model::ListCloudLocationsResponse>> {
        use gaxi::http::reqwest::{HeaderValue, Method};
        use gaxi::path_parameter::PathMismatchBuilder;
        use gaxi::path_parameter::try_match;
        use gaxi::routing_parameter::Segment;
        use google_cloud_gax::error::binding::BindingError;
        let (builder, method, _path_template, _resource_name) = None
            .or_else(|| {
                let var_parent = try_match(
                    Some(&req).map(|m| &m.parent).map(|s| s.as_str()),
                    &[
                        Segment::Literal("projects/"),
                        Segment::SingleWildcard,
                        Segment::Literal("/locations/"),
                        Segment::SingleWildcard,
                    ],
                )?;
                let path = format!("/v1/{}/cloudLocations", var_parent,);
                let path_template = "/v1/{parent}/cloudLocations";

                let resource_name = format!("//cloudlocationfinder.googleapis.com/{}", var_parent,);
                let builder = self.inner.builder(Method::GET, path);
                let builder = builder.query(&[("pageSize", &req.page_size)]);
                let builder = builder.query(&[("pageToken", &req.page_token)]);
                let builder = builder.query(&[("filter", &req.filter)]);
                let builder = Ok(builder);
                Some(builder.map(|b| (b, Method::GET, path_template, resource_name)))
            })
            .ok_or_else(|| {
                let mut paths = Vec::new();
                {
                    let builder = PathMismatchBuilder::default();
                    let builder = builder.maybe_add(
                        Some(&req).map(|m| &m.parent).map(|s| s.as_str()),
                        &[
                            Segment::Literal("projects/"),
                            Segment::SingleWildcard,
                            Segment::Literal("/locations/"),
                            Segment::SingleWildcard,
                        ],
                        "parent",
                        "projects/*/locations/*",
                    );
                    paths.push(builder.build());
                }
                google_cloud_gax::error::Error::binding(BindingError { paths })
            })??;
        if let Some(recorder) = gaxi::observability::RequestRecorder::current() {
            recorder.on_client_request(
                gaxi::observability::ClientRequestAttributes::default()
                    .set_rpc_method(
                        "google.cloud.locationfinder.v1.CloudLocationFinder/ListCloudLocations",
                    )
                    .set_url_template(_path_template)
                    .set_resource_name(_resource_name),
            );
        }
        let options = google_cloud_gax::options::internal::set_default_idempotency(
            options,
            gaxi::http::default_idempotency(&method),
        );
        let builder = builder.query(&[("$alt", "json;enum-encoding=int")]).header(
            "x-goog-api-client",
            HeaderValue::from_static(&crate::info::X_GOOG_API_CLIENT_HEADER),
        );
        let body = gaxi::http::handle_empty(None::<gaxi::http::NoBody>, &method);
        self.inner.execute(builder, body, options).await
    }

    async fn get_cloud_location(
        &self,
        req: crate::model::GetCloudLocationRequest,
        options: crate::RequestOptions,
    ) -> Result<crate::Response<crate::model::CloudLocation>> {
        use gaxi::http::reqwest::{HeaderValue, Method};
        use gaxi::path_parameter::PathMismatchBuilder;
        use gaxi::path_parameter::try_match;
        use gaxi::routing_parameter::Segment;
        use google_cloud_gax::error::binding::BindingError;
        let (builder, method, _path_template, _resource_name) = None
            .or_else(|| {
                let var_name = try_match(
                    Some(&req).map(|m| &m.name).map(|s| s.as_str()),
                    &[
                        Segment::Literal("projects/"),
                        Segment::SingleWildcard,
                        Segment::Literal("/locations/"),
                        Segment::SingleWildcard,
                        Segment::Literal("/cloudLocations/"),
                        Segment::SingleWildcard,
                    ],
                )?;
                let path = format!("/v1/{}", var_name,);
                let path_template = "/v1/{name}";

                let resource_name = format!("//cloudlocationfinder.googleapis.com/{}", var_name,);
                let builder = self.inner.builder(Method::GET, path);
                let builder = Ok(builder);
                Some(builder.map(|b| (b, Method::GET, path_template, resource_name)))
            })
            .ok_or_else(|| {
                let mut paths = Vec::new();
                {
                    let builder = PathMismatchBuilder::default();
                    let builder = builder.maybe_add(
                        Some(&req).map(|m| &m.name).map(|s| s.as_str()),
                        &[
                            Segment::Literal("projects/"),
                            Segment::SingleWildcard,
                            Segment::Literal("/locations/"),
                            Segment::SingleWildcard,
                            Segment::Literal("/cloudLocations/"),
                            Segment::SingleWildcard,
                        ],
                        "name",
                        "projects/*/locations/*/cloudLocations/*",
                    );
                    paths.push(builder.build());
                }
                google_cloud_gax::error::Error::binding(BindingError { paths })
            })??;
        if let Some(recorder) = gaxi::observability::RequestRecorder::current() {
            recorder.on_client_request(
                gaxi::observability::ClientRequestAttributes::default()
                    .set_rpc_method(
                        "google.cloud.locationfinder.v1.CloudLocationFinder/GetCloudLocation",
                    )
                    .set_url_template(_path_template)
                    .set_resource_name(_resource_name),
            );
        }
        let options = google_cloud_gax::options::internal::set_default_idempotency(
            options,
            gaxi::http::default_idempotency(&method),
        );
        let builder = builder.query(&[("$alt", "json;enum-encoding=int")]).header(
            "x-goog-api-client",
            HeaderValue::from_static(&crate::info::X_GOOG_API_CLIENT_HEADER),
        );
        let body = gaxi::http::handle_empty(None::<gaxi::http::NoBody>, &method);
        self.inner.execute(builder, body, options).await
    }

    async fn search_cloud_locations(
        &self,
        req: crate::model::SearchCloudLocationsRequest,
        options: crate::RequestOptions,
    ) -> Result<crate::Response<crate::model::SearchCloudLocationsResponse>> {
        use gaxi::http::reqwest::{HeaderValue, Method};
        use gaxi::path_parameter::PathMismatchBuilder;
        use gaxi::path_parameter::try_match;
        use gaxi::routing_parameter::Segment;
        use google_cloud_gax::error::binding::BindingError;
        let (builder, method, _path_template, _resource_name) = None
            .or_else(|| {
                let var_parent = try_match(
                    Some(&req).map(|m| &m.parent).map(|s| s.as_str()),
                    &[
                        Segment::Literal("projects/"),
                        Segment::SingleWildcard,
                        Segment::Literal("/locations/"),
                        Segment::SingleWildcard,
                    ],
                )?;
                let path = format!("/v1/{}/cloudLocations:search", var_parent,);
                let path_template = "/v1/{parent}/cloudLocations:search";

                let resource_name = format!("//cloudlocationfinder.googleapis.com/{}", var_parent,);
                let builder = self.inner.builder(Method::GET, path);
                let builder = builder.query(&[("sourceCloudLocation", &req.source_cloud_location)]);
                let builder = builder.query(&[("pageSize", &req.page_size)]);
                let builder = builder.query(&[("pageToken", &req.page_token)]);
                let builder = builder.query(&[("query", &req.query)]);
                let builder = Ok(builder);
                Some(builder.map(|b| (b, Method::GET, path_template, resource_name)))
            })
            .ok_or_else(|| {
                let mut paths = Vec::new();
                {
                    let builder = PathMismatchBuilder::default();
                    let builder = builder.maybe_add(
                        Some(&req).map(|m| &m.parent).map(|s| s.as_str()),
                        &[
                            Segment::Literal("projects/"),
                            Segment::SingleWildcard,
                            Segment::Literal("/locations/"),
                            Segment::SingleWildcard,
                        ],
                        "parent",
                        "projects/*/locations/*",
                    );
                    paths.push(builder.build());
                }
                google_cloud_gax::error::Error::binding(BindingError { paths })
            })??;
        if let Some(recorder) = gaxi::observability::RequestRecorder::current() {
            recorder.on_client_request(
                gaxi::observability::ClientRequestAttributes::default()
                    .set_rpc_method(
                        "google.cloud.locationfinder.v1.CloudLocationFinder/SearchCloudLocations",
                    )
                    .set_url_template(_path_template)
                    .set_resource_name(_resource_name),
            );
        }
        let options = google_cloud_gax::options::internal::set_default_idempotency(
            options,
            gaxi::http::default_idempotency(&method),
        );
        let builder = builder.query(&[("$alt", "json;enum-encoding=int")]).header(
            "x-goog-api-client",
            HeaderValue::from_static(&crate::info::X_GOOG_API_CLIENT_HEADER),
        );
        let body = gaxi::http::handle_empty(None::<gaxi::http::NoBody>, &method);
        self.inner.execute(builder, body, options).await
    }

    async fn list_locations(
        &self,
        req: google_cloud_location::model::ListLocationsRequest,
        options: crate::RequestOptions,
    ) -> Result<crate::Response<google_cloud_location::model::ListLocationsResponse>> {
        use gaxi::http::reqwest::{HeaderValue, Method};
        use gaxi::path_parameter::PathMismatchBuilder;
        use gaxi::path_parameter::try_match;
        use gaxi::routing_parameter::Segment;
        use google_cloud_gax::error::binding::BindingError;
        let (builder, method, _path_template) = None
            .or_else(|| {
                let var_name = try_match(
                    Some(&req).map(|m| &m.name).map(|s| s.as_str()),
                    &[Segment::Literal("projects/"), Segment::SingleWildcard],
                )?;
                let path = format!("/v1/{}/locations", var_name,);
                let path_template = "/v1/{name}/locations";

                let builder = self.inner.builder(Method::GET, path);
                let builder = builder.query(&[("filter", &req.filter)]);
                let builder = builder.query(&[("pageSize", &req.page_size)]);
                let builder = builder.query(&[("pageToken", &req.page_token)]);
                let builder = Ok(builder);
                Some(builder.map(|b| (b, Method::GET, path_template)))
            })
            .ok_or_else(|| {
                let mut paths = Vec::new();
                {
                    let builder = PathMismatchBuilder::default();
                    let builder = builder.maybe_add(
                        Some(&req).map(|m| &m.name).map(|s| s.as_str()),
                        &[Segment::Literal("projects/"), Segment::SingleWildcard],
                        "name",
                        "projects/*",
                    );
                    paths.push(builder.build());
                }
                google_cloud_gax::error::Error::binding(BindingError { paths })
            })??;
        if let Some(recorder) = gaxi::observability::RequestRecorder::current() {
            recorder.on_client_request(
                gaxi::observability::ClientRequestAttributes::default()
                    .set_rpc_method("google.cloud.location.Locations/ListLocations")
                    .set_url_template(_path_template),
            );
        }
        let options = google_cloud_gax::options::internal::set_default_idempotency(
            options,
            gaxi::http::default_idempotency(&method),
        );
        let builder = builder.query(&[("$alt", "json;enum-encoding=int")]).header(
            "x-goog-api-client",
            HeaderValue::from_static(&crate::info::X_GOOG_API_CLIENT_HEADER),
        );
        let body = gaxi::http::handle_empty(None::<gaxi::http::NoBody>, &method);
        self.inner.execute(builder, body, options).await
    }

    async fn get_location(
        &self,
        req: google_cloud_location::model::GetLocationRequest,
        options: crate::RequestOptions,
    ) -> Result<crate::Response<google_cloud_location::model::Location>> {
        use gaxi::http::reqwest::{HeaderValue, Method};
        use gaxi::path_parameter::PathMismatchBuilder;
        use gaxi::path_parameter::try_match;
        use gaxi::routing_parameter::Segment;
        use google_cloud_gax::error::binding::BindingError;
        let (builder, method, _path_template) = None
            .or_else(|| {
                let var_name = try_match(
                    Some(&req).map(|m| &m.name).map(|s| s.as_str()),
                    &[
                        Segment::Literal("projects/"),
                        Segment::SingleWildcard,
                        Segment::Literal("/locations/"),
                        Segment::SingleWildcard,
                    ],
                )?;
                let path = format!("/v1/{}", var_name,);
                let path_template = "/v1/{name}";

                let builder = self.inner.builder(Method::GET, path);
                let builder = Ok(builder);
                Some(builder.map(|b| (b, Method::GET, path_template)))
            })
            .ok_or_else(|| {
                let mut paths = Vec::new();
                {
                    let builder = PathMismatchBuilder::default();
                    let builder = builder.maybe_add(
                        Some(&req).map(|m| &m.name).map(|s| s.as_str()),
                        &[
                            Segment::Literal("projects/"),
                            Segment::SingleWildcard,
                            Segment::Literal("/locations/"),
                            Segment::SingleWildcard,
                        ],
                        "name",
                        "projects/*/locations/*",
                    );
                    paths.push(builder.build());
                }
                google_cloud_gax::error::Error::binding(BindingError { paths })
            })??;
        if let Some(recorder) = gaxi::observability::RequestRecorder::current() {
            recorder.on_client_request(
                gaxi::observability::ClientRequestAttributes::default()
                    .set_rpc_method("google.cloud.location.Locations/GetLocation")
                    .set_url_template(_path_template),
            );
        }
        let options = google_cloud_gax::options::internal::set_default_idempotency(
            options,
            gaxi::http::default_idempotency(&method),
        );
        let builder = builder.query(&[("$alt", "json;enum-encoding=int")]).header(
            "x-goog-api-client",
            HeaderValue::from_static(&crate::info::X_GOOG_API_CLIENT_HEADER),
        );
        let body = gaxi::http::handle_empty(None::<gaxi::http::NoBody>, &method);
        self.inner.execute(builder, body, options).await
    }
}