postmark 2.0.0

Postmark rust client
Documentation
use std::borrow::Cow;

use crate::Endpoint;
use crate::api::endpoint_with_path_segment;
use crate::api::signatures::{SenderSignature, SignatureId};
use serde::Serialize;
use typed_builder::TypedBuilder;

#[derive(Debug, Clone, PartialEq, Serialize, TypedBuilder)]
#[serde(rename_all = "PascalCase")]
pub struct GetSignatureRequest {
    #[builder(setter(into))]
    #[serde(skip)]
    pub signature_id: SignatureId,
}

impl Endpoint for GetSignatureRequest {
    type Request = GetSignatureRequest;
    type Response = SenderSignature;

    fn endpoint(&self) -> Cow<'static, str> {
        endpoint_with_path_segment("/senders", &self.signature_id.to_string())
    }

    fn body(&self) -> &Self::Request {
        self
    }

    fn method(&self) -> http::Method {
        http::Method::GET
    }
}

#[cfg(test)]
mod tests {
    use httptest::matchers::request;
    use httptest::{Expectation, Server, responders::*};
    use serde_json::json;

    use crate::Query;
    use crate::reqwest::PostmarkClient;

    use super::*;

    #[tokio::test]
    async fn get_signature() {
        let server = Server::run();
        server.expect(
            Expectation::matching(request::method_path("GET", "/senders/1")).respond_with(
                json_encoded(json!({
                    "Domain": "example.com",
                    "EmailAddress": "john@example.com",
                    "ReplyToEmailAddress": "reply@example.com",
                    "Name": "John",
                    "Confirmed": true,
                    "SPFVerified": false,
                    "DKIMVerified": true,
                    "WeakDKIM": false,
                    "ID": 1
                })),
            ),
        );
        let client = PostmarkClient::builder()
            .base_url(server.url("/").to_string())
            .build();
        let req = GetSignatureRequest::builder().signature_id(1).build();
        let resp = req.execute(&client).await.expect("json decode");
        assert_eq!(resp.id, 1);
    }
}