postmark/api/server/
edit_server.rs1use std::borrow::Cow;
2
3use crate::Endpoint;
4use crate::api::server::{DeliveryType, Server, ServerColor};
5use serde::Serialize;
6use typed_builder::TypedBuilder;
7
8#[derive(Debug, Clone, PartialEq, Serialize, TypedBuilder)]
9#[serde(rename_all = "PascalCase")]
10pub struct EditServerRequest {
11 #[builder(default, setter(into, strip_option))]
12 #[serde(skip_serializing_if = "Option::is_none")]
13 pub name: Option<String>,
14 #[builder(default, setter(into, strip_option))]
15 #[serde(skip_serializing_if = "Option::is_none")]
16 pub color: Option<ServerColor>,
17 #[builder(default, setter(into, strip_option))]
18 #[serde(skip_serializing_if = "Option::is_none")]
19 pub delivery_type: Option<DeliveryType>,
20 #[builder(default, setter(into, strip_option))]
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub smtp_api_activated: Option<bool>,
23}
24
25impl Endpoint for EditServerRequest {
26 type Request = EditServerRequest;
27 type Response = Server;
28
29 fn endpoint(&self) -> Cow<'static, str> {
30 "/server".into()
31 }
32
33 fn body(&self) -> &Self::Request {
34 self
35 }
36
37 fn method(&self) -> http::Method {
38 http::Method::PUT
39 }
40}
41
42#[cfg(test)]
43mod tests {
44 use httptest::matchers::request;
45 use httptest::{Expectation, Server as HttpServer, responders::*};
46 use serde_json::json;
47
48 use crate::Query;
49 use crate::reqwest::PostmarkClient;
50
51 use super::*;
52
53 #[tokio::test]
54 pub async fn edit_server() {
55 let server = HttpServer::run();
56
57 server.expect(
58 Expectation::matching(request::method_path("PUT", "/server")).respond_with(
59 json_encoded(json!({
60 "ID": 1,
61 "Name": "Staging Testing",
62 "ApiTokens": ["server token"],
63 "SmtpApiActivated": true
64 })),
65 ),
66 );
67
68 let client = PostmarkClient::builder()
69 .base_url(server.url("/").to_string())
70 .build();
71
72 let req = EditServerRequest::builder().name("Staging Testing").build();
73
74 let resp = req.execute(&client).await.expect("json decode");
75 assert_eq!(resp.id, 1);
76 }
77}