spacetraders-client 0.1.0

Async Rust client for the SpaceTraders API v2 with priority-aware rate limiting and retry
Documentation
use std::num::NonZeroU64;

use crate::client::StClient;
use crate::client::{ClientError, RequestPriority};
use crate::types;

impl StClient {
    pub async fn get_contracts(
        &self,
        limit: Option<NonZeroU64>,
        page: Option<NonZeroU64>,
    ) -> Result<types::GetContractsResponse, ClientError> {
        self.get_contracts_with_priority(limit, page, RequestPriority::Normal)
            .await
    }

    pub async fn get_contracts_with_priority(
        &self,
        limit: Option<NonZeroU64>,
        page: Option<NonZeroU64>,
        priority: RequestPriority,
    ) -> Result<types::GetContractsResponse, ClientError> {
        self.send("get_contracts", priority, || {
            self.inner.get_contracts(limit, page)
        })
        .await
    }

    pub async fn get_contract(
        &self,
        contract_id: &str,
    ) -> Result<types::GetContractResponse, ClientError> {
        self.get_contract_with_priority(contract_id, RequestPriority::Normal)
            .await
    }

    pub async fn get_contract_with_priority(
        &self,
        contract_id: &str,
        priority: RequestPriority,
    ) -> Result<types::GetContractResponse, ClientError> {
        self.send("get_contract", priority, || {
            self.inner.get_contract(contract_id)
        })
        .await
    }

    pub async fn accept_contract(
        &self,
        contract_id: &str,
    ) -> Result<types::AcceptContractResponse, ClientError> {
        self.accept_contract_with_priority(contract_id, RequestPriority::Normal)
            .await
    }

    pub async fn accept_contract_with_priority(
        &self,
        contract_id: &str,
        priority: RequestPriority,
    ) -> Result<types::AcceptContractResponse, ClientError> {
        self.send_mutating("accept_contract", priority, || {
            self.inner.accept_contract(contract_id)
        })
        .await
    }

    pub async fn deliver_contract(
        &self,
        contract_id: &str,
        ship_symbol: &str,
        trade_symbol: &str,
        units: NonZeroU64,
    ) -> Result<types::DeliverContractResponse, ClientError> {
        self.deliver_contract_with_priority(
            contract_id,
            ship_symbol,
            trade_symbol,
            units,
            RequestPriority::Normal,
        )
        .await
    }

    pub async fn deliver_contract_with_priority(
        &self,
        contract_id: &str,
        ship_symbol: &str,
        trade_symbol: &str,
        units: NonZeroU64,
        priority: RequestPriority,
    ) -> Result<types::DeliverContractResponse, ClientError> {
        let body = types::DeliverContractBody {
            ship_symbol: ship_symbol.to_string(),
            trade_symbol: trade_symbol.to_string(),
            units,
        };
        self.send_mutating("deliver_contract", priority, || {
            self.inner.deliver_contract(contract_id, &body)
        })
        .await
    }

    pub async fn fulfill_contract(
        &self,
        contract_id: &str,
    ) -> Result<types::FulfillContractResponse, ClientError> {
        self.fulfill_contract_with_priority(contract_id, RequestPriority::Normal)
            .await
    }

    pub async fn fulfill_contract_with_priority(
        &self,
        contract_id: &str,
        priority: RequestPriority,
    ) -> Result<types::FulfillContractResponse, ClientError> {
        self.send_mutating("fulfill_contract", priority, || {
            self.inner.fulfill_contract(contract_id)
        })
        .await
    }
}