From 21d299df879faccaa2c49fac6ce115d6e74da4b2 Mon Sep 17 00:00:00 2001 From: jchen293 Date: Thu, 7 Dec 2023 13:47:55 -0500 Subject: [PATCH 1/8] add allChildren function --- CHANGELOG.md | 5 + .../java/com/easypost/model/Children.java | 12 +++ .../easypost/model/ChildrenCollection.java | 25 +++++ .../com/easypost/service/UserService.java | 35 +++++++ src/test/cassettes/user/all_children.json | 94 +++++++++++++++++++ src/test/cassettes/user/get_next_page.json | 91 ++++++++++++++++++ src/test/java/com/easypost/UserTest.java | 57 +++++++++++ 7 files changed, 319 insertions(+) create mode 100644 src/main/java/com/easypost/model/Children.java create mode 100644 src/main/java/com/easypost/model/ChildrenCollection.java create mode 100644 src/test/cassettes/user/all_children.json create mode 100644 src/test/cassettes/user/get_next_page.json diff --git a/CHANGELOG.md b/CHANGELOG.md index f0f3bb759..45f40f02a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## Next release + +- Adds `allChildren` function in User service to get a paginated list of children +- Adds `getNextPage` function in User service to get next paginated list of children + ## v7.0.1 (2023-12-08) - Adds the `object` field to all models; previously, most models were missing this field. diff --git a/src/main/java/com/easypost/model/Children.java b/src/main/java/com/easypost/model/Children.java new file mode 100644 index 000000000..a08db0533 --- /dev/null +++ b/src/main/java/com/easypost/model/Children.java @@ -0,0 +1,12 @@ +package com.easypost.model; + +import java.util.List; + +public class Children extends EasyPostResource { + private String parentId; + private String name; + private String phoneNumber; + private Boolean verified; + private Boolean defaultCarbonOffset; + private List apiKeys; +} diff --git a/src/main/java/com/easypost/model/ChildrenCollection.java b/src/main/java/com/easypost/model/ChildrenCollection.java new file mode 100644 index 000000000..b9c8669d2 --- /dev/null +++ b/src/main/java/com/easypost/model/ChildrenCollection.java @@ -0,0 +1,25 @@ +package com.easypost.model; + +import java.util.List; +import java.util.Map; + +import lombok.Getter; + +@Getter +public final class ChildrenCollection extends PaginatedCollection { + private List children; + + @Override + protected Map buildNextPageParameters(List children, Integer pageSize) { + String lastId = children.get(children.size() - 1).getId(); + + Map parameters = new java.util.HashMap<>(); + parameters.put("before_id", lastId); + + if (pageSize != null) { + parameters.put("page_size", pageSize); + } + + return parameters; + } +} diff --git a/src/main/java/com/easypost/service/UserService.java b/src/main/java/com/easypost/service/UserService.java index 25d69df2f..f46ae1305 100644 --- a/src/main/java/com/easypost/service/UserService.java +++ b/src/main/java/com/easypost/service/UserService.java @@ -2,18 +2,23 @@ import com.easypost.Constants; import com.easypost.exception.EasyPostException; +import com.easypost.exception.General.EndOfPaginationError; import com.easypost.exception.General.FilteringError; import com.easypost.http.Requestor; import com.easypost.http.Requestor.RequestMethod; import com.easypost.model.ApiKey; import com.easypost.model.ApiKeys; import com.easypost.model.Brand; +import com.easypost.model.ChildrenCollection; import com.easypost.model.User; +import lombok.SneakyThrows; + import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.function.Function; public class UserService { private final EasyPostClient client; @@ -137,4 +142,34 @@ public Brand updateBrand(final String id, final Map params) thro return Requestor.request(RequestMethod.PUT, endpoint, wrappedParams, Brand.class, client); } + + /** + * Retrieve the paginated list of children of a user. + * + * @param params Map of parameters. + * @return ChildCollection object. + * @throws EasyPostException when the request fails. + */ + public ChildrenCollection allChildren(final Map params) throws EasyPostException { + String endpoint = "users/children"; + + return Requestor.request(RequestMethod.GET, endpoint, params, ChildrenCollection.class, client, "beta"); + } + + /** + * Get the next page of an ChildrenCollection. + * + * @param collection ChildrenCollection to get next page of. + * @param pageSize The number of results to return on the next page. + * @return ChildrenCollection object. + * @throws EndOfPaginationError when there are no more pages to retrieve. + */ + public ChildrenCollection getNextPage(ChildrenCollection collection, Integer pageSize) throws EndOfPaginationError { + return collection.getNextPage(new Function, ChildrenCollection>() { + @Override @SneakyThrows + public ChildrenCollection apply(Map parameters) { + return allChildren(parameters); + } + }, collection.getChildren(), pageSize); + } } diff --git a/src/test/cassettes/user/all_children.json b/src/test/cassettes/user/all_children.json new file mode 100644 index 000000000..4e42570ac --- /dev/null +++ b/src/test/cassettes/user/all_children.json @@ -0,0 +1,94 @@ +[ + { + "recordedAt": 1702314914, + "request": { + "body": "", + "method": "GET", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ] + }, + "uri": "https://api.easypost.com/beta/users/children?%70%61%67%65%5F%73%69%7A%65\u003d%35" + }, + "response": { + "body": "{\n \"children\": [\n {\n \"parent_id\": \"user_54356a6b96c940d8913961a3c7b909f2\",\n \"name\": \"Test User2\",\n \"verified\": true,\n \"created_at\": \"2023-12-11T17:13:38Z\",\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_584be78af2f141e988b6c60dda9dd8fd\",\n \"object\": \"User\"\n },\n {\n \"parent_id\": \"user_54356a6b96c940d8913961a3c7b909f2\",\n \"name\": \"Test User2\",\n \"verified\": true,\n \"created_at\": \"2023-12-11T17:13:43Z\",\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_437e724f37de412db6df8821968d8d3c\",\n \"object\": \"User\"\n }\n ],\n \"has_more\": false\n}", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 200 OK" + ], + "content-length": [ + "461" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb43nuq" + ], + "vary": [ + "Origin" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-backend": [ + "easypost" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-download-options": [ + "noopen" + ], + "strict-transport-security": [ + "max-age\u003d31536000; includeSubDomains; preload" + ], + "pragma": [ + "no-cache" + ], + "x-canary": [ + "direct" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-xss-protection": [ + "1; mode\u003dblock" + ], + "x-ep-request-uuid": [ + "76c4c42b657743a2e79b0b290013bf5e" + ], + "x-proxied": [ + "extlb1nuq 003ad9bca0", + "intlb1nuq b3de2c47ef" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.052884" + ], + "content-type": [ + "application/json; charset\u003dutf-8" + ], + "x-version-label": [ + "easypost-202312082253-518d5f5344-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "uri": "https://api.easypost.com/beta/users/children?%70%61%67%65%5F%73%69%7A%65\u003d%35" + }, + "duration": 435 + } +] \ No newline at end of file diff --git a/src/test/cassettes/user/get_next_page.json b/src/test/cassettes/user/get_next_page.json new file mode 100644 index 000000000..376f262ae --- /dev/null +++ b/src/test/cassettes/user/get_next_page.json @@ -0,0 +1,91 @@ +[ + { + "recordedAt": 1702314913, + "request": { + "body": "", + "method": "GET", + "headers": { + "Accept-Charset": [ + "UTF-8" + ], + "User-Agent": [ + "REDACTED" + ] + }, + "uri": "https://api.easypost.com/beta/users/children?%70%61%67%65%5F%73%69%7A%65\u003d%35" + }, + "response": { + "body": "{\n \"children\": [\n {\n \"parent_id\": \"user_54356a6b96c940d8913961a3c7b909f2\",\n \"name\": \"Test User2\",\n \"verified\": true,\n \"created_at\": \"2023-12-11T17:13:38Z\",\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_584be78af2f141e988b6c60dda9dd8fd\",\n \"object\": \"User\"\n },\n {\n \"parent_id\": \"user_54356a6b96c940d8913961a3c7b909f2\",\n \"name\": \"Test User2\",\n \"verified\": true,\n \"created_at\": \"2023-12-11T17:13:43Z\",\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_437e724f37de412db6df8821968d8d3c\",\n \"object\": \"User\"\n }\n ],\n \"has_more\": false\n}", + "httpVersion": null, + "headers": { + "null": [ + "HTTP/1.1 200 OK" + ], + "content-length": [ + "461" + ], + "expires": [ + "0" + ], + "x-node": [ + "bigweb41nuq" + ], + "vary": [ + "Origin" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-backend": [ + "easypost" + ], + "x-permitted-cross-domain-policies": [ + "none" + ], + "x-download-options": [ + "noopen" + ], + "strict-transport-security": [ + "max-age\u003d31536000; includeSubDomains; preload" + ], + "pragma": [ + "no-cache" + ], + "x-content-type-options": [ + "nosniff" + ], + "x-xss-protection": [ + "1; mode\u003dblock" + ], + "x-ep-request-uuid": [ + "76c4c429657743a1e79b0b250013bd7d" + ], + "x-proxied": [ + "extlb1nuq 003ad9bca0", + "intlb2nuq b3de2c47ef" + ], + "referrer-policy": [ + "strict-origin-when-cross-origin" + ], + "x-runtime": [ + "0.057947" + ], + "content-type": [ + "application/json; charset\u003dutf-8" + ], + "x-version-label": [ + "easypost-202312082253-518d5f5344-master" + ], + "cache-control": [ + "private, no-cache, no-store" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "uri": "https://api.easypost.com/beta/users/children?%70%61%67%65%5F%73%69%7A%65\u003d%35" + }, + "duration": 439 + } +] \ No newline at end of file diff --git a/src/test/java/com/easypost/UserTest.java b/src/test/java/com/easypost/UserTest.java index 4cb51ca3b..976d44053 100644 --- a/src/test/java/com/easypost/UserTest.java +++ b/src/test/java/com/easypost/UserTest.java @@ -1,19 +1,26 @@ package com.easypost; import com.easypost.exception.EasyPostException; +import com.easypost.exception.General.EndOfPaginationError; import com.easypost.model.Brand; +import com.easypost.model.Children; +import com.easypost.model.ChildrenCollection; import com.easypost.model.User; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import java.util.HashMap; +import java.util.List; import java.util.Map; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public final class UserTest { private static String testUserId = null; @@ -177,4 +184,54 @@ public void testUpdateBrand() throws EasyPostException { assertTrue(brand.getId().startsWith("brd_")); assertEquals(color, brand.getColor()); } + + /** + * Test retrieving a paginated list of children. + * + * @throws EasyPostException when the request fails. + */ + @Test + public void testAllChildren() throws EasyPostException { + vcr.setUpTest("all_children"); + + Map params = new HashMap<>(); + params.put("page_size", Fixtures.pageSize()); + + ChildrenCollection children = vcr.client.user.allChildren(params); + + List childrenList = children.getChildren(); + + assertTrue(childrenList.size() <= Fixtures.pageSize()); + assertNotNull(children.getHasMore()); + assertTrue(childrenList.stream().allMatch(children_user -> children_user != null)); + } + + /** + * Test retrieving the next page. + * + * @throws EasyPostException when the request fails. + */ + @Test + public void testGetNextPage() throws EasyPostException { + vcr.setUpTest("get_next_page"); + + Map params = new HashMap<>(); + params.put("page_size", Fixtures.pageSize()); + ChildrenCollection collection = vcr.client.user.allChildren(params); + + try { + ChildrenCollection nextPage = vcr.client.user.getNextPage(collection, Fixtures.pageSize()); + + assertNotNull(nextPage); + + String firstIdOfFirstPage = collection.getChildren().get(0).getId(); + String firstIdOfSecondPage = nextPage.getChildren().get(0).getId(); + + assertNotEquals(firstIdOfFirstPage, firstIdOfSecondPage); + } catch (EndOfPaginationError e) { // There's no next page, that's not a failure + assertTrue(true); + } catch (Exception e) { // Any other exception is a failure + fail(); + } + } } From 803a60406ba48f559de762957675f92bb781c291 Mon Sep 17 00:00:00 2001 From: jchen293 Date: Thu, 4 Jan 2024 13:49:02 -0500 Subject: [PATCH 2/8] use GA endpoint --- .../com/easypost/service/UserService.java | 2 +- src/test/cassettes/user/all_children.json | 30 ++++++++----------- src/test/cassettes/user/get_next_page.json | 30 +++++++++---------- 3 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/easypost/service/UserService.java b/src/main/java/com/easypost/service/UserService.java index f46ae1305..3a68a0678 100644 --- a/src/main/java/com/easypost/service/UserService.java +++ b/src/main/java/com/easypost/service/UserService.java @@ -153,7 +153,7 @@ public Brand updateBrand(final String id, final Map params) thro public ChildrenCollection allChildren(final Map params) throws EasyPostException { String endpoint = "users/children"; - return Requestor.request(RequestMethod.GET, endpoint, params, ChildrenCollection.class, client, "beta"); + return Requestor.request(RequestMethod.GET, endpoint, params, ChildrenCollection.class, client); } /** diff --git a/src/test/cassettes/user/all_children.json b/src/test/cassettes/user/all_children.json index 4e42570ac..485cb59ae 100644 --- a/src/test/cassettes/user/all_children.json +++ b/src/test/cassettes/user/all_children.json @@ -1,6 +1,6 @@ [ { - "recordedAt": 1702314914, + "recordedAt": 1704394018, "request": { "body": "", "method": "GET", @@ -12,26 +12,23 @@ "REDACTED" ] }, - "uri": "https://api.easypost.com/beta/users/children?%70%61%67%65%5F%73%69%7A%65\u003d%35" + "uri": "https://api.easypost.com/v2/users/children?%70%61%67%65%5F%73%69%7A%65\u003d%35" }, "response": { - "body": "{\n \"children\": [\n {\n \"parent_id\": \"user_54356a6b96c940d8913961a3c7b909f2\",\n \"name\": \"Test User2\",\n \"verified\": true,\n \"created_at\": \"2023-12-11T17:13:38Z\",\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_584be78af2f141e988b6c60dda9dd8fd\",\n \"object\": \"User\"\n },\n {\n \"parent_id\": \"user_54356a6b96c940d8913961a3c7b909f2\",\n \"name\": \"Test User2\",\n \"verified\": true,\n \"created_at\": \"2023-12-11T17:13:43Z\",\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_437e724f37de412db6df8821968d8d3c\",\n \"object\": \"User\"\n }\n ],\n \"has_more\": false\n}", + "body": "{\n \"children\": [\n {\n \"parent_id\": \"user_0f6b83e3530b401cb1e8aeaa6a250d4d\",\n \"name\": \"Test User\",\n \"verified\": true,\n \"created_at\": \"2023-05-16T22:01:20Z\",\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_484dd58db70a4f31b4bb862998cf0e04\",\n \"object\": \"User\"\n },\n {\n \"parent_id\": \"user_0f6b83e3530b401cb1e8aeaa6a250d4d\",\n \"name\": \"Test User\",\n \"verified\": true,\n \"created_at\": \"2023-09-27T22:05:26Z\",\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_14e894c0d541459395f4456e7cf4f175\",\n \"object\": \"User\"\n },\n {\n \"parent_id\": \"user_0f6b83e3530b401cb1e8aeaa6a250d4d\",\n \"name\": \"Test User\",\n \"verified\": true,\n \"created_at\": \"2023-11-30T19:23:22Z\",\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_f04df3dad13848339a7975d295d6629f\",\n \"object\": \"User\"\n }\n ],\n \"has_more\": false\n}", "httpVersion": null, "headers": { "null": [ "HTTP/1.1 200 OK" ], "content-length": [ - "461" + "673" ], "expires": [ "0" ], "x-node": [ - "bigweb43nuq" - ], - "vary": [ - "Origin" + "bigweb34nuq" ], "x-frame-options": [ "SAMEORIGIN" @@ -51,9 +48,6 @@ "pragma": [ "no-cache" ], - "x-canary": [ - "direct" - ], "x-content-type-options": [ "nosniff" ], @@ -61,23 +55,23 @@ "1; mode\u003dblock" ], "x-ep-request-uuid": [ - "76c4c42b657743a2e79b0b290013bf5e" + "3c78c40b6596fd22e799facc000653b1" ], "x-proxied": [ - "extlb1nuq 003ad9bca0", - "intlb1nuq b3de2c47ef" + "extlb2nuq 003ad9bca0", + "intlb2nuq 2c48984abf" ], "referrer-policy": [ "strict-origin-when-cross-origin" ], "x-runtime": [ - "0.052884" + "0.039539" ], "content-type": [ "application/json; charset\u003dutf-8" ], "x-version-label": [ - "easypost-202312082253-518d5f5344-master" + "easypost-202401041812-437974c716-master" ], "cache-control": [ "private, no-cache, no-store" @@ -87,8 +81,8 @@ "code": 200, "message": "OK" }, - "uri": "https://api.easypost.com/beta/users/children?%70%61%67%65%5F%73%69%7A%65\u003d%35" + "uri": "https://api.easypost.com/v2/users/children?%70%61%67%65%5F%73%69%7A%65\u003d%35" }, - "duration": 435 + "duration": 420 } ] \ No newline at end of file diff --git a/src/test/cassettes/user/get_next_page.json b/src/test/cassettes/user/get_next_page.json index 376f262ae..68dfc51cb 100644 --- a/src/test/cassettes/user/get_next_page.json +++ b/src/test/cassettes/user/get_next_page.json @@ -1,6 +1,6 @@ [ { - "recordedAt": 1702314913, + "recordedAt": 1704394017, "request": { "body": "", "method": "GET", @@ -12,26 +12,23 @@ "REDACTED" ] }, - "uri": "https://api.easypost.com/beta/users/children?%70%61%67%65%5F%73%69%7A%65\u003d%35" + "uri": "https://api.easypost.com/v2/users/children?%70%61%67%65%5F%73%69%7A%65\u003d%35" }, "response": { - "body": "{\n \"children\": [\n {\n \"parent_id\": \"user_54356a6b96c940d8913961a3c7b909f2\",\n \"name\": \"Test User2\",\n \"verified\": true,\n \"created_at\": \"2023-12-11T17:13:38Z\",\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_584be78af2f141e988b6c60dda9dd8fd\",\n \"object\": \"User\"\n },\n {\n \"parent_id\": \"user_54356a6b96c940d8913961a3c7b909f2\",\n \"name\": \"Test User2\",\n \"verified\": true,\n \"created_at\": \"2023-12-11T17:13:43Z\",\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_437e724f37de412db6df8821968d8d3c\",\n \"object\": \"User\"\n }\n ],\n \"has_more\": false\n}", + "body": "{\n \"children\": [\n {\n \"parent_id\": \"user_0f6b83e3530b401cb1e8aeaa6a250d4d\",\n \"name\": \"Test User\",\n \"verified\": true,\n \"created_at\": \"2023-05-16T22:01:20Z\",\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_484dd58db70a4f31b4bb862998cf0e04\",\n \"object\": \"User\"\n },\n {\n \"parent_id\": \"user_0f6b83e3530b401cb1e8aeaa6a250d4d\",\n \"name\": \"Test User\",\n \"verified\": true,\n \"created_at\": \"2023-09-27T22:05:26Z\",\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_14e894c0d541459395f4456e7cf4f175\",\n \"object\": \"User\"\n },\n {\n \"parent_id\": \"user_0f6b83e3530b401cb1e8aeaa6a250d4d\",\n \"name\": \"Test User\",\n \"verified\": true,\n \"created_at\": \"2023-11-30T19:23:22Z\",\n \"phone_number\": \"REDACTED\",\n \"id\": \"user_f04df3dad13848339a7975d295d6629f\",\n \"object\": \"User\"\n }\n ],\n \"has_more\": false\n}", "httpVersion": null, "headers": { "null": [ "HTTP/1.1 200 OK" ], "content-length": [ - "461" + "673" ], "expires": [ "0" ], "x-node": [ - "bigweb41nuq" - ], - "vary": [ - "Origin" + "bigweb32nuq" ], "x-frame-options": [ "SAMEORIGIN" @@ -51,6 +48,9 @@ "pragma": [ "no-cache" ], + "x-canary": [ + "direct" + ], "x-content-type-options": [ "nosniff" ], @@ -58,23 +58,23 @@ "1; mode\u003dblock" ], "x-ep-request-uuid": [ - "76c4c429657743a1e79b0b250013bd7d" + "3c78c4086596fd20e799fac90006528a" ], "x-proxied": [ - "extlb1nuq 003ad9bca0", - "intlb2nuq b3de2c47ef" + "extlb2nuq 003ad9bca0", + "intlb2nuq 2c48984abf" ], "referrer-policy": [ "strict-origin-when-cross-origin" ], "x-runtime": [ - "0.057947" + "0.193572" ], "content-type": [ "application/json; charset\u003dutf-8" ], "x-version-label": [ - "easypost-202312082253-518d5f5344-master" + "easypost-202401041812-437974c716-master" ], "cache-control": [ "private, no-cache, no-store" @@ -84,8 +84,8 @@ "code": 200, "message": "OK" }, - "uri": "https://api.easypost.com/beta/users/children?%70%61%67%65%5F%73%69%7A%65\u003d%35" + "uri": "https://api.easypost.com/v2/users/children?%70%61%67%65%5F%73%69%7A%65\u003d%35" }, - "duration": 439 + "duration": 594 } ] \ No newline at end of file From c5a7aa16472843931cf742f35f8bc7aba74dfb2f Mon Sep 17 00:00:00 2001 From: jchen293 Date: Thu, 4 Jan 2024 15:18:17 -0500 Subject: [PATCH 3/8] address feedback --- src/main/java/com/easypost/model/Children.java | 3 ++- src/main/java/com/easypost/service/UserService.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/easypost/model/Children.java b/src/main/java/com/easypost/model/Children.java index a08db0533..31aaf7dca 100644 --- a/src/main/java/com/easypost/model/Children.java +++ b/src/main/java/com/easypost/model/Children.java @@ -1,12 +1,13 @@ package com.easypost.model; import java.util.List; +import lombok.Getter; +@Getter public class Children extends EasyPostResource { private String parentId; private String name; private String phoneNumber; private Boolean verified; - private Boolean defaultCarbonOffset; private List apiKeys; } diff --git a/src/main/java/com/easypost/service/UserService.java b/src/main/java/com/easypost/service/UserService.java index 3a68a0678..77039bd11 100644 --- a/src/main/java/com/easypost/service/UserService.java +++ b/src/main/java/com/easypost/service/UserService.java @@ -144,7 +144,7 @@ public Brand updateBrand(final String id, final Map params) thro } /** - * Retrieve the paginated list of children of a user. + * Retrieve the paginated list of children for the authenticated user. * * @param params Map of parameters. * @return ChildCollection object. @@ -157,7 +157,7 @@ public ChildrenCollection allChildren(final Map params) throws E } /** - * Get the next page of an ChildrenCollection. + * Get the next page of a ChildrenCollection. * * @param collection ChildrenCollection to get next page of. * @param pageSize The number of results to return on the next page. From 0bcedc546fe66791928ff3d3390e3dbe875c9f5e Mon Sep 17 00:00:00 2001 From: jchen293 Date: Thu, 4 Jan 2024 15:41:56 -0500 Subject: [PATCH 4/8] change children to child --- CHANGELOG.md | 4 ++-- .../model/{Children.java => Child.java} | 2 +- ...enCollection.java => ChildCollection.java} | 6 +++--- .../com/easypost/service/UserService.java | 20 +++++++++---------- src/test/java/com/easypost/UserTest.java | 12 +++++------ 5 files changed, 22 insertions(+), 22 deletions(-) rename src/main/java/com/easypost/model/{Children.java => Child.java} (82%) rename src/main/java/com/easypost/model/{ChildrenCollection.java => ChildCollection.java} (76%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45f40f02a..ccba14f06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,8 @@ ## Next release -- Adds `allChildren` function in User service to get a paginated list of children -- Adds `getNextPage` function in User service to get next paginated list of children +- Adds `allChildren` function in User service to get a paginated list of child users +- Adds `getNextPage` function in User service to get next paginated list of child users ## v7.0.1 (2023-12-08) diff --git a/src/main/java/com/easypost/model/Children.java b/src/main/java/com/easypost/model/Child.java similarity index 82% rename from src/main/java/com/easypost/model/Children.java rename to src/main/java/com/easypost/model/Child.java index 31aaf7dca..b00a81397 100644 --- a/src/main/java/com/easypost/model/Children.java +++ b/src/main/java/com/easypost/model/Child.java @@ -4,7 +4,7 @@ import lombok.Getter; @Getter -public class Children extends EasyPostResource { +public class Child extends EasyPostResource { private String parentId; private String name; private String phoneNumber; diff --git a/src/main/java/com/easypost/model/ChildrenCollection.java b/src/main/java/com/easypost/model/ChildCollection.java similarity index 76% rename from src/main/java/com/easypost/model/ChildrenCollection.java rename to src/main/java/com/easypost/model/ChildCollection.java index b9c8669d2..51e55d95b 100644 --- a/src/main/java/com/easypost/model/ChildrenCollection.java +++ b/src/main/java/com/easypost/model/ChildCollection.java @@ -6,11 +6,11 @@ import lombok.Getter; @Getter -public final class ChildrenCollection extends PaginatedCollection { - private List children; +public final class ChildCollection extends PaginatedCollection { + private List children; @Override - protected Map buildNextPageParameters(List children, Integer pageSize) { + protected Map buildNextPageParameters(List children, Integer pageSize) { String lastId = children.get(children.size() - 1).getId(); Map parameters = new java.util.HashMap<>(); diff --git a/src/main/java/com/easypost/service/UserService.java b/src/main/java/com/easypost/service/UserService.java index 77039bd11..b6afb238d 100644 --- a/src/main/java/com/easypost/service/UserService.java +++ b/src/main/java/com/easypost/service/UserService.java @@ -9,7 +9,7 @@ import com.easypost.model.ApiKey; import com.easypost.model.ApiKeys; import com.easypost.model.Brand; -import com.easypost.model.ChildrenCollection; +import com.easypost.model.ChildCollection; import com.easypost.model.User; import lombok.SneakyThrows; @@ -144,30 +144,30 @@ public Brand updateBrand(final String id, final Map params) thro } /** - * Retrieve the paginated list of children for the authenticated user. + * Retrieve the paginated list of child users for the authenticated user. * * @param params Map of parameters. * @return ChildCollection object. * @throws EasyPostException when the request fails. */ - public ChildrenCollection allChildren(final Map params) throws EasyPostException { + public ChildCollection allChildren(final Map params) throws EasyPostException { String endpoint = "users/children"; - return Requestor.request(RequestMethod.GET, endpoint, params, ChildrenCollection.class, client); + return Requestor.request(RequestMethod.GET, endpoint, params, ChildCollection.class, client); } /** - * Get the next page of a ChildrenCollection. + * Get the next page of a ChildCollection. * - * @param collection ChildrenCollection to get next page of. + * @param collection ChildCollection to get next page of. * @param pageSize The number of results to return on the next page. - * @return ChildrenCollection object. + * @return ChildCollection object. * @throws EndOfPaginationError when there are no more pages to retrieve. */ - public ChildrenCollection getNextPage(ChildrenCollection collection, Integer pageSize) throws EndOfPaginationError { - return collection.getNextPage(new Function, ChildrenCollection>() { + public ChildCollection getNextPage(ChildCollection collection, Integer pageSize) throws EndOfPaginationError { + return collection.getNextPage(new Function, ChildCollection>() { @Override @SneakyThrows - public ChildrenCollection apply(Map parameters) { + public ChildCollection apply(Map parameters) { return allChildren(parameters); } }, collection.getChildren(), pageSize); diff --git a/src/test/java/com/easypost/UserTest.java b/src/test/java/com/easypost/UserTest.java index 976d44053..b3d2a64ce 100644 --- a/src/test/java/com/easypost/UserTest.java +++ b/src/test/java/com/easypost/UserTest.java @@ -3,8 +3,8 @@ import com.easypost.exception.EasyPostException; import com.easypost.exception.General.EndOfPaginationError; import com.easypost.model.Brand; -import com.easypost.model.Children; -import com.easypost.model.ChildrenCollection; +import com.easypost.model.Child; +import com.easypost.model.ChildCollection; import com.easypost.model.User; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; @@ -197,9 +197,9 @@ public void testAllChildren() throws EasyPostException { Map params = new HashMap<>(); params.put("page_size", Fixtures.pageSize()); - ChildrenCollection children = vcr.client.user.allChildren(params); + ChildCollection children = vcr.client.user.allChildren(params); - List childrenList = children.getChildren(); + List childrenList = children.getChildren(); assertTrue(childrenList.size() <= Fixtures.pageSize()); assertNotNull(children.getHasMore()); @@ -217,10 +217,10 @@ public void testGetNextPage() throws EasyPostException { Map params = new HashMap<>(); params.put("page_size", Fixtures.pageSize()); - ChildrenCollection collection = vcr.client.user.allChildren(params); + ChildCollection collection = vcr.client.user.allChildren(params); try { - ChildrenCollection nextPage = vcr.client.user.getNextPage(collection, Fixtures.pageSize()); + ChildCollection nextPage = vcr.client.user.getNextPage(collection, Fixtures.pageSize()); assertNotNull(nextPage); From 2ae52735fa8220296613866ac85995a9baa86965 Mon Sep 17 00:00:00 2001 From: jchen293 Date: Thu, 4 Jan 2024 15:56:52 -0500 Subject: [PATCH 5/8] rename child to childuser --- .../model/{Child.java => ChildUser.java} | 2 +- ...llection.java => ChildUserCollection.java} | 6 +++--- .../com/easypost/service/UserService.java | 20 +++++++++---------- src/test/java/com/easypost/UserTest.java | 14 ++++++------- 4 files changed, 21 insertions(+), 21 deletions(-) rename src/main/java/com/easypost/model/{Child.java => ChildUser.java} (82%) rename src/main/java/com/easypost/model/{ChildCollection.java => ChildUserCollection.java} (75%) diff --git a/src/main/java/com/easypost/model/Child.java b/src/main/java/com/easypost/model/ChildUser.java similarity index 82% rename from src/main/java/com/easypost/model/Child.java rename to src/main/java/com/easypost/model/ChildUser.java index b00a81397..0d25b556e 100644 --- a/src/main/java/com/easypost/model/Child.java +++ b/src/main/java/com/easypost/model/ChildUser.java @@ -4,7 +4,7 @@ import lombok.Getter; @Getter -public class Child extends EasyPostResource { +public class ChildUser extends EasyPostResource { private String parentId; private String name; private String phoneNumber; diff --git a/src/main/java/com/easypost/model/ChildCollection.java b/src/main/java/com/easypost/model/ChildUserCollection.java similarity index 75% rename from src/main/java/com/easypost/model/ChildCollection.java rename to src/main/java/com/easypost/model/ChildUserCollection.java index 51e55d95b..4c5707445 100644 --- a/src/main/java/com/easypost/model/ChildCollection.java +++ b/src/main/java/com/easypost/model/ChildUserCollection.java @@ -6,11 +6,11 @@ import lombok.Getter; @Getter -public final class ChildCollection extends PaginatedCollection { - private List children; +public final class ChildUserCollection extends PaginatedCollection { + private List children; @Override - protected Map buildNextPageParameters(List children, Integer pageSize) { + protected Map buildNextPageParameters(List children, Integer pageSize) { String lastId = children.get(children.size() - 1).getId(); Map parameters = new java.util.HashMap<>(); diff --git a/src/main/java/com/easypost/service/UserService.java b/src/main/java/com/easypost/service/UserService.java index b6afb238d..dbb737e35 100644 --- a/src/main/java/com/easypost/service/UserService.java +++ b/src/main/java/com/easypost/service/UserService.java @@ -9,7 +9,7 @@ import com.easypost.model.ApiKey; import com.easypost.model.ApiKeys; import com.easypost.model.Brand; -import com.easypost.model.ChildCollection; +import com.easypost.model.ChildUserCollection; import com.easypost.model.User; import lombok.SneakyThrows; @@ -147,27 +147,27 @@ public Brand updateBrand(final String id, final Map params) thro * Retrieve the paginated list of child users for the authenticated user. * * @param params Map of parameters. - * @return ChildCollection object. + * @return ChildUserCollection object. * @throws EasyPostException when the request fails. */ - public ChildCollection allChildren(final Map params) throws EasyPostException { + public ChildUserCollection allChildren(final Map params) throws EasyPostException { String endpoint = "users/children"; - return Requestor.request(RequestMethod.GET, endpoint, params, ChildCollection.class, client); + return Requestor.request(RequestMethod.GET, endpoint, params, ChildUserCollection.class, client); } /** - * Get the next page of a ChildCollection. + * Get the next page of a ChildUserCollection. * - * @param collection ChildCollection to get next page of. + * @param collection ChildUserCollection to get next page of. * @param pageSize The number of results to return on the next page. - * @return ChildCollection object. + * @return ChildUserCollection object. * @throws EndOfPaginationError when there are no more pages to retrieve. */ - public ChildCollection getNextPage(ChildCollection collection, Integer pageSize) throws EndOfPaginationError { - return collection.getNextPage(new Function, ChildCollection>() { + public ChildUserCollection getNextPage(ChildUserCollection collection, Integer pageSize) throws EndOfPaginationError { + return collection.getNextPage(new Function, ChildUserCollection>() { @Override @SneakyThrows - public ChildCollection apply(Map parameters) { + public ChildUserCollection apply(Map parameters) { return allChildren(parameters); } }, collection.getChildren(), pageSize); diff --git a/src/test/java/com/easypost/UserTest.java b/src/test/java/com/easypost/UserTest.java index b3d2a64ce..387653fc6 100644 --- a/src/test/java/com/easypost/UserTest.java +++ b/src/test/java/com/easypost/UserTest.java @@ -3,8 +3,8 @@ import com.easypost.exception.EasyPostException; import com.easypost.exception.General.EndOfPaginationError; import com.easypost.model.Brand; -import com.easypost.model.Child; -import com.easypost.model.ChildCollection; +import com.easypost.model.ChildUser; +import com.easypost.model.ChildUserCollection; import com.easypost.model.User; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; @@ -197,9 +197,9 @@ public void testAllChildren() throws EasyPostException { Map params = new HashMap<>(); params.put("page_size", Fixtures.pageSize()); - ChildCollection children = vcr.client.user.allChildren(params); + ChildUserCollection children = vcr.client.user.allChildren(params); - List childrenList = children.getChildren(); + List childrenList = children.getChildren(); assertTrue(childrenList.size() <= Fixtures.pageSize()); assertNotNull(children.getHasMore()); @@ -207,7 +207,7 @@ public void testAllChildren() throws EasyPostException { } /** - * Test retrieving the next page. + * Test retrieving the next page of child users. * * @throws EasyPostException when the request fails. */ @@ -217,10 +217,10 @@ public void testGetNextPage() throws EasyPostException { Map params = new HashMap<>(); params.put("page_size", Fixtures.pageSize()); - ChildCollection collection = vcr.client.user.allChildren(params); + ChildUserCollection collection = vcr.client.user.allChildren(params); try { - ChildCollection nextPage = vcr.client.user.getNextPage(collection, Fixtures.pageSize()); + ChildUserCollection nextPage = vcr.client.user.getNextPage(collection, Fixtures.pageSize()); assertNotNull(nextPage); From aac4d670ae57990410dfa35483235394478ac94f Mon Sep 17 00:00:00 2001 From: jchen293 Date: Thu, 4 Jan 2024 16:28:44 -0500 Subject: [PATCH 6/8] use User as Child --- src/main/java/com/easypost/model/ChildUser.java | 13 ------------- .../com/easypost/model/ChildUserCollection.java | 6 +++--- src/test/java/com/easypost/UserTest.java | 2 +- 3 files changed, 4 insertions(+), 17 deletions(-) delete mode 100644 src/main/java/com/easypost/model/ChildUser.java diff --git a/src/main/java/com/easypost/model/ChildUser.java b/src/main/java/com/easypost/model/ChildUser.java deleted file mode 100644 index 0d25b556e..000000000 --- a/src/main/java/com/easypost/model/ChildUser.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.easypost.model; - -import java.util.List; -import lombok.Getter; - -@Getter -public class ChildUser extends EasyPostResource { - private String parentId; - private String name; - private String phoneNumber; - private Boolean verified; - private List apiKeys; -} diff --git a/src/main/java/com/easypost/model/ChildUserCollection.java b/src/main/java/com/easypost/model/ChildUserCollection.java index 4c5707445..0d99d67ac 100644 --- a/src/main/java/com/easypost/model/ChildUserCollection.java +++ b/src/main/java/com/easypost/model/ChildUserCollection.java @@ -6,11 +6,11 @@ import lombok.Getter; @Getter -public final class ChildUserCollection extends PaginatedCollection { - private List children; +public final class ChildUserCollection extends PaginatedCollection { + private List children; @Override - protected Map buildNextPageParameters(List children, Integer pageSize) { + protected Map buildNextPageParameters(List children, Integer pageSize) { String lastId = children.get(children.size() - 1).getId(); Map parameters = new java.util.HashMap<>(); diff --git a/src/test/java/com/easypost/UserTest.java b/src/test/java/com/easypost/UserTest.java index 387653fc6..ae663b01f 100644 --- a/src/test/java/com/easypost/UserTest.java +++ b/src/test/java/com/easypost/UserTest.java @@ -199,7 +199,7 @@ public void testAllChildren() throws EasyPostException { ChildUserCollection children = vcr.client.user.allChildren(params); - List childrenList = children.getChildren(); + List childrenList = children.getChildren(); assertTrue(childrenList.size() <= Fixtures.pageSize()); assertNotNull(children.getHasMore()); From affe39b0fa73d0777220ef3203f9c7f5e5c0e891 Mon Sep 17 00:00:00 2001 From: jchen293 Date: Thu, 4 Jan 2024 16:30:20 -0500 Subject: [PATCH 7/8] remove unused import --- src/test/java/com/easypost/UserTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/easypost/UserTest.java b/src/test/java/com/easypost/UserTest.java index ae663b01f..b33ee2bcf 100644 --- a/src/test/java/com/easypost/UserTest.java +++ b/src/test/java/com/easypost/UserTest.java @@ -3,7 +3,6 @@ import com.easypost.exception.EasyPostException; import com.easypost.exception.General.EndOfPaginationError; import com.easypost.model.Brand; -import com.easypost.model.ChildUser; import com.easypost.model.ChildUserCollection; import com.easypost.model.User; import org.junit.jupiter.api.AfterEach; From 87d25bd0fd07eff60941fc2ef6f1d0974dfca5ca Mon Sep 17 00:00:00 2001 From: jchen293 Date: Thu, 4 Jan 2024 16:31:46 -0500 Subject: [PATCH 8/8] fix lint --- src/main/java/com/easypost/service/UserService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/easypost/service/UserService.java b/src/main/java/com/easypost/service/UserService.java index dbb737e35..44d67a57f 100644 --- a/src/main/java/com/easypost/service/UserService.java +++ b/src/main/java/com/easypost/service/UserService.java @@ -164,7 +164,8 @@ public ChildUserCollection allChildren(final Map params) throws * @return ChildUserCollection object. * @throws EndOfPaginationError when there are no more pages to retrieve. */ - public ChildUserCollection getNextPage(ChildUserCollection collection, Integer pageSize) throws EndOfPaginationError { + public ChildUserCollection getNextPage(ChildUserCollection collection, Integer pageSize) + throws EndOfPaginationError { return collection.getNextPage(new Function, ChildUserCollection>() { @Override @SneakyThrows public ChildUserCollection apply(Map parameters) {