forked from crowdin/crowdin-api-client-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Notifications APIs|| AuthenticatedUsers, ProjectMembers, Organi…
…zationMembers
- Loading branch information
Showing
16 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/com/crowdin/client/notifications/NotificationsApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.crowdin.client.notifications; | ||
|
||
import com.crowdin.client.core.CrowdinApi; | ||
import com.crowdin.client.core.http.HttpRequestConfig; | ||
import com.crowdin.client.core.http.exceptions.HttpBadRequestException; | ||
import com.crowdin.client.core.http.exceptions.HttpException; | ||
import com.crowdin.client.core.model.ClientConfig; | ||
import com.crowdin.client.core.model.Credentials; | ||
import com.crowdin.client.notifications.model.NotificationRequestToAuthenticatedUsers; | ||
import com.crowdin.client.notifications.model.NotificationRequestToOrganizationMembers; | ||
import com.crowdin.client.notifications.model.NotificationRequestToProjectMember; | ||
|
||
public class NotificationsApi extends CrowdinApi { | ||
public NotificationsApi(Credentials credentials) { | ||
super(credentials); | ||
} | ||
|
||
public NotificationsApi(Credentials credentials, ClientConfig clientConfig) { | ||
super(credentials, clientConfig); | ||
} | ||
|
||
/** | ||
* @param request request object | ||
* @see <ul> | ||
* <li><a href="https://developer.crowdin.com/api/v2/#tag/Notifications/api.projects.notification.post" target="_blank"><b>API Documentation</b></a></li> | ||
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#tag/Notifications/api.projects.notification.post" target="_blank"><b>Enterprise API Documentation</b></a></li> | ||
* </ul> | ||
*/ | ||
public void sendNotificationToAuthenticatedUser(NotificationRequestToAuthenticatedUsers request) throws HttpException, HttpBadRequestException { | ||
String builtUrl = String.format("%s/notify", this.url); | ||
this.httpClient.post(builtUrl, request, new HttpRequestConfig(), Void.class); | ||
} | ||
|
||
/** | ||
* @param projectId Project Identifier | ||
* @param request request object | ||
* @see <ul> | ||
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.notify.post" target="_blank"><b>API Documentation</b></a></li> | ||
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.notify.post" target="_blank"><b>Enterprise API Documentation</b></a></li> | ||
* </ul> | ||
*/ | ||
public void sendNotificationToProjectMembers(Long projectId, NotificationRequestToProjectMember request) throws HttpException, HttpBadRequestException { | ||
String builtUrl = String.format("%s/projects/%d/notify", this.url, projectId); | ||
this.httpClient.post(builtUrl, request, new HttpRequestConfig(), Void.class); | ||
} | ||
|
||
/** | ||
* @param request request object | ||
* @see <ul> | ||
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.notify.post" target="_blank"><b>API Documentation</b></a></li> | ||
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.notify.post" target="_blank"><b>Enterprise API Documentation</b></a></li> | ||
* </ul> | ||
*/ | ||
public void sendNotificationToOrganizationMembers(NotificationRequestToOrganizationMembers request) throws HttpException, HttpBadRequestException { | ||
String builtUrl = String.format("%s/notify", this.url); | ||
this.httpClient.post(builtUrl, request, new HttpRequestConfig(), Void.class); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
.../java/com/crowdin/client/notifications/model/NotificationRequestToAuthenticatedUsers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.crowdin.client.notifications.model; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class NotificationRequestToAuthenticatedUsers { | ||
private String message; | ||
} |
4 changes: 4 additions & 0 deletions
4
...java/com/crowdin/client/notifications/model/NotificationRequestToOrganizationMembers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.crowdin.client.notifications.model; | ||
|
||
public abstract class NotificationRequestToOrganizationMembers { | ||
} |
9 changes: 9 additions & 0 deletions
9
...om/crowdin/client/notifications/model/NotificationRequestToOrganizationMembersByRole.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.crowdin.client.notifications.model; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class NotificationRequestToOrganizationMembersByRole extends NotificationRequestToOrganizationMembers{ | ||
private String role; | ||
private String message; | ||
} |
11 changes: 11 additions & 0 deletions
11
...crowdin/client/notifications/model/NotificationRequestToOrganizationMembersByUserIds.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.crowdin.client.notifications.model; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
public class NotificationRequestToOrganizationMembersByUserIds extends NotificationRequestToOrganizationMembers{ | ||
private List<Long> userIds; | ||
private String message; | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/crowdin/client/notifications/model/NotificationRequestToProjectMember.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.crowdin.client.notifications.model; | ||
|
||
public abstract class NotificationRequestToProjectMember { | ||
} |
9 changes: 9 additions & 0 deletions
9
...java/com/crowdin/client/notifications/model/NotificationRequestToProjectMemberByRole.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.crowdin.client.notifications.model; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class NotificationRequestToProjectMemberByRole extends NotificationRequestToProjectMember { | ||
private String role; | ||
private String message; | ||
} |
11 changes: 11 additions & 0 deletions
11
...a/com/crowdin/client/notifications/model/NotificationRequestToProjectMemberByUserIds.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.crowdin.client.notifications.model; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
public class NotificationRequestToProjectMemberByUserIds extends NotificationRequestToProjectMember { | ||
private List<Long> userIds; | ||
private String message; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/test/java/com/crowdin/client/notifications/NotificationsApiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.crowdin.client.notifications; | ||
|
||
import com.crowdin.client.framework.RequestMock; | ||
import com.crowdin.client.framework.TestClient; | ||
import com.crowdin.client.notifications.model.NotificationRequestToAuthenticatedUsers; | ||
import com.crowdin.client.notifications.model.NotificationRequestToOrganizationMembers; | ||
import com.crowdin.client.notifications.model.NotificationRequestToOrganizationMembersByRole; | ||
import com.crowdin.client.notifications.model.NotificationRequestToOrganizationMembersByUserIds; | ||
import com.crowdin.client.notifications.model.NotificationRequestToProjectMember; | ||
import com.crowdin.client.notifications.model.NotificationRequestToProjectMemberByRole; | ||
import com.crowdin.client.notifications.model.NotificationRequestToProjectMemberByUserIds; | ||
import org.apache.http.client.methods.HttpPost; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class NotificationsApiTest extends TestClient { | ||
private final Long projectId = 8L; | ||
private final List<Long> userIds = Arrays.asList(1l,2L); | ||
|
||
@Override | ||
public List<RequestMock> getMocks() { | ||
return Arrays.asList( | ||
RequestMock.buildWithRequestFileOnly(this.url + "/notify", HttpPost.METHOD_NAME,"api/notifications/notificationRequestToAuthenticatedUsers.json"), | ||
RequestMock.buildWithRequestFileOnly(String.format("%s/projects/%d/notify",this.url,projectId), HttpPost.METHOD_NAME, "api/notifications/notificationRequestToProjectMembersByRole.json") | ||
); | ||
} | ||
|
||
@Test | ||
public void sendNotificationToAuthenticatedUserTest(){ | ||
NotificationRequestToAuthenticatedUsers request = new NotificationRequestToAuthenticatedUsers(){{ | ||
setMessage("Hiii..."); | ||
}}; | ||
this.getNotificationsApi().sendNotificationToAuthenticatedUser(request); | ||
} | ||
|
||
|
||
@Test | ||
public void sendNotificationToProjectMembersByRole(){ | ||
NotificationRequestToProjectMember request = new NotificationRequestToProjectMemberByRole(){{ | ||
setRole("Admin"); | ||
setMessage("Hiii..."); | ||
}}; | ||
this.getNotificationsApi().sendNotificationToProjectMembers(projectId,request); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/test/resources/api/notifications/notificationRequestToAuthenticatedUsers.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"message": "Hiii..." | ||
} |
4 changes: 4 additions & 0 deletions
4
src/test/resources/api/notifications/notificationRequestToOrganizationMembersByRole.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"role": "Admin", | ||
"message": "New notification message to Admin" | ||
} |
6 changes: 6 additions & 0 deletions
6
src/test/resources/api/notifications/notificationRequestToOrganizationMembersByUserIds.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"userIds": [ | ||
2 | ||
], | ||
"message": "New notification message" | ||
} |
4 changes: 4 additions & 0 deletions
4
src/test/resources/api/notifications/notificationRequestToProjectMembersByRole.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"role": "Admin", | ||
"message": "Hiii..." | ||
} |
6 changes: 6 additions & 0 deletions
6
src/test/resources/api/notifications/notificationRequestToProjectMembersByUserIds.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"userIds": [ | ||
1,2 | ||
], | ||
"message": "Hiii..." | ||
} |