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
// Generated by wuapi-codegen from the OpenAPI spec. Do not edit: run `bun run codegen`.
use crate::http::{HttpClient, Method, Request, RequestParts, encode_path};
use crate::pagination::Paginator;
use crate::types;
/// API keys scoped to one project.
#[derive(Clone, Debug)]
pub struct ProjectsApiKeysResource {
http: HttpClient,
}
impl ProjectsApiKeysResource {
pub(crate) fn new(http: HttpClient) -> Self {
Self { http }
}
/// List a project's API keys
///
/// Every key of the project, revoked ones included. Never the key itself. Organization keys only (project keys get `403 forbidden`); the `Wuapi-Project` header does not change the result.
///
/// `GET /v1/projects/{projectId}/api-keys`
///
/// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
pub fn list(
&self,
project_id: &str,
params: types::ProjectsApiKeysListParams,
) -> Paginator<types::ApiKeyList> {
let parts = RequestParts::new(Method::Get, format!("/v1/projects/{}/api-keys", encode_path(project_id)))
.query_opt("limit", params.limit.as_ref())
.retryable();
Paginator::new(self.http.clone(), parts, "cursor", params.cursor)
}
/// Create a project API key
///
/// A key that reaches only this project's resources. At most 20 active keys per project. The `key` is shown only here. Organization keys only (project keys get `403 forbidden`); the `Wuapi-Project` header does not change the result.
///
/// `POST /v1/projects/{projectId}/api-keys`
///
/// Sends `Idempotency-Key` (a random key, or your own with `.idempotency_key(..)`), so it is retried on timeouts, network errors, `429` and `5xx` without repeating its effect.
pub fn create(
&self,
project_id: &str,
params: types::ProjectsApiKeysCreateParams,
) -> Request<types::ApiKey> {
let parts = RequestParts::new(Method::Post, format!("/v1/projects/{}/api-keys", encode_path(project_id)))
.body(¶ms)
.keyed();
self.http.request(parts)
}
/// Revoke a project API key
///
/// The key stops working at once. Organization keys only (project keys get `403 forbidden`); the `Wuapi-Project` header does not change the result.
///
/// `DELETE /v1/projects/{projectId}/api-keys/{apiKeyId}`
///
/// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
pub fn revoke(&self, project_id: &str, api_key_id: &str) -> Request<()> {
let parts = RequestParts::new(Method::Delete, format!("/v1/projects/{}/api-keys/{}", encode_path(project_id), encode_path(api_key_id)))
.retryable()
.no_content();
self.http.request(parts)
}
}
/// The `projects` methods.
#[derive(Clone, Debug)]
pub struct ProjectsResource {
http: HttpClient,
}
impl ProjectsResource {
pub(crate) fn new(http: HttpClient) -> Self {
Self { http }
}
/// API keys scoped to one project.
#[must_use]
pub fn api_keys(&self) -> ProjectsApiKeysResource {
ProjectsApiKeysResource::new(self.http.clone())
}
/// Create a project
///
/// Fires `project.created`. Organization keys only (project keys get `403 forbidden`); the `Wuapi-Project` header does not change the result.
///
/// `POST /v1/projects`
///
/// Sends `Idempotency-Key` (a random key, or your own with `.idempotency_key(..)`), so it is retried on timeouts, network errors, `429` and `5xx` without repeating its effect.
pub fn create(&self, params: types::ProjectsCreateParams) -> Request<types::Project> {
let parts = RequestParts::new(Method::Post, "/v1/projects").body(¶ms).keyed();
self.http.request(parts)
}
/// List projects
///
/// Live projects, newest first. Organization keys only (project keys get `403 forbidden`); the `Wuapi-Project` header does not change the result.
///
/// `GET /v1/projects`
///
/// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
pub fn list(&self, params: types::ProjectsListParams) -> Paginator<types::ProjectList> {
let parts = RequestParts::new(Method::Get, "/v1/projects")
.query_opt("limit", params.limit.as_ref())
.query_opt("externalId", params.external_id.as_ref())
.query_opt("status", params.status.as_ref())
.retryable();
Paginator::new(self.http.clone(), parts, "cursor", params.cursor)
}
/// Get a project
///
/// A project, by id or `ext:<externalId>`. Organization keys only (project keys get `403 forbidden`); the `Wuapi-Project` header does not change the result.
///
/// `GET /v1/projects/{projectId}`
///
/// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
pub fn get(&self, project_id: &str) -> Request<types::Project> {
let parts = RequestParts::new(Method::Get, format!("/v1/projects/{}", encode_path(project_id)))
.retryable();
self.http.request(parts)
}
/// Update, suspend or resume a project
///
/// `status: suspended` refuses every send and write in the project (`403 project_suspended`) while reads and inbound keep working. Fires `project.updated`. Organization keys only (project keys get `403 forbidden`); the `Wuapi-Project` header does not change the result.
///
/// `PATCH /v1/projects/{projectId}`
///
/// Not idempotent: retried only when the request never reached the API or was refused with `429`.
pub fn update(
&self,
project_id: &str,
params: types::ProjectsUpdateParams,
) -> Request<types::Project> {
let parts = RequestParts::new(Method::Patch, format!("/v1/projects/{}", encode_path(project_id)))
.body(¶ms);
self.http.request(parts)
}
/// Delete a project
///
/// Answers at once: from then on the project is 404, its keys answer 401 and its `externalId` can be reused. In the background its accounts are logged out and deleted, then its webhook endpoints removed, and `project.deleted` fires. Organization keys only (project keys get `403 forbidden`); the `Wuapi-Project` header does not change the result.
///
/// `DELETE /v1/projects/{projectId}`
///
/// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
pub fn delete(&self, project_id: &str) -> Request<()> {
let parts = RequestParts::new(Method::Delete, format!("/v1/projects/{}", encode_path(project_id)))
.retryable()
.no_content();
self.http.request(parts)
}
/// Get a project's usage
///
/// The project's usage for `month`. Organization keys only (project keys get `403 forbidden`); the `Wuapi-Project` header does not change the result.
///
/// `GET /v1/projects/{projectId}/usage`
///
/// Safe to repeat: retried on timeouts, network errors, `429` and `5xx`.
pub fn get_usage(
&self,
project_id: &str,
params: types::ProjectsGetUsageParams,
) -> Request<types::ProjectUsage> {
let parts = RequestParts::new(Method::Get, format!("/v1/projects/{}/usage", encode_path(project_id)))
.query_opt("month", params.month.as_ref())
.retryable();
self.http.request(parts)
}
}