spacetraders_client/endpoints/contracts/
mod.rs1use std::num::NonZeroU64;
2
3use crate::client::StClient;
4use crate::client::{ClientError, RequestPriority};
5use crate::types;
6
7impl StClient {
8 pub async fn get_contracts(
9 &self,
10 limit: Option<NonZeroU64>,
11 page: Option<NonZeroU64>,
12 ) -> Result<types::GetContractsResponse, ClientError> {
13 self.get_contracts_with_priority(limit, page, RequestPriority::Normal)
14 .await
15 }
16
17 pub async fn get_contracts_with_priority(
18 &self,
19 limit: Option<NonZeroU64>,
20 page: Option<NonZeroU64>,
21 priority: RequestPriority,
22 ) -> Result<types::GetContractsResponse, ClientError> {
23 self.send("get_contracts", priority, || {
24 self.inner.get_contracts(limit, page)
25 })
26 .await
27 }
28
29 pub async fn get_contract(
30 &self,
31 contract_id: &str,
32 ) -> Result<types::GetContractResponse, ClientError> {
33 self.get_contract_with_priority(contract_id, RequestPriority::Normal)
34 .await
35 }
36
37 pub async fn get_contract_with_priority(
38 &self,
39 contract_id: &str,
40 priority: RequestPriority,
41 ) -> Result<types::GetContractResponse, ClientError> {
42 self.send("get_contract", priority, || {
43 self.inner.get_contract(contract_id)
44 })
45 .await
46 }
47
48 pub async fn accept_contract(
49 &self,
50 contract_id: &str,
51 ) -> Result<types::AcceptContractResponse, ClientError> {
52 self.accept_contract_with_priority(contract_id, RequestPriority::Normal)
53 .await
54 }
55
56 pub async fn accept_contract_with_priority(
57 &self,
58 contract_id: &str,
59 priority: RequestPriority,
60 ) -> Result<types::AcceptContractResponse, ClientError> {
61 self.send_mutating("accept_contract", priority, || {
62 self.inner.accept_contract(contract_id)
63 })
64 .await
65 }
66
67 pub async fn deliver_contract(
68 &self,
69 contract_id: &str,
70 ship_symbol: &str,
71 trade_symbol: &str,
72 units: NonZeroU64,
73 ) -> Result<types::DeliverContractResponse, ClientError> {
74 self.deliver_contract_with_priority(
75 contract_id,
76 ship_symbol,
77 trade_symbol,
78 units,
79 RequestPriority::Normal,
80 )
81 .await
82 }
83
84 pub async fn deliver_contract_with_priority(
85 &self,
86 contract_id: &str,
87 ship_symbol: &str,
88 trade_symbol: &str,
89 units: NonZeroU64,
90 priority: RequestPriority,
91 ) -> Result<types::DeliverContractResponse, ClientError> {
92 let body = types::DeliverContractBody {
93 ship_symbol: ship_symbol.to_string(),
94 trade_symbol: trade_symbol.to_string(),
95 units,
96 };
97 self.send_mutating("deliver_contract", priority, || {
98 self.inner.deliver_contract(contract_id, &body)
99 })
100 .await
101 }
102
103 pub async fn fulfill_contract(
104 &self,
105 contract_id: &str,
106 ) -> Result<types::FulfillContractResponse, ClientError> {
107 self.fulfill_contract_with_priority(contract_id, RequestPriority::Normal)
108 .await
109 }
110
111 pub async fn fulfill_contract_with_priority(
112 &self,
113 contract_id: &str,
114 priority: RequestPriority,
115 ) -> Result<types::FulfillContractResponse, ClientError> {
116 self.send_mutating("fulfill_contract", priority, || {
117 self.inner.fulfill_contract(contract_id)
118 })
119 .await
120 }
121}