dfns-sdk-rust 0.1.0

Dfns API SDK for Rust (generated client + hand-written core)
Documentation
// Code generated by rust-sdk-generator. DO NOT EDIT.

pub mod types;

#[allow(unused_imports)]
use types::*;

/// Client for allocations operations.
#[derive(Clone)]
pub struct AllocationsClient {
    client: crate::client::Client,
}

impl AllocationsClient {
    pub fn new(client: crate::client::Client) -> Self {
        AllocationsClient { client }
    }

    /// Lists the allocations of your organization.
    pub async fn list_allocations(
        &self,
        query: Option<ListAllocationsQuery>,
    ) -> Result<ListAllocationsResponse, crate::error::Error> {
        let mut path = String::from("/allocations");
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            if let Some(v) = &query.limit {
                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.pagination_token {
                q.push(format!(
                    "paginationToken={}",
                    urlencoding::encode(&v.to_string())
                ));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<ListAllocationsResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Create a new allocation.
    pub async fn create_allocation(
        &self,
        body: CreateAllocationRequest,
    ) -> Result<CreateAllocationResponse, crate::error::Error> {
        let path = String::from("/allocations");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateAllocationResponse>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }

    /// Retrieve the list of actions for a specific allocation.
    pub async fn list_allocation_actions(
        &self,
        allocation_id: String,
        query: Option<ListAllocationActionsQuery>,
    ) -> Result<ListAllocationActionsResponse, crate::error::Error> {
        let mut path = format!(
            "/allocations/{}/actions",
            urlencoding::encode(&allocation_id)
        );
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            if let Some(v) = &query.limit {
                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.pagination_token {
                q.push(format!(
                    "paginationToken={}",
                    urlencoding::encode(&v.to_string())
                ));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<ListAllocationActionsResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Create a new action for an existing allocation.
    pub async fn create_allocation_action(
        &self,
        allocation_id: String,
        body: CreateAllocationActionRequest,
    ) -> Result<CreateAllocationActionResponse, crate::error::Error> {
        let path = format!(
            "/allocations/{}/actions",
            urlencoding::encode(&allocation_id)
        );
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateAllocationActionResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                true,
            )
            .await
    }

    /// Retrieve the details of a specific allocation.
    pub async fn get_allocation(
        &self,
        allocation_id: String,
    ) -> Result<GetAllocationResponse, crate::error::Error> {
        let path = format!("/allocations/{}", urlencoding::encode(&allocation_id));
        self.client
            .request::<GetAllocationResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Retrieve the current reward rate (APY) for each supported allocation protocol.
    pub async fn get_allocations_info(
        &self,
    ) -> Result<GetAllocationsInfoResponse, crate::error::Error> {
        let path = String::from("/allocations/info");
        self.client
            .request::<GetAllocationsInfoResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }
}