001package com.box.sdk;
002
003import com.eclipsesource.json.JsonObject;
004import com.eclipsesource.json.JsonValue;
005
006/**
007 * Represents an email address that can be used to upload files to a folder on Box.
008 */
009public class BoxUploadEmail extends BoxJSONObject {
010    private Access access;
011    private String email;
012
013    /**
014     * Constructs a BoxUploadEmail with default settings.
015     */
016    public BoxUploadEmail() {
017    }
018
019    /**
020     * Constructs a BoxUploadEmail from a JSON string.
021     *
022     * @param json the JSON encoded upload email.
023     */
024    public BoxUploadEmail(String json) {
025        super(json);
026    }
027
028    BoxUploadEmail(JsonObject jsonObject) {
029        super(jsonObject);
030    }
031
032    /**
033     * Gets the access level of this upload email.
034     *
035     * @return the access level of this upload email.
036     */
037    public Access getAccess() {
038        return this.access;
039    }
040
041    /**
042     * Sets the access level of this upload email.
043     *
044     * @param access the new access level of this upload email.
045     */
046    public void setAccess(Access access) {
047        this.access = access;
048        this.addPendingChange("access", access.toJSONValue());
049    }
050
051    /**
052     * Gets the email address of this upload email.
053     *
054     * @return the email address of this upload email.
055     */
056    public String getEmail() {
057        return this.email;
058    }
059
060    @Override
061    void parseJSONMember(JsonObject.Member member) {
062        JsonValue value = member.getValue();
063        String memberName = member.getName();
064        try {
065            if (memberName.equals("access")) {
066                this.access = Access.fromJSONValue(value.asString());
067            } else if (memberName.equals("email")) {
068                this.email = value.asString();
069            }
070        } catch (Exception e) {
071            throw new BoxDeserializationException(memberName, value.toString(), e);
072        }
073    }
074
075    /**
076     * Enumerates the possible access levels that can be set on an upload email.
077     */
078    public enum Access {
079        /**
080         * Anyone can send an upload to this email address.
081         */
082        OPEN("open"),
083
084        /**
085         * Only collaborators can send an upload to this email address.
086         */
087        COLLABORATORS("collaborators");
088
089        private final String jsonValue;
090
091        Access(String jsonValue) {
092            this.jsonValue = jsonValue;
093        }
094
095        static Access fromJSONValue(String jsonValue) {
096            return Access.valueOf(jsonValue.toUpperCase());
097        }
098
099        String toJSONValue() {
100            return this.jsonValue;
101        }
102    }
103}