Skip to content

Commit

Permalink
feat: Add notification_email to BoxUser (#1088)
Browse files Browse the repository at this point in the history
  • Loading branch information
arjankowski authored Aug 25, 2022
1 parent 49411aa commit 5477223
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 49 deletions.
63 changes: 63 additions & 0 deletions src/main/java/com/box/sdk/BoxNotificationEmail.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.box.sdk;

import com.eclipsesource.json.JsonObject;
import com.eclipsesource.json.JsonValue;

/**
* Represents a notification email object
*/
public class BoxNotificationEmail extends BoxJSONObject {
private boolean isConfirmed;
private String email;

/**
* Constructs a BoxNotificationEmail from a JSON string.
*
* @param json the json encoded email alias.
*/
public BoxNotificationEmail(String json) {
super(json);
}

/**
* Constructs a BoxNotificationEmail using an already parsed JSON object.
*
* @param jsonObject the parsed JSON object.
*/
BoxNotificationEmail(JsonObject jsonObject) {
super(jsonObject);
}

/**
* Gets whether or not the email address has been confirmed.
*
* @return true if this email address has been confirmed; otherwise false.
*/
public boolean getIsConfirmed() {
return this.isConfirmed;
}

/**
* Gets the email address to send notifications to.
*
* @return The email address to send the notifications to.
*/
public String getEmail() {
return this.email;
}

@Override
void parseJSONMember(JsonObject.Member member) {
JsonValue value = member.getValue();
String memberName = member.getName();
try {
if (memberName.equals("is_confirmed")) {
this.isConfirmed = value.asBoolean();
} else if (memberName.equals("email")) {
this.email = value.asString();
}
} catch (Exception e) {
throw new BoxDeserializationException(memberName, value.toString(), e);
}
}
}
35 changes: 30 additions & 5 deletions src/main/java/com/box/sdk/BoxUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class BoxUser extends BoxCollaborator {
"language", "timezone", "space_amount", "space_used", "max_upload_size", "tracking_codes",
"can_see_managed_users", "is_sync_enabled", "is_external_collab_restricted", "status", "job_title", "phone",
"address", "avatar_url", "is_exempt_from_device_limits", "is_exempt_from_login_verification", "enterprise",
"my_tags", "hostname", "is_platform_access_only", "external_app_user_id"};
"my_tags", "hostname", "is_platform_access_only", "external_app_user_id", "notification_email"};

/**
* User URL Template.
Expand Down Expand Up @@ -690,8 +690,8 @@ public AvatarUploadResponse uploadAvatar(File file) {
}

/**
* Upload avatar image to user account. Supported formats are JPG and PNG.
* The image size cannot exceed 1024 * 1024 pixels or 1MB.
* Upload avatar image to user account. Supported formats are JPG and PNG.
* The image size cannot exceed 1024 * 1024 pixels or 1MB.
*
* @param file {@link File} containg avatar image.
* @param progressListener {@link ProgressListener} set if you want to track upload progress
Expand All @@ -718,8 +718,8 @@ public AvatarUploadResponse uploadAvatar(InputStream content, String fileName) {
}

/**
* Upload avatar image to user account. Supported formats are JPG and PNG.
* The image size cannot exceed 1024 * 1024 pixels or 1MB.
* Upload avatar image to user account. Supported formats are JPG and PNG.
* The image size cannot exceed 1024 * 1024 pixels or 1MB.
*
* @param content {@link InputStream} containing image data
* @param fileName file name with extention what will be used to determine content type
Expand Down Expand Up @@ -852,6 +852,7 @@ public class Info extends BoxCollaborator.Info {
private String phone;
private String address;
private String avatarURL;
private BoxNotificationEmail notificationEmail;
private boolean isExemptFromDeviceLimits;
private boolean isExemptFromLoginVerification;
private boolean isPasswordResetRequired;
Expand Down Expand Up @@ -1086,6 +1087,24 @@ public String getAvatarURL() {
return this.avatarURL;
}

/**
* Gets the user's alternate notification email address to which email notifications are sent.
*
* @return the user's notification email address.
*/
public BoxNotificationEmail getNotificationEmail() {
return this.notificationEmail;
}

/**
* Sets the user's notification email address.
*
* @param notificationEmail the user's new notification email address.
*/
public void setNotificationEmail(BoxNotificationEmail notificationEmail) {
this.notificationEmail = notificationEmail;
}

/**
* Gets the enterprise that the user belongs to.
*
Expand Down Expand Up @@ -1325,6 +1344,12 @@ protected void parseJSONMember(JsonObject.Member member) {
this.address = value.asString();
} else if (memberName.equals("avatar_url")) {
this.avatarURL = value.asString();
} else if (memberName.equals("notification_email")) {
if (value.isObject()) {
this.notificationEmail = new BoxNotificationEmail(value.asObject());
} else {
this.notificationEmail = null;
}
} else if (memberName.equals("can_see_managed_users")) {
this.canSeeManagedUsers = value.asBoolean();
} else if (memberName.equals("is_sync_enabled")) {
Expand Down
6 changes: 5 additions & 1 deletion src/test/Fixtures/BoxUser/GetCurrentUserInfo200.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@
"job_title": "",
"phone": "1111111111",
"address": "",
"avatar_url": "https://test.app.box.com/api/avatar/large/12345"
"avatar_url": "https://test.app.box.com/api/avatar/large/12345",
"notification_email": {
"email": "[email protected]",
"is_confirmed": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "user",
"id": "12345",
"name": "Test User",
"login": "[email protected]",
"created_at": "2015-04-09T12:32:40-07:00",
"modified_at": "2018-04-25T11:00:20-07:00",
"language": "en",
"timezone": "America/Los_Angeles",
"space_amount": 1000000000000000,
"space_used": 22392578035,
"max_upload_size": 16106127360,
"status": "active",
"job_title": "",
"phone": "1111111111",
"address": "",
"avatar_url": "https://test.app.box.com/api/avatar/large/12345",
"notification_email": []
}
Loading

0 comments on commit 5477223

Please sign in to comment.