dfns-sdk-rust 0.2.0

Dfns API SDK for Rust
Documentation
// Code generated by rust-sdk-generator. DO NOT EDIT.

pub mod delegated;
pub mod types;

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

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

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

    /// Retrieves all Fee Sponsors configured in your organization.
    pub async fn list_fee_sponsors(
        &self,
        query: Option<ListFeeSponsorsQuery>,
    ) -> Result<ListFeeSponsorsResponse, crate::error::Error> {
        let mut path = String::from("/fee-sponsors");
        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::<ListFeeSponsorsResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Creates a new `FeeSponsor` associated with a sponsor wallet. Returns a new fee sponsor entity with the `id` to be used when making a transfer.
    pub async fn create_fee_sponsor(
        &self,
        body: CreateFeeSponsorRequest,
    ) -> Result<CreateFeeSponsorResponse, crate::error::Error> {
        let path = String::from("/fee-sponsors");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateFeeSponsorResponse>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }

    /// Retrieve a Fee Sponsor information by ID.
    pub async fn get_fee_sponsor(
        &self,
        fee_sponsor_id: String,
    ) -> Result<GetFeeSponsorResponse, crate::error::Error> {
        let path = format!("/fee-sponsors/{}", urlencoding::encode(&fee_sponsor_id));
        self.client
            .request::<GetFeeSponsorResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Delete a Fee Sponsor. This action is irreversible. The fee sponsor won't be able to be used anymore when making a transfer.
    pub async fn delete_fee_sponsor(
        &self,
        fee_sponsor_id: String,
    ) -> Result<DeleteFeeSponsorResponse, crate::error::Error> {
        let path = format!("/fee-sponsors/{}", urlencoding::encode(&fee_sponsor_id));
        self.client
            .request::<DeleteFeeSponsorResponse>(reqwest::Method::DELETE, &path, None, true)
            .await
    }

    /// Deactivate a Fee Sponsor: The fee sponsor won't be able to be used anymore when making a transfer.
    pub async fn deactivate_fee_sponsor(
        &self,
        fee_sponsor_id: String,
    ) -> Result<DeactivateFeeSponsorResponse, crate::error::Error> {
        let path = format!(
            "/fee-sponsors/{}/deactivate",
            urlencoding::encode(&fee_sponsor_id)
        );
        self.client
            .request::<DeactivateFeeSponsorResponse>(reqwest::Method::PUT, &path, None, true)
            .await
    }

    /// Activate a Fee Sponsor: The fee sponsor can be used when making a transfer.
    pub async fn activate_fee_sponsor(
        &self,
        fee_sponsor_id: String,
    ) -> Result<ActivateFeeSponsorResponse, crate::error::Error> {
        let path = format!(
            "/fee-sponsors/{}/activate",
            urlencoding::encode(&fee_sponsor_id)
        );
        self.client
            .request::<ActivateFeeSponsorResponse>(reqwest::Method::PUT, &path, None, true)
            .await
    }

    /// Retrieves all fees paid by the specific Fee Sponsor.
    pub async fn list_sponsored_fees(
        &self,
        fee_sponsor_id: String,
        query: Option<ListSponsoredFeesQuery>,
    ) -> Result<ListSponsoredFeesResponse, crate::error::Error> {
        let mut path = format!(
            "/fee-sponsors/{}/fees",
            urlencoding::encode(&fee_sponsor_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::<ListSponsoredFeesResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }
}