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