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     * Constructs a BoxUploadEmail from a JSON string.
020     * @param  json the JSON encoded upload email.
021     */
022    public BoxUploadEmail(String json) {
023        super(json);
024    }
025
026    BoxUploadEmail(JsonObject jsonObject) {
027        super(jsonObject);
028    }
029
030    /**
031     * Gets the access level of this upload email.
032     * @return the access level of this upload email.
033     */
034    public Access getAccess() {
035        return this.access;
036    }
037
038    /**
039     * Sets the access level of this upload email.
040     * @param access the new access level of this upload email.
041     */
042    public void setAccess(Access access) {
043        this.access = access;
044        this.addPendingChange("access", access.toJSONValue());
045    }
046
047    /**
048     * Gets the email address of this upload email.
049     * @return the email address of this upload email.
050     */
051    public String getEmail() {
052        return this.email;
053    }
054
055    @Override
056    void parseJSONMember(JsonObject.Member member) {
057        JsonValue value = member.getValue();
058        String memberName = member.getName();
059        if (memberName.equals("access")) {
060            this.access = Access.fromJSONValue(value.asString());
061        } else if (memberName.equals("email")) {
062            this.email = value.asString();
063        }
064    }
065
066    /**
067     * Enumerates the possible access levels that can be set on an upload email.
068     */
069    public enum Access {
070        /**
071         * Anyone can send an upload to this email address.
072         */
073        OPEN("open"),
074
075        /**
076         * Only collaborators can send an upload to this email address.
077         */
078        COLLABORATORS("collaborators");
079
080        private final String jsonValue;
081
082        private Access(String jsonValue) {
083            this.jsonValue = jsonValue;
084        }
085
086        static Access fromJSONValue(String jsonValue) {
087            return Access.valueOf(jsonValue.toUpperCase());
088        }
089
090        String toJSONValue() {
091            return this.jsonValue;
092        }
093    }
094}