All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.gov.service.notify.SendEmailResponse Maven / Gradle / Ivy

Go to download

Use this client to send emails, text messages and letters using the GOV.UK Notify API.

There is a newer version: 5.2.1-RELEASE
Show newest version
package uk.gov.service.notify;

import org.json.JSONObject;

import java.util.Optional;
import java.util.UUID;

public class SendEmailResponse {
    private final UUID notificationId;
    private final String reference;
    private final UUID templateId;
    private final int templateVersion;
    private final String templateUri;
    private final String body;
    private final String subject;
    private final String fromEmail;


    public SendEmailResponse(String response) {
        JSONObject data = new JSONObject(response);
        notificationId = UUID.fromString(data.getString("id"));
        reference = data.isNull("reference") ? null : data.getString("reference");
        JSONObject content = data.getJSONObject("content");
        body = content.getString("body");
        fromEmail = content.isNull("from_email") ? null : content.getString("from_email");
        subject = content.getString("subject");
        JSONObject template = data.getJSONObject("template");
        templateId = UUID.fromString(template.getString("id"));
        templateVersion = template.getInt("version");
        templateUri = template.getString("uri");
    }

    public UUID getNotificationId() {
        return notificationId;
    }

    public Optional getReference() {
        return Optional.ofNullable(reference);
    }

    public UUID getTemplateId() {
        return templateId;
    }

    public int getTemplateVersion() {
        return templateVersion;
    }

    public String getTemplateUri() {
        return templateUri;
    }

    public String getBody() {
        return body;
    }

    public String getSubject() {
        return subject;
    }

    public Optional getFromEmail() {
        return Optional.ofNullable(fromEmail);
    }

    @Override
    public String toString() {
        return "SendEmailResponse{" +
                "notificationId=" + notificationId +
                ", reference=" + reference +
                ", templateId=" + templateId +
                ", templateVersion=" + templateVersion +
                ", templateUri='" + templateUri + '\'' +
                ", body='" + body + '\'' +
                ", subject='" + subject + '\'' +
                ", fromEmail=" + fromEmail +
                '}';
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy