|
13 | 13 |
|
14 | 14 | import org.gitlab4j.api.GitLabApi.ApiVersion; |
15 | 15 | import org.gitlab4j.api.models.CustomAttribute; |
| 16 | +import org.gitlab4j.api.models.Email; |
16 | 17 | import org.gitlab4j.api.models.ImpersonationToken; |
17 | 18 | import org.gitlab4j.api.models.ImpersonationToken.Scope; |
18 | 19 | import org.gitlab4j.api.models.SshKey; |
@@ -1012,4 +1013,105 @@ public User setUserAvatar(final Object userIdOrUsername, File avatarFile) throws |
1012 | 1013 | Response response = putUpload(Response.Status.OK, "avatar", avatarFile, "users", getUserIdOrUsername(userIdOrUsername)); |
1013 | 1014 | return (response.readEntity(User.class)); |
1014 | 1015 | } |
| 1016 | + |
| 1017 | + /** |
| 1018 | + * Get a list of emails for the current user. |
| 1019 | + * |
| 1020 | + * <pre><code>GitLab Endpoint: GET /users/emails</code></pre> |
| 1021 | + * |
| 1022 | + * @return a List of Email instances for the current user |
| 1023 | + * @throws GitLabApiException if any exception occurs |
| 1024 | + */ |
| 1025 | + public List<Email> getEmails() throws GitLabApiException { |
| 1026 | + Response response = get(Response.Status.OK, null, "user", "emails"); |
| 1027 | + return (response.readEntity(new GenericType<List<Email>>() {})); |
| 1028 | + } |
| 1029 | + |
| 1030 | + /** |
| 1031 | + * Get a list of a specified user’s emails. Available only for admin users. |
| 1032 | + * |
| 1033 | + * <pre><code>GitLab Endpoint: GET /user/:id/emails</code></pre> |
| 1034 | + * |
| 1035 | + * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance |
| 1036 | + * @return a List of Email instances for the specified user |
| 1037 | + * @throws GitLabApiException if any exception occurs |
| 1038 | + */ |
| 1039 | + public List<Email> getEmails(final Object userIdOrUsername) throws GitLabApiException { |
| 1040 | + Response response = get(Response.Status.OK, null, "users", getUserIdOrUsername(userIdOrUsername), "emails"); |
| 1041 | + return (response.readEntity(new GenericType<List<Email>>() {})); |
| 1042 | + } |
| 1043 | + |
| 1044 | + /** |
| 1045 | + * Add an email to the current user's emails. |
| 1046 | + * |
| 1047 | + * <pre><code>GitLab Endpoint: POST /user/:id/emails</code></pre> |
| 1048 | + * |
| 1049 | + * @param email the email address to add |
| 1050 | + * @return the Email instance for the added email |
| 1051 | + * @throws GitLabApiException if any exception occurs |
| 1052 | + */ |
| 1053 | + public Email addEmail(String email) throws GitLabApiException { |
| 1054 | + GitLabApiForm formData = new GitLabApiForm().withParam("email", email, true); |
| 1055 | + Response response = post(Response.Status.CREATED, formData, "user", "emails"); |
| 1056 | + return (response.readEntity(Email.class)); |
| 1057 | + } |
| 1058 | + |
| 1059 | + /** |
| 1060 | + * Get a single Email instance specified by he email ID |
| 1061 | + * |
| 1062 | + * <pre><code>GitLab Endpoint: GET /user/emails/:emailId</code></pre> |
| 1063 | + * |
| 1064 | + * @param emailId the email ID to get |
| 1065 | + * @return the Email instance for the provided email ID |
| 1066 | + * @throws GitLabApiException if any exception occurs |
| 1067 | + */ |
| 1068 | + public Email getEmail(final Long emailId) throws GitLabApiException { |
| 1069 | + Response response = get(Response.Status.CREATED, null, "user", "emails", emailId); |
| 1070 | + return (response.readEntity(Email.class)); |
| 1071 | + } |
| 1072 | + |
| 1073 | + /** |
| 1074 | + * Add an email to the user's emails. |
| 1075 | + * |
| 1076 | + * <pre><code>GitLab Endpoint: POST /user/:id/emails</code></pre> |
| 1077 | + * |
| 1078 | + * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance |
| 1079 | + * @param email the email address to add |
| 1080 | + * @param skipConfirmation skip confirmation and assume e-mail is verified - true or false (default) |
| 1081 | + * @return the Email instance for the added email |
| 1082 | + * @throws GitLabApiException if any exception occurs |
| 1083 | + */ |
| 1084 | + public Email addEmail(final Object userIdOrUsername, String email, Boolean skipConfirmation) throws GitLabApiException { |
| 1085 | + |
| 1086 | + GitLabApiForm formData = new GitLabApiForm() |
| 1087 | + .withParam("email", email, true) |
| 1088 | + .withParam("skip_confirmation ", skipConfirmation); |
| 1089 | + Response response = post(Response.Status.CREATED, formData, "users", getUserIdOrUsername(userIdOrUsername), "emails"); |
| 1090 | + return (response.readEntity(Email.class)); |
| 1091 | + } |
| 1092 | + |
| 1093 | + /** |
| 1094 | + * Deletes an email belonging to the current user. |
| 1095 | + * |
| 1096 | + * <pre><code>GitLab Endpoint: DELETE /user/emails/:emailId</code></pre> |
| 1097 | + * |
| 1098 | + * @param emailId the email ID to delete |
| 1099 | + * @throws GitLabApiException if any exception occurs |
| 1100 | + */ |
| 1101 | + public void deleteEmail(final Long emailId) throws GitLabApiException { |
| 1102 | + delete(Response.Status.NO_CONTENT, null, "user", "emails", emailId); |
| 1103 | + } |
| 1104 | + |
| 1105 | + /** |
| 1106 | + * Deletes a user's email |
| 1107 | + * |
| 1108 | + * <pre><code>GitLab Endpoint: DELETE /user/:id/emails/:emailId</code></pre> |
| 1109 | + * |
| 1110 | + * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance |
| 1111 | + * @param emailId the email ID to delete |
| 1112 | + * @throws GitLabApiException if any exception occurs |
| 1113 | + */ |
| 1114 | + public void deleteEmail(final Object userIdOrUsername, final Long emailId) throws GitLabApiException { |
| 1115 | + delete(Response.Status.NO_CONTENT, null, "users", getUserIdOrUsername(userIdOrUsername), "emails", emailId); |
| 1116 | + } |
1015 | 1117 | } |
0 commit comments