spacetraders-client 0.1.0

Async Rust client for the SpaceTraders API v2 with priority-aware rate limiting and retry
Documentation
use crate::client::StClient;
use crate::client::{ClientError, RequestPriority};
use crate::types;

impl StClient {
    pub async fn get_mounts(
        &self,
        ship_symbol: &str,
    ) -> Result<types::GetMounts200Response, ClientError> {
        self.get_mounts_with_priority(ship_symbol, RequestPriority::Normal)
            .await
    }

    pub async fn get_mounts_with_priority(
        &self,
        ship_symbol: &str,
        priority: RequestPriority,
    ) -> Result<types::GetMounts200Response, ClientError> {
        self.send("get_mounts", priority, || {
            self.inner.get_mounts(ship_symbol)
        })
        .await
    }

    pub async fn install_mount(
        &self,
        ship_symbol: &str,
        symbol: &str,
    ) -> Result<types::InstallMount201Response, ClientError> {
        self.install_mount_with_priority(ship_symbol, symbol, RequestPriority::Normal)
            .await
    }

    pub async fn install_mount_with_priority(
        &self,
        ship_symbol: &str,
        symbol: &str,
        priority: RequestPriority,
    ) -> Result<types::InstallMount201Response, ClientError> {
        let body = types::InstallMountRequest {
            symbol: symbol
                .parse()
                .map_err(|e| ClientError::Api(format!("invalid mount symbol: {e:?}")))?,
        };
        self.send_mutating("install_mount", priority, || {
            self.inner.install_mount(ship_symbol, &body)
        })
        .await
    }

    pub async fn remove_mount(
        &self,
        ship_symbol: &str,
        symbol: &str,
    ) -> Result<types::RemoveMount201Response, ClientError> {
        self.remove_mount_with_priority(ship_symbol, symbol, RequestPriority::Normal)
            .await
    }

    pub async fn remove_mount_with_priority(
        &self,
        ship_symbol: &str,
        symbol: &str,
        priority: RequestPriority,
    ) -> Result<types::RemoveMount201Response, ClientError> {
        let body = types::RemoveMountRequest {
            symbol: symbol
                .parse()
                .map_err(|e| ClientError::Api(format!("invalid mount symbol: {e:?}")))?,
        };
        self.send_mutating("remove_mount", priority, || {
            self.inner.remove_mount(ship_symbol, &body)
        })
        .await
    }

    pub async fn get_repair_ship(
        &self,
        ship_symbol: &str,
    ) -> Result<types::GetRepairShipResponse, ClientError> {
        self.get_repair_ship_with_priority(ship_symbol, RequestPriority::Normal)
            .await
    }

    pub async fn get_repair_ship_with_priority(
        &self,
        ship_symbol: &str,
        priority: RequestPriority,
    ) -> Result<types::GetRepairShipResponse, ClientError> {
        self.send("get_repair_ship", priority, || {
            self.inner.get_repair_ship(ship_symbol)
        })
        .await
    }

    pub async fn repair_ship(
        &self,
        ship_symbol: &str,
    ) -> Result<types::RepairShipResponse, ClientError> {
        self.repair_ship_with_priority(ship_symbol, RequestPriority::Normal)
            .await
    }

    pub async fn repair_ship_with_priority(
        &self,
        ship_symbol: &str,
        priority: RequestPriority,
    ) -> Result<types::RepairShipResponse, ClientError> {
        self.send_mutating("repair_ship", priority, || {
            self.inner.repair_ship(ship_symbol)
        })
        .await
    }

    pub async fn get_scrap_ship(
        &self,
        ship_symbol: &str,
    ) -> Result<types::GetScrapShipResponse, ClientError> {
        self.get_scrap_ship_with_priority(ship_symbol, RequestPriority::Normal)
            .await
    }

    pub async fn get_scrap_ship_with_priority(
        &self,
        ship_symbol: &str,
        priority: RequestPriority,
    ) -> Result<types::GetScrapShipResponse, ClientError> {
        self.send("get_scrap_ship", priority, || {
            self.inner.get_scrap_ship(ship_symbol)
        })
        .await
    }

    pub async fn scrap_ship(
        &self,
        ship_symbol: &str,
    ) -> Result<types::ScrapShipResponse, ClientError> {
        self.scrap_ship_with_priority(ship_symbol, RequestPriority::Normal)
            .await
    }

    pub async fn scrap_ship_with_priority(
        &self,
        ship_symbol: &str,
        priority: RequestPriority,
    ) -> Result<types::ScrapShipResponse, ClientError> {
        self.send_mutating("scrap_ship", priority, || {
            self.inner.scrap_ship(ship_symbol)
        })
        .await
    }

    pub async fn get_ship_modules(
        &self,
        ship_symbol: &str,
    ) -> Result<types::GetShipModulesResponse, ClientError> {
        self.get_ship_modules_with_priority(ship_symbol, RequestPriority::Normal)
            .await
    }

    pub async fn get_ship_modules_with_priority(
        &self,
        ship_symbol: &str,
        priority: RequestPriority,
    ) -> Result<types::GetShipModulesResponse, ClientError> {
        self.send("get_ship_modules", priority, || {
            self.inner.get_ship_modules(ship_symbol)
        })
        .await
    }

    pub async fn install_ship_module(
        &self,
        ship_symbol: &str,
        symbol: &str,
    ) -> Result<types::InstallShipModuleResponse, ClientError> {
        self.install_ship_module_with_priority(ship_symbol, symbol, RequestPriority::Normal)
            .await
    }

    pub async fn install_ship_module_with_priority(
        &self,
        ship_symbol: &str,
        symbol: &str,
        priority: RequestPriority,
    ) -> Result<types::InstallShipModuleResponse, ClientError> {
        let body = types::InstallShipModuleBody {
            symbol: symbol
                .parse()
                .map_err(|e| ClientError::Api(format!("invalid module symbol: {e:?}")))?,
        };
        self.send_mutating("install_ship_module", priority, || {
            self.inner.install_ship_module(ship_symbol, &body)
        })
        .await
    }

    pub async fn remove_ship_module(
        &self,
        ship_symbol: &str,
        symbol: &str,
    ) -> Result<types::RemoveShipModuleResponse, ClientError> {
        self.remove_ship_module_with_priority(ship_symbol, symbol, RequestPriority::Normal)
            .await
    }

    pub async fn remove_ship_module_with_priority(
        &self,
        ship_symbol: &str,
        symbol: &str,
        priority: RequestPriority,
    ) -> Result<types::RemoveShipModuleResponse, ClientError> {
        let body = types::RemoveShipModuleBody {
            symbol: symbol
                .parse()
                .map_err(|e| ClientError::Api(format!("invalid module symbol: {e:?}")))?,
        };
        self.send_mutating("remove_ship_module", priority, || {
            self.inner.remove_ship_module(ship_symbol, &body)
        })
        .await
    }

    pub async fn create_ship_ship_scan(
        &self,
        ship_symbol: &str,
    ) -> Result<types::CreateShipShipScanResponse, ClientError> {
        self.create_ship_ship_scan_with_priority(ship_symbol, RequestPriority::Normal)
            .await
    }

    pub async fn create_ship_ship_scan_with_priority(
        &self,
        ship_symbol: &str,
        priority: RequestPriority,
    ) -> Result<types::CreateShipShipScanResponse, ClientError> {
        self.send_mutating("create_ship_ship_scan", priority, || {
            self.inner.create_ship_ship_scan(ship_symbol)
        })
        .await
    }

    pub async fn create_ship_system_scan(
        &self,
        ship_symbol: &str,
    ) -> Result<types::CreateShipSystemScanResponse, ClientError> {
        self.create_ship_system_scan_with_priority(ship_symbol, RequestPriority::Normal)
            .await
    }

    pub async fn create_ship_system_scan_with_priority(
        &self,
        ship_symbol: &str,
        priority: RequestPriority,
    ) -> Result<types::CreateShipSystemScanResponse, ClientError> {
        self.send_mutating("create_ship_system_scan", priority, || {
            self.inner.create_ship_system_scan(ship_symbol)
        })
        .await
    }

    pub async fn create_ship_waypoint_scan(
        &self,
        ship_symbol: &str,
    ) -> Result<types::CreateShipWaypointScanResponse, ClientError> {
        self.create_ship_waypoint_scan_with_priority(ship_symbol, RequestPriority::Normal)
            .await
    }

    pub async fn create_ship_waypoint_scan_with_priority(
        &self,
        ship_symbol: &str,
        priority: RequestPriority,
    ) -> Result<types::CreateShipWaypointScanResponse, ClientError> {
        self.send_mutating("create_ship_waypoint_scan", priority, || {
            self.inner.create_ship_waypoint_scan(ship_symbol)
        })
        .await
    }
}