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 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 /** 071 * Enumerates the possible access levels that can be set on an upload email. 072 */ 073 public enum Access { 074 /** 075 * Anyone can send an upload to this email address. 076 */ 077 OPEN("open"), 078 079 /** 080 * Only collaborators can send an upload to this email address. 081 */ 082 COLLABORATORS("collaborators"); 083 084 private final String jsonValue; 085 086 private Access(String jsonValue) { 087 this.jsonValue = jsonValue; 088 } 089 090 static Access fromJSONValue(String jsonValue) { 091 return Access.valueOf(jsonValue.toUpperCase()); 092 } 093 094 String toJSONValue() { 095 return this.jsonValue; 096 } 097 } 098}