Skip to main content

everymap_providers_mapbox/
client.rs

1use everymap_core::auth::AuthProvider;
2use everymap_core::error::EveryMapResult;
3use std::sync::Arc;
4
5const PROVIDER_NAME: &str = "mapbox";
6
7/// The shared HTTP client for MapBox APIs.
8///
9/// Delegates to `everymap_core::client::ProviderClient` for common
10/// request/response logic. Each domain module constructs its own
11/// base URL per the MapBox API specification.
12pub struct MapBoxClient {
13    inner: everymap_core::client::ProviderClient,
14}
15
16impl MapBoxClient {
17    /// Creates a new `MapBoxClient` with the given authentication provider.
18    pub fn new(auth_provider: Arc<dyn AuthProvider>) -> Self {
19        Self {
20            inner: everymap_core::client::ProviderClient::new(auth_provider, PROVIDER_NAME),
21        }
22    }
23
24    /// Creates a `MapBoxClient` with a custom `reqwest::Client` configuration.
25    pub fn with_client_builder(
26        builder: reqwest::ClientBuilder,
27        auth_provider: Arc<dyn AuthProvider>,
28    ) -> EveryMapResult<Self> {
29        Ok(Self {
30            inner: everymap_core::client::ProviderClient::with_client_builder(
31                builder,
32                auth_provider,
33                PROVIDER_NAME,
34            )?,
35        })
36    }
37
38    /// Enable or disable verbose output.
39    pub fn set_verbose(&mut self, verbose: bool) {
40        self.inner.set_verbose(verbose);
41    }
42
43    /// Whether verbose mode is enabled.
44    pub fn is_verbose(&self) -> bool {
45        self.inner.is_verbose()
46    }
47
48    /// Builds a request to the given full URL with the specified HTTP method.
49    pub fn build_request(&self, method: reqwest::Method, url: &str) -> reqwest::RequestBuilder {
50        self.inner.build_request(method, url)
51    }
52
53    /// Sends a request, applying authentication first.
54    pub async fn request(
55        &self,
56        builder: reqwest::RequestBuilder,
57    ) -> EveryMapResult<reqwest::Response> {
58        self.inner.request(builder).await
59    }
60
61    /// Sends a request and deserializes the JSON response into `T`.
62    pub async fn request_json<T: serde::de::DeserializeOwned>(
63        &self,
64        builder: reqwest::RequestBuilder,
65    ) -> EveryMapResult<T> {
66        self.inner.request_json(builder).await
67    }
68}