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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
use crate::{
config::Configuration,
http::client::HttpClient,
models::{
errors::ApiError, CancelSubscriptionResponse, CreateSubscriptionRequest,
CreateSubscriptionResponse, DeleteSubscriptionActionResponse,
ListSubscriptionEventsParameters, ListSubscriptionEventsResponse, PauseSubscriptionRequest,
PauseSubscriptionResponse, ResumeSubscriptionRequest, ResumeSubscriptionResponse,
RetrieveSubscriptionParameters, RetrieveSubscriptionResponse, SearchSubscriptionsRequest,
SearchSubscriptionsResponse, SwapPlanRequest, SwapPlanResponse, UpdateSubscriptionRequest,
UpdateSubscriptionResponse,
},
};
const DEFAULT_URI: &str = "/subscriptions";
pub struct SubscriptionsApi {
config: Configuration,
client: HttpClient,
}
impl SubscriptionsApi {
pub fn new(config: Configuration, client: HttpClient) -> Self {
Self { config, client }
}
pub async fn create_subscription(
&self,
body: &CreateSubscriptionRequest,
) -> Result<CreateSubscriptionResponse, ApiError> {
let response = self.client.post(&self.url(), body).await?;
response.deserialize().await
}
pub async fn search_subscriptions(
&self,
body: &SearchSubscriptionsRequest,
) -> Result<SearchSubscriptionsResponse, ApiError> {
let url = format!("{}/search", &self.url());
let response = self.client.post(&url, body).await?;
response.deserialize().await
}
pub async fn retrieve_subscription(
&self,
subscription_id: &str,
params: &RetrieveSubscriptionParameters,
) -> Result<RetrieveSubscriptionResponse, ApiError> {
let url = format!("{}/{}{}", &self.url(), subscription_id, params.to_query_string());
let response = self.client.get(&url).await?;
response.deserialize().await
}
pub async fn update_subscription(
&self,
subscription_id: &str,
body: &UpdateSubscriptionRequest,
) -> Result<UpdateSubscriptionResponse, ApiError> {
let url = format!("{}/{}", &self.url(), subscription_id);
let response = self.client.put(&url, body).await?;
response.deserialize().await
}
pub async fn delete_subscription_action(
&self,
subscription_id: &str,
action_id: &str,
) -> Result<DeleteSubscriptionActionResponse, ApiError> {
let url = format!("{}/{}/actions/{}", &self.url(), subscription_id, action_id);
let response = self.client.delete(&url).await?;
response.deserialize().await
}
pub async fn cancel_subscription(
&self,
subscription_id: &str,
) -> Result<CancelSubscriptionResponse, ApiError> {
let url = format!("{}/{}/cancel", &self.url(), subscription_id);
let response = self.client.post(&url, "").await?;
response.deserialize().await
}
pub async fn list_subscription_events(
&self,
subscription_id: &str,
params: &ListSubscriptionEventsParameters,
) -> Result<ListSubscriptionEventsResponse, ApiError> {
let url = format!("{}/{}/events{}", &self.url(), subscription_id, params.to_query_string());
let response = self.client.get(&url).await?;
response.deserialize().await
}
pub async fn pause_subscription(
&self,
subscription_id: &str,
body: &PauseSubscriptionRequest,
) -> Result<PauseSubscriptionResponse, ApiError> {
let url = format!("{}/{}/pause", &self.url(), subscription_id);
let response = self.client.post(&url, body).await?;
response.deserialize().await
}
pub async fn resume_subscription(
&self,
subscription_id: &str,
body: &ResumeSubscriptionRequest,
) -> Result<ResumeSubscriptionResponse, ApiError> {
let url = format!("{}/{}/resume", &self.url(), subscription_id);
let response = self.client.post(&url, body).await?;
response.deserialize().await
}
pub async fn swap_plan(
&self,
subscription_id: &str,
body: &SwapPlanRequest,
) -> Result<SwapPlanResponse, ApiError> {
let url = format!("{}/{}/swap-plan", &self.url(), subscription_id);
let response = self.client.post(&url, body).await?;
response.deserialize().await
}
fn url(&self) -> String {
format!("{}{}", &self.config.get_base_url(), DEFAULT_URI)
}
}