From f2242793a7dd085951cecaba7629732d8ebfc11a Mon Sep 17 00:00:00 2001 From: DecarteAdam Date: Wed, 8 May 2024 00:32:39 +0200 Subject: [PATCH] feat: refactored after review Renamed method for 'reportArchiveApi' to prefix 'userId' --- .../crowdin/client/reports/ReportsApi.java | 35 ++++++++++--------- .../client/reports/ReportsApiTest.java | 4 +-- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/crowdin/client/reports/ReportsApi.java b/src/main/java/com/crowdin/client/reports/ReportsApi.java index 8847164d..c3841e61 100644 --- a/src/main/java/com/crowdin/client/reports/ReportsApi.java +++ b/src/main/java/com/crowdin/client/reports/ReportsApi.java @@ -228,18 +228,18 @@ public void deleteReportSettingsTemplate(Long projectId, Long reportSettingsTemp * @return list of report settings template * @see */ public ResponseList listReportArchives(Long userId, String scopeType, Long scopeId, Integer limit, Integer offset) throws HttpException, HttpBadRequestException { - String url = getUserPrefixedUrl(userId); + String url = getReportArchivesPath(userId, "reports/archives/"); Map> queryParams = HttpRequestConfig.buildUrlParams( "scopeType", Optional.ofNullable(scopeType), "scopeId", Optional.ofNullable(scopeId), "limit", Optional.ofNullable(limit), "offset", Optional.ofNullable(offset) ); - ReportArchiveList responseObject = this.httpClient.get(url + "/reports/archives/", new HttpRequestConfig(queryParams), ReportArchiveList.class); + ReportArchiveList responseObject = this.httpClient.get(url, new HttpRequestConfig(queryParams), ReportArchiveList.class); return ReportArchiveList.to(responseObject); } @@ -253,8 +253,8 @@ public ResponseList listReportArchives(Long userId, String scopeT * */ public ResponseObject getReportArchive(Long userId, Long archiveId) throws HttpException, HttpBadRequestException { - String url = getUserPrefixedUrl(userId); - ReportArchiveResponseObject reportArchiveResponseObject = this.httpClient.get(url + "/reports/archives/" + archiveId, new HttpRequestConfig(), ReportArchiveResponseObject.class); + String url = getReportArchivesPath(userId, "reports/archives/" + archiveId); + ReportArchiveResponseObject reportArchiveResponseObject = this.httpClient.get(url, new HttpRequestConfig(), ReportArchiveResponseObject.class); return ResponseObject.of(reportArchiveResponseObject.getData()); } @@ -267,8 +267,8 @@ public ResponseObject getReportArchive(Long userId, Long archiveI * */ public void deleteReportArchive(Long userId, Long archiveId) throws HttpException, HttpBadRequestException { - String url = getUserPrefixedUrl(userId); - this.httpClient.delete(url + "/reports/archives/" + archiveId, new HttpRequestConfig(), Void.class); + String url = getReportArchivesPath(userId, "reports/archives/" + archiveId); + this.httpClient.delete(url, new HttpRequestConfig(), Void.class); } /** @@ -282,8 +282,8 @@ public void deleteReportArchive(Long userId, Long archiveId) throws HttpExceptio * */ public ResponseObject exportReportArchive(Long userId, Long archiveId, ExportReportRequest request) throws HttpException, HttpBadRequestException { - String url = getUserPrefixedUrl(userId); - GroupReportStatusResponseObject responseObject = this.httpClient.post(url + "/reports/archives/" + archiveId + "/exports", request, new HttpRequestConfig(), GroupReportStatusResponseObject.class); + String url = getReportArchivesPath(userId, "reports/archives/" + archiveId + "/exports"); + GroupReportStatusResponseObject responseObject = this.httpClient.post(url, request, new HttpRequestConfig(), GroupReportStatusResponseObject.class); return ResponseObject.of(responseObject.getData()); } @@ -296,8 +296,9 @@ public ResponseObject exportReportArchive(Long userId, Long a *
  • Enterprise API Documentation
  • * */ - public ResponseObject checkReportArchiveExportStatus(Long archiveId, String exportId) throws HttpException, HttpBadRequestException { - GroupReportStatusResponseObject responseObject = this.httpClient.get(this.url + "/reports/archives" + archiveId + "/exports/" + exportId, new HttpRequestConfig(), GroupReportStatusResponseObject.class); + public ResponseObject checkReportArchiveExportStatus(Long userId, Long archiveId, String exportId) throws HttpException, HttpBadRequestException { + String url = getReportArchivesPath(userId, "reports/archives/" + archiveId + "/exports/" + exportId); + GroupReportStatusResponseObject responseObject = this.httpClient.get(url, new HttpRequestConfig(), GroupReportStatusResponseObject.class); return ResponseObject.of(responseObject.getData()); } @@ -312,17 +313,19 @@ public ResponseObject checkReportArchiveExportStatus(Long arc * */ public ResponseObject downloadReportArchive(Long userId, Long archiveId, String exportId) throws HttpException, HttpBadRequestException { - String url = getUserPrefixedUrl(userId); - DownloadLinkResponseObject responseObject = this.httpClient.get(url + "/reports/archives" + archiveId + "/exports/" + exportId + "/download", new HttpRequestConfig(), DownloadLinkResponseObject.class); + String url = getReportArchivesPath(userId, "reports/archives" + archiveId + "/exports/" + exportId + "/download"); + DownloadLinkResponseObject responseObject = this.httpClient.get(url, new HttpRequestConfig(), DownloadLinkResponseObject.class); return ResponseObject.of(responseObject.getData()); } /** * Build an url with or without userId prefix - * @param userId user identifier + * + * @param userId user identifier (for crowdin.com only) + * @param path sub-path of the url * @return url with userId prefix if exist */ - private String getUserPrefixedUrl(Long userId) { - return userId != null ? this.url + "/users/" + userId : this.url; + private String getReportArchivesPath(Long userId, String path) { + return userId != null ? String.format("%s/users/%d/%s", this.url, userId, path) : String.format("%s/%s", this.url, path); } } diff --git a/src/test/java/com/crowdin/client/reports/ReportsApiTest.java b/src/test/java/com/crowdin/client/reports/ReportsApiTest.java index cc3ea2da..0073acd2 100644 --- a/src/test/java/com/crowdin/client/reports/ReportsApiTest.java +++ b/src/test/java/com/crowdin/client/reports/ReportsApiTest.java @@ -59,7 +59,7 @@ public List getMocks() { RequestMock.build(this.url + "/users/" + userId + "/reports/archives/" + archiveId, HttpGet.METHOD_NAME, "api/reports/reportArchive.json"), RequestMock.build(this.url + "/users/" + userId + "/reports/archives/" + archiveId, HttpDelete.METHOD_NAME), RequestMock.build(this.url + "/users/" + userId + "/reports/archives/" + archiveId + "/exports", HttpPost.METHOD_NAME, "api/reports/exportReportArchiveReques.json", "api/reports/reportGenerationStatus.json"), - RequestMock.build(this.url + "/reports/archives" + archiveId + "/exports/" + exportId, HttpGet.METHOD_NAME, "api/reports/reportGenerationStatus.json"), + RequestMock.build(this.url + "/users/" + userId + "/reports/archives/" + archiveId + "/exports/" + exportId, HttpGet.METHOD_NAME, "api/reports/reportGenerationStatus.json"), RequestMock.build(this.url + "/users/" + userId + "/reports/archives" + archiveId + "/exports/" + exportId + "/download", HttpGet.METHOD_NAME, "api/reports/downloadLink.json")); } @@ -215,7 +215,7 @@ public void exportReportArchiveTest() { @Test public void checkReportArchiveExportStatusTest() { - ResponseObject reportStatusResponseObject = this.getReportsApi().checkReportArchiveExportStatus(archiveId, exportId); + ResponseObject reportStatusResponseObject = this.getReportsApi().checkReportArchiveExportStatus(userId, archiveId, exportId); assertEquals(reportStatusResponseObject.getData().getIdentifier(), id); }