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

uk.gov.service.notify.LetterResponse 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 LetterResponse {
    private final UUID notificationId;
    private final String reference;
    private final String postage;
    private final JSONObject data;

    public LetterResponse(String response) {
        data = new JSONObject(response);
        notificationId = UUID.fromString(data.getString("id"));
        reference = data.isNull("reference") ? null : data.getString("reference");
        postage = data.isNull("postage") ? null : data.getString("postage");

    }

    public UUID getNotificationId() {
        return notificationId;
    }

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

    public JSONObject getData() {
        return data;
    }

    public Optional getPostage() {
        return Optional.ofNullable(postage);
    }

    @Override
    public String toString() {
        return "SendLetterResponse{" +
                "notificationId=" + notificationId +
                ", reference=" + reference +
                '}';
    }

    public String tryToGetString(JSONObject jsonObj, String key)
    {
        if (jsonObj.has(key))
        {
            if(jsonObj.opt(key).toString().equals("null"))
            {
                return null;
            }
            else
            {
                return jsonObj.opt(key).toString();
            }
        }

        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy