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