Skip to content

Commit

Permalink
Added Notifications APIs|| Refactored Class and Role names
Browse files Browse the repository at this point in the history
  • Loading branch information
Durdush committed Aug 19, 2023
1 parent ee78c9c commit d08bb33
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
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;
import com.crowdin.client.notifications.model.SendNotificationToAuthenticatedUserRequest;
import com.crowdin.client.notifications.model.SendNotificationToOrganizationMembersRequest;
import com.crowdin.client.notifications.model.SendNotificationToProjectMemberRequest;

public class NotificationsApi extends CrowdinApi {
public NotificationsApi(Credentials credentials) {
Expand All @@ -23,10 +23,9 @@ public NotificationsApi(Credentials credentials, ClientConfig 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 {
public void sendNotificationToAuthenticatedUser(SendNotificationToAuthenticatedUserRequest request) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/notify", this.url);
this.httpClient.post(builtUrl, request, new HttpRequestConfig(), Void.class);
}
Expand All @@ -39,19 +38,18 @@ public void sendNotificationToAuthenticatedUser(NotificationRequestToAuthenticat
* <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 {
public void sendNotificationToProjectMembers(Long projectId, SendNotificationToProjectMemberRequest 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 {
public void sendNotificationToOrganizationMembers(SendNotificationToOrganizationMembersRequest request) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/notify", this.url);
this.httpClient.post(builtUrl, request, new HttpRequestConfig(), Void.class);
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import lombok.Data;

@Data
public class NotificationRequestToAuthenticatedUsers {
public class SendNotificationToAuthenticatedUserRequest {
private String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.Data;

@Data
public class NotificationRequestToOrganizationMembersByRole extends NotificationRequestToOrganizationMembers{
public class SendNotificationToOrganizationMembersByRoleRequest extends SendNotificationToOrganizationMembersRequest {
private String role;
private String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.List;

@Data
public class NotificationRequestToOrganizationMembersByUserIds extends NotificationRequestToOrganizationMembers{
public class SendNotificationToOrganizationMembersByUserIdsRequest extends SendNotificationToOrganizationMembersRequest {
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 SendNotificationToOrganizationMembersRequest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.Data;

@Data
public class NotificationRequestToProjectMemberByRole extends NotificationRequestToProjectMember {
public class SendNotificationToProjectMemberByRoleRequest extends SendNotificationToProjectMemberRequest {
private String role;
private String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.List;

@Data
public class NotificationRequestToProjectMemberByUserIds extends NotificationRequestToProjectMember {
public class SendNotificationToProjectMemberByUserIdsRequest extends SendNotificationToProjectMemberRequest {
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 SendNotificationToProjectMemberRequest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

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 com.crowdin.client.notifications.model.SendNotificationToAuthenticatedUserRequest;
import com.crowdin.client.notifications.model.SendNotificationToProjectMemberRequest;
import com.crowdin.client.notifications.model.SendNotificationToProjectMemberByRoleRequest;
import org.apache.http.client.methods.HttpPost;
import org.junit.jupiter.api.Test;

Expand All @@ -29,7 +25,7 @@ public List<RequestMock> getMocks() {

@Test
public void sendNotificationToAuthenticatedUserTest(){
NotificationRequestToAuthenticatedUsers request = new NotificationRequestToAuthenticatedUsers(){{
SendNotificationToAuthenticatedUserRequest request = new SendNotificationToAuthenticatedUserRequest(){{
setMessage("Hiii...");
}};
this.getNotificationsApi().sendNotificationToAuthenticatedUser(request);
Expand All @@ -38,8 +34,8 @@ public void sendNotificationToAuthenticatedUserTest(){

@Test
public void sendNotificationToProjectMembersByRole(){
NotificationRequestToProjectMember request = new NotificationRequestToProjectMemberByRole(){{
setRole("Admin");
SendNotificationToProjectMemberRequest request = new SendNotificationToProjectMemberByRoleRequest(){{
setRole("owner");
setMessage("Hiii...");
}};
this.getNotificationsApi().sendNotificationToProjectMembers(projectId,request);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"role": "Admin",
"role": "owner",
"message": "New notification message to Admin"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"role": "Admin",
"role": "owner",
"message": "Hiii..."
}

0 comments on commit d08bb33

Please sign in to comment.