001package com.box.sdk;
002
003import com.eclipsesource.json.Json;
004import com.eclipsesource.json.JsonObject;
005import com.eclipsesource.json.JsonValue;
006
007/**
008 * Represents a notification email object
009 */
010public class BoxNotificationEmail extends BoxJSONObject {
011    private boolean isConfirmed;
012    private String email;
013
014
015    /**
016     * Constructs a BoxNotificationEmail object.
017     *
018     * @param email The email address to send the notifications to.
019     * @param isConfirmed Specifies if this email address has been confirmed.
020     */
021    public BoxNotificationEmail(String email, boolean isConfirmed) {
022        this(new JsonObject()
023            .add("email", email)
024            .add("is_confirmed", isConfirmed)
025        );
026    }
027
028    /**
029     * Constructs a BoxNotificationEmail from a JSON string.
030     *
031     * @param json the json encoded email alias.
032     */
033    public BoxNotificationEmail(String json) {
034        this(Json.parse(json).asObject());
035    }
036
037    /**
038     * Constructs a BoxNotificationEmail using an already parsed JSON object.
039     *
040     * @param jsonObject the parsed JSON object.
041     */
042    BoxNotificationEmail(JsonObject jsonObject) {
043        super(jsonObject);
044    }
045
046    /**
047     * Gets if this email address has been confirmed.
048     *
049     * @return true if this email address has been confirmed; otherwise false.
050     */
051    public boolean getIsConfirmed() {
052        return this.isConfirmed;
053    }
054
055    /**
056     * Gets the email address to send notifications to.
057     *
058     * @return The email address to send the notifications to.
059     */
060    public String getEmail() {
061        return this.email;
062    }
063
064    @Override
065    void parseJSONMember(JsonObject.Member member) {
066        JsonValue value = member.getValue();
067        String memberName = member.getName();
068        try {
069            if (memberName.equals("is_confirmed")) {
070                this.isConfirmed = value.asBoolean();
071            } else if (memberName.equals("email")) {
072                this.email = value.asString();
073            }
074        } catch (Exception e) {
075            throw new BoxDeserializationException(memberName, value.toString(), e);
076        }
077    }
078}