Skip to content

Commit

Permalink
Added Notifications APIs|| AuthenticatedUsers, ProjectMembers, Organi…
Browse files Browse the repository at this point in the history
…zationMembers
  • Loading branch information
Durdush committed Aug 14, 2023
1 parent 6061f2d commit ee78c9c
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/crowdin/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.crowdin.client.labels.LabelsApi;
import com.crowdin.client.languages.LanguagesApi;
import com.crowdin.client.machinetranslationengines.MachineTranslationEnginesApi;
import com.crowdin.client.notifications.NotificationsApi;
import com.crowdin.client.projectsgroups.ProjectsGroupsApi;
import com.crowdin.client.reports.ReportsApi;
import com.crowdin.client.screenshots.ScreenshotsApi;
Expand Down Expand Up @@ -60,6 +61,7 @@ public class Client extends CrowdinApi {
private final LabelsApi labelsApi;
private final StringCommentsApi stringCommentsApi;
private final BundlesApi bundlesApi;
private final NotificationsApi notificationsApi;

public Client(Credentials credentials) {
super(credentials);
Expand Down Expand Up @@ -89,6 +91,7 @@ public Client(Credentials credentials) {
this.labelsApi = new LabelsApi(credentials);
this.stringCommentsApi = new StringCommentsApi(credentials);
this.bundlesApi = new BundlesApi(credentials);
this.notificationsApi = new NotificationsApi(credentials);
}

public Client(Credentials credentials, ClientConfig clientConfig) {
Expand Down Expand Up @@ -119,6 +122,7 @@ public Client(Credentials credentials, ClientConfig clientConfig) {
this.labelsApi = new LabelsApi(credentials, clientConfig);
this.stringCommentsApi = new StringCommentsApi(credentials, clientConfig);
this.bundlesApi = new BundlesApi(credentials, clientConfig);
this.notificationsApi = new NotificationsApi(credentials, clientConfig);
}

}
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);
}

}
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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.crowdin.client.notifications.model;

public abstract class NotificationRequestToOrganizationMembers {
}
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;
}
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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.crowdin.client.notifications.model;

public abstract class NotificationRequestToProjectMember {
}
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;
}
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;
}
11 changes: 11 additions & 0 deletions src/test/java/com/crowdin/client/framework/RequestMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,15 @@ public static RequestMock build(String url, String httpMethod) {
Collections.emptyMap()
);
}

public static RequestMock buildWithRequestFileOnly(String url, String httpMethod, String requestFile) {
return new RequestMock(
url,
requestFile,
null,
httpMethod,
Collections.emptyMap(),
Collections.emptyMap()
);
}
}
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"message": "Hiii..."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"role": "Admin",
"message": "New notification message to Admin"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"userIds": [
2
],
"message": "New notification message"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"role": "Admin",
"message": "Hiii..."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"userIds": [
1,2
],
"message": "Hiii..."
}

0 comments on commit ee78c9c

Please sign in to comment.