Skip to main content

spacetraders_client/endpoints/fleet/
cargo.rs

1use std::num::NonZeroU64;
2
3use crate::client::StClient;
4use crate::client::{ClientError, RequestPriority};
5use crate::types;
6
7impl StClient {
8    pub async fn jettison(
9        &self,
10        ship_symbol: &str,
11        symbol: types::TradeSymbol,
12        units: NonZeroU64,
13    ) -> Result<types::JettisonResponse, ClientError> {
14        self.jettison_with_priority(ship_symbol, symbol, units, RequestPriority::Normal)
15            .await
16    }
17
18    pub async fn jettison_with_priority(
19        &self,
20        ship_symbol: &str,
21        symbol: types::TradeSymbol,
22        units: NonZeroU64,
23        priority: RequestPriority,
24    ) -> Result<types::JettisonResponse, ClientError> {
25        let body = types::JettisonBody { symbol, units };
26        self.send_mutating("jettison", priority, || {
27            self.inner.jettison(ship_symbol, &body)
28        })
29        .await
30    }
31
32    pub async fn sell_cargo(
33        &self,
34        ship_symbol: &str,
35        symbol: types::TradeSymbol,
36        units: NonZeroU64,
37    ) -> Result<types::SellCargo201Response, ClientError> {
38        self.sell_cargo_with_priority(ship_symbol, symbol, units, RequestPriority::Normal)
39            .await
40    }
41
42    pub async fn sell_cargo_with_priority(
43        &self,
44        ship_symbol: &str,
45        symbol: types::TradeSymbol,
46        units: NonZeroU64,
47        priority: RequestPriority,
48    ) -> Result<types::SellCargo201Response, ClientError> {
49        let body = types::SellCargoRequest { symbol, units };
50        self.send_mutating("sell_cargo", priority, || {
51            self.inner.sell_cargo(ship_symbol, &body)
52        })
53        .await
54    }
55
56    pub async fn purchase_cargo(
57        &self,
58        ship_symbol: &str,
59        symbol: types::TradeSymbol,
60        units: NonZeroU64,
61    ) -> Result<types::PurchaseCargo201Response, ClientError> {
62        self.purchase_cargo_with_priority(ship_symbol, symbol, units, RequestPriority::Normal)
63            .await
64    }
65
66    pub async fn purchase_cargo_with_priority(
67        &self,
68        ship_symbol: &str,
69        symbol: types::TradeSymbol,
70        units: NonZeroU64,
71        priority: RequestPriority,
72    ) -> Result<types::PurchaseCargo201Response, ClientError> {
73        let body = types::PurchaseCargoRequest { symbol, units };
74        self.send_mutating("purchase_cargo", priority, || {
75            self.inner.purchase_cargo(ship_symbol, &body)
76        })
77        .await
78    }
79
80    pub async fn transfer_cargo(
81        &self,
82        ship_symbol: &str,
83        trade_symbol: types::TradeSymbol,
84        units: NonZeroU64,
85        target_ship_symbol: &str,
86    ) -> Result<types::TransferCargo200Response, ClientError> {
87        self.transfer_cargo_with_priority(
88            ship_symbol,
89            trade_symbol,
90            units,
91            target_ship_symbol,
92            RequestPriority::Normal,
93        )
94        .await
95    }
96
97    pub async fn transfer_cargo_with_priority(
98        &self,
99        ship_symbol: &str,
100        trade_symbol: types::TradeSymbol,
101        units: NonZeroU64,
102        target_ship_symbol: &str,
103        priority: RequestPriority,
104    ) -> Result<types::TransferCargo200Response, ClientError> {
105        let body = types::TransferCargoRequest {
106            trade_symbol,
107            units,
108            ship_symbol: target_ship_symbol.to_string(),
109        };
110        self.send_mutating("transfer_cargo", priority, || {
111            self.inner.transfer_cargo(ship_symbol, &body)
112        })
113        .await
114    }
115
116    pub async fn negotiate_contract(
117        &self,
118        ship_symbol: &str,
119    ) -> Result<types::NegotiateContract201Response, ClientError> {
120        self.negotiate_contract_with_priority(ship_symbol, RequestPriority::Normal)
121            .await
122    }
123
124    pub async fn negotiate_contract_with_priority(
125        &self,
126        ship_symbol: &str,
127        priority: RequestPriority,
128    ) -> Result<types::NegotiateContract201Response, ClientError> {
129        self.send_mutating("negotiate_contract", priority, || {
130            self.inner.negotiate_contract(ship_symbol)
131        })
132        .await
133    }
134}