1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
use crate::{
config::Configuration,
http::client::HttpClient,
models::{
errors::ApiError, CreateGiftCardRequest, CreateGiftCardResponse,
LinkCustomerToGiftCardRequest, LinkCustomerToGiftCardResponse, ListGiftCardsParameters,
ListGiftCardsResponse, RetrieveGiftCardFromGANRequest, RetrieveGiftCardFromGANResponse,
RetrieveGiftCardFromNonceRequest, RetrieveGiftCardFromNonceResponse,
RetrieveGiftCardResponse, UnlinkCustomerFromGiftCardRequest,
UnlinkCustomerFromGiftCardResponse,
},
};
const DEFAULT_URI: &str = "/gift-cards";
pub struct GiftCardsApi {
config: Configuration,
client: HttpClient,
}
impl GiftCardsApi {
pub fn new(config: Configuration, client: HttpClient) -> Self {
Self { config, client }
}
pub async fn list_gift_cards(
&self,
params: &ListGiftCardsParameters,
) -> Result<ListGiftCardsResponse, ApiError> {
let url = format!("{}{}", &self.url(), params.to_query_string());
let response = self.client.get(&url).await?;
response.deserialize().await
}
pub async fn create_gift_card(
&self,
body: &CreateGiftCardRequest,
) -> Result<CreateGiftCardResponse, ApiError> {
let response = self.client.post(&self.url(), body).await?;
response.deserialize().await
}
pub async fn retrieve_gift_card_from_gan(
&self,
body: &RetrieveGiftCardFromGANRequest,
) -> Result<RetrieveGiftCardFromGANResponse, ApiError> {
let url = format!("{}/from-gan", &self.url());
let response = self.client.post(&url, body).await?;
response.deserialize().await
}
pub async fn retrieve_gift_card_from_nonce(
&self,
body: &RetrieveGiftCardFromNonceRequest,
) -> Result<RetrieveGiftCardFromNonceResponse, ApiError> {
let url = format!("{}/from-nonce", &self.url());
let response = self.client.post(&url, body).await?;
response.deserialize().await
}
pub async fn link_customer_to_gift_card(
&self,
gift_card_id: &str,
body: &LinkCustomerToGiftCardRequest,
) -> Result<LinkCustomerToGiftCardResponse, ApiError> {
let url = format!("{}/{}/link-customer", &self.url(), gift_card_id);
let response = self.client.post(&url, body).await?;
response.deserialize().await
}
pub async fn unlink_customer_from_gift_card(
&self,
gift_card_id: &str,
body: &UnlinkCustomerFromGiftCardRequest,
) -> Result<UnlinkCustomerFromGiftCardResponse, ApiError> {
let url = format!("{}/{}/unlink-customer", &self.url(), gift_card_id);
let response = self.client.post(&url, body).await?;
response.deserialize().await
}
pub async fn retrieve_gift_card(&self, id: &str) -> Result<RetrieveGiftCardResponse, ApiError> {
let url = format!("{}/{}", &self.url(), id);
let response = self.client.get(&url).await?;
response.deserialize().await
}
fn url(&self) -> String {
format!("{}{}", &self.config.get_base_url(), DEFAULT_URI)
}
}