coinbase_advanced/rest/data.rs
1//! Data API endpoints.
2
3use crate::client::RestClient;
4use crate::error::Result;
5use crate::models::ApiKeyPermissions;
6
7/// API for retrieving data about the current API key.
8///
9/// This API provides endpoints for querying API key permissions and capabilities.
10pub struct DataApi<'a> {
11 client: &'a RestClient,
12}
13
14impl<'a> DataApi<'a> {
15 /// Create a new Data API instance.
16 pub(crate) fn new(client: &'a RestClient) -> Self {
17 Self { client }
18 }
19
20 /// Get the permissions for the current API key.
21 ///
22 /// This returns information about what actions the API key is authorized to perform.
23 ///
24 /// # Example
25 ///
26 /// ```no_run
27 /// # use coinbase_advanced::{RestClient, Credentials};
28 /// # async fn example() -> coinbase_advanced::Result<()> {
29 /// let client = RestClient::builder()
30 /// .credentials(Credentials::from_env()?)
31 /// .build()?;
32 ///
33 /// let permissions = client.data().get_key_permissions().await?;
34 /// println!("Can view: {}", permissions.can_view);
35 /// println!("Can trade: {}", permissions.can_trade);
36 /// println!("Can transfer: {}", permissions.can_transfer);
37 /// # Ok(())
38 /// # }
39 /// ```
40 pub async fn get_key_permissions(&self) -> Result<ApiKeyPermissions> {
41 self.client.get("/key_permissions").await
42 }
43}