Skip to content

Commit f682dae

Browse files
author
Watson Zuo
committed
support 2025-04 version
1 parent fb09285 commit f682dae

File tree

87 files changed

+1419
-724
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1419
-724
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Default ignored files
2+
.idea
3+
.target
4+
target

README.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ If you need support using AfterShip products, please contact [email protected]
2222
- [Endpoints](#endpoints)
2323
- [/trackings](#trackings)
2424
- [/couriers](#couriers)
25+
- [/courier-connections](#courier-connections)
2526
- [/estimated-delivery-date](#estimated-delivery-date)
2627
- [Help](#help)
2728
- [License](#license)
@@ -41,6 +42,7 @@ Each SDK version is designed to work with a specific API version. Please refer t
4142

4243
| SDK Version | Supported API Version | Branch |
4344
| ----------- | --------------------- | ----------------------------------------------------------- |
45+
| 9.x.x | 2025-04 | https://github.com/AfterShip/tracking-sdk-java/tree/2025-04 |
4446
| 8.x.x | 2025-01 | https://github.com/AfterShip/tracking-sdk-java/tree/2025-01 |
4547
| 7.x.x | 2024-10 | https://github.com/AfterShip/tracking-sdk-java/tree/2024-10 |
4648
| 6.x.x | 2024-07 | https://github.com/AfterShip/tracking-sdk-java/tree/2024-07 |
@@ -55,7 +57,7 @@ Each SDK version is designed to work with a specific API version. Please refer t
5557
<dependency>
5658
<groupId>com.aftership</groupId>
5759
<artifactId>tracking-sdk</artifactId>
58-
<version>8.0.0</version>
60+
<version>9.0.0</version>
5961
</dependency>
6062
```
6163

@@ -106,7 +108,7 @@ public class App {
106108

107109
## Rate Limiter
108110

109-
See the [Rate Limit](https://www.aftership.com/docs/tracking/2025-01/quickstart/rate-limit) to understand the AfterShip rate limit policy.
111+
See the [Rate Limit](https://www.aftership.com/docs/tracking/2025-04/quickstart/rate-limit) to understand the AfterShip rate limit policy.
110112

111113
## Error Handling
112114

@@ -155,6 +157,7 @@ The AfterShip instance has the following properties which are exactly the same a
155157

156158
- courier - Get a list of our supported couriers.
157159
- tracking - Create trackings, update trackings, and get tracking results.
160+
- courier-connection - Create courier connections, update courier connections, and get courier connections results.
158161
- estimated-delivery-date - Get estimated delivery date for your order.
159162

160163
### /trackings
@@ -235,14 +238,7 @@ System.out.println(response.getTrackingNumber());
235238
**GET** /couriers
236239

237240
```java
238-
GetUserCouriersResponse response = CourierResource.getUserCouriers().fetch();
239-
System.out.println(response.getTotal());
240-
```
241-
242-
**GET** /couriers/all
243-
244-
```java
245-
GetAllCouriersResponse response = CourierResource.getAllCouriers().fetch();
241+
GetUserCouriersResponse response = CourierResource.getCouriers().fetch();
246242
System.out.println(response.getTotal());
247243
```
248244

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.aftership</groupId>
88
<artifactId>tracking-sdk</artifactId>
9-
<version>8.0.0</version>
9+
<version>9.0.0</version>
1010

1111
<name>AfterShip Tracking SDK</name>
1212
<description>The official AfterShip Tracking Java API library</description>

src/main/java/com/aftership/constant/ErrorEnum.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ public enum ErrorEnum {
6464
"You have exceeded the API call rate limit. The default limit is 10 requests per second."),
6565
INTERNAL_ERROR(500, 500, "Something went wrong on AfterShip's end.");
6666

67+
private final int code;
68+
69+
private final int statusCode;
70+
71+
private final String message;
72+
6773
private static final Map<Integer, ErrorEnum> META = new HashMap<>();
6874

6975
static {
@@ -72,24 +78,12 @@ public enum ErrorEnum {
7278
}
7379
}
7480

75-
private final int code;
76-
private final int statusCode;
77-
private final String message;
78-
7981
ErrorEnum(int code, int statusCode, String message) {
8082
this.code = code;
8183
this.statusCode = statusCode;
8284
this.message = message;
8385
}
8486

85-
public static int getByMetaCode(int code) {
86-
ErrorEnum e = META.get(code);
87-
if (e == null) {
88-
return BAD_REQUEST.code;
89-
}
90-
return e.code;
91-
}
92-
9387
public int getCode() {
9488
return code;
9589
}
@@ -102,6 +96,14 @@ public String getMessage() {
10296
return message;
10397
}
10498

99+
public static int getByMetaCode(int code) {
100+
ErrorEnum e = META.get(code);
101+
if (e == null) {
102+
return BAD_REQUEST.code;
103+
}
104+
return e.code;
105+
}
106+
105107
@Override
106108
public String toString() {
107109
return "ErrorEnum{" + "code=" + code + ", message='" + message + '\'' + '}';

src/main/java/com/aftership/courier/CourierResource.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ public static DetectCourierCreator detectCourier() {
1111
return new DetectCourierCreator();
1212
}
1313

14-
public static GetUserCouriersFetcher getUserCouriers() {
15-
return new GetUserCouriersFetcher();
16-
}
17-
18-
public static GetAllCouriersFetcher getAllCouriers() {
19-
return new GetAllCouriersFetcher();
14+
public static GetCouriersFetcher getCouriers() {
15+
return new GetCouriersFetcher();
2016
}
2117
}

src/main/java/com/aftership/courier/DetectCourierCreator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com.aftership.base.Creator;
88
import com.aftership.http.*;
9+
import com.aftership.http.Request;
910
import com.aftership.model.DetectCourierRequest;
1011
import com.aftership.model.DetectCourierResponse;
1112
import com.google.gson.Gson;
@@ -15,7 +16,6 @@
1516

1617
public class DetectCourierCreator extends Creator<DetectCourierResponse> {
1718
private final Map<String, String> headerParams = new HashMap<>(8);
18-
private DetectCourierRequest detectCourierRequest;
1919

2020
public DetectCourierCreator addHeaderParam(final String name, final String value) {
2121
if (value == null || value.equals("null")) {
@@ -34,14 +34,16 @@ private void setHeaderParams(final Request request) {
3434
}
3535
}
3636

37+
private DetectCourierRequest detectCourierRequest;
38+
3739
public DetectCourierCreator setDetectCourierRequest(DetectCourierRequest detectCourierRequest) {
3840
this.detectCourierRequest = detectCourierRequest;
3941
return this;
4042
}
4143

4244
@Override
4345
public DetectCourierResponse create(AfterShipClient client) throws Exception {
44-
String path = "/tracking/2025-01/couriers/detect";
46+
String path = "/tracking/2025-04/couriers/detect";
4547
Request request = new Request(HttpMethod.POST, path);
4648
request.setBody((new Gson()).toJson(detectCourierRequest));
4749

src/main/java/com/aftership/courier/GetAllCouriersFetcher.java renamed to src/main/java/com/aftership/courier/GetCouriersFetcher.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66

77
import com.aftership.base.Fetcher;
88
import com.aftership.http.*;
9-
import com.aftership.model.GetAllCouriersResponse;
9+
import com.aftership.http.Request;
10+
import com.aftership.model.GetCouriersResponse;
1011
import com.google.gson.Gson;
1112
import com.google.gson.reflect.TypeToken;
1213
import java.util.HashMap;
1314
import java.util.Map;
1415

15-
public class GetAllCouriersFetcher extends Fetcher<GetAllCouriersResponse> {
16+
public class GetCouriersFetcher extends Fetcher<GetCouriersResponse> {
1617
private final Map<String, String> headerParams = new HashMap<>(8);
1718

18-
public GetAllCouriersFetcher addHeaderParam(final String name, final String value) {
19+
public GetCouriersFetcher addHeaderParam(final String name, final String value) {
1920
if (value == null || value.equals("null")) {
2021
return this;
2122
}
@@ -32,17 +33,41 @@ private void setHeaderParams(final Request request) {
3233
}
3334
}
3435

36+
private Boolean active;
37+
38+
private String slug;
39+
40+
public GetCouriersFetcher setActive(Boolean active) {
41+
this.active = active;
42+
return this;
43+
}
44+
45+
public GetCouriersFetcher setSlug(String slug) {
46+
this.slug = slug;
47+
return this;
48+
}
49+
3550
@Override
36-
public GetAllCouriersResponse fetch(AfterShipClient client) throws Exception {
37-
String path = "/tracking/2025-01/couriers/all";
51+
public GetCouriersResponse fetch(AfterShipClient client) throws Exception {
52+
String path = "/tracking/2025-04/couriers";
3853
Request request = new Request(HttpMethod.GET, path);
54+
addQueryParams(request);
3955
setHeaderParams(request);
4056
Response response = client.request(request);
41-
AfterShipResponse<GetAllCouriersResponse> trackingResponse =
57+
AfterShipResponse<GetCouriersResponse> trackingResponse =
4258
new Gson()
4359
.fromJson(
4460
response.getContent(),
45-
new TypeToken<AfterShipResponse<GetAllCouriersResponse>>() {}.getType());
61+
new TypeToken<AfterShipResponse<GetCouriersResponse>>() {}.getType());
4662
return trackingResponse.getData();
4763
}
64+
65+
private void addQueryParams(final Request request) {
66+
if (active != null) {
67+
request.addQueryParam("active", String.valueOf(active));
68+
}
69+
if (slug != null) {
70+
request.addQueryParam("slug", slug);
71+
}
72+
}
4873
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* This code was auto generated by AfterShip SDK Generator.
3+
* Do not edit the class manually.
4+
*/
5+
package com.aftership.courier_connection;
6+
7+
import com.aftership.base.Resource;
8+
9+
public class CourierConnectionResource extends Resource {
10+
public static GetCourierConnectionsByIdFetcher getCourierConnectionsById() {
11+
return new GetCourierConnectionsByIdFetcher();
12+
}
13+
14+
public static GetCourierConnectionsReader getCourierConnections() {
15+
return new GetCourierConnectionsReader();
16+
}
17+
18+
public static PutCourierConnectionsByIdUpdater putCourierConnectionsById() {
19+
return new PutCourierConnectionsByIdUpdater();
20+
}
21+
22+
public static DeleteCourierConnectionsByIdDeleter deleteCourierConnectionsById() {
23+
return new DeleteCourierConnectionsByIdDeleter();
24+
}
25+
26+
public static PostCourierConnectionsCreator postCourierConnections() {
27+
return new PostCourierConnectionsCreator();
28+
}
29+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* This code was auto generated by AfterShip SDK Generator.
3+
* Do not edit the class manually.
4+
*/
5+
package com.aftership.courier_connection;
6+
7+
import com.aftership.base.Deleter;
8+
import com.aftership.constant.ErrorEnum;
9+
import com.aftership.exception.ApiException;
10+
import com.aftership.http.*;
11+
import com.aftership.http.Request;
12+
import com.aftership.model.CourierConnection;
13+
import com.google.gson.Gson;
14+
import com.google.gson.reflect.TypeToken;
15+
import java.util.HashMap;
16+
import java.util.Map;
17+
18+
public class DeleteCourierConnectionsByIdDeleter extends Deleter<CourierConnection> {
19+
private final Map<String, String> headerParams = new HashMap<>(8);
20+
21+
public DeleteCourierConnectionsByIdDeleter addHeaderParam(final String name, final String value) {
22+
if (value == null || value.equals("null")) {
23+
return this;
24+
}
25+
26+
if (!headerParams.containsKey(name)) {
27+
headerParams.put(name, value);
28+
}
29+
return this;
30+
}
31+
32+
private void setHeaderParams(final Request request) {
33+
for (final Map.Entry<String, String> entry : headerParams.entrySet()) {
34+
request.addHeaderParam(entry.getKey(), entry.getValue());
35+
}
36+
}
37+
38+
private String id;
39+
40+
public DeleteCourierConnectionsByIdDeleter setId(String id) {
41+
this.id = id;
42+
return this;
43+
}
44+
45+
@Override
46+
public CourierConnection delete(AfterShipClient client) throws Exception {
47+
if (id == null || id.isEmpty()) {
48+
throw new ApiException(
49+
ErrorEnum.BAD_REQUEST.getCode(),
50+
ErrorEnum.BAD_REQUEST.getMessage() + ": `id` is invalid");
51+
}
52+
String path = String.format("/tracking/2025-04/courier-connections/%s", id);
53+
Request request = new Request(HttpMethod.DELETE, path);
54+
setHeaderParams(request);
55+
Response response = client.request(request);
56+
AfterShipResponse<CourierConnection> trackingResponse =
57+
new Gson()
58+
.fromJson(
59+
response.getContent(),
60+
new TypeToken<AfterShipResponse<CourierConnection>>() {}.getType());
61+
return trackingResponse.getData();
62+
}
63+
}

src/main/java/com/aftership/courier/GetUserCouriersFetcher.java renamed to src/main/java/com/aftership/courier_connection/GetCourierConnectionsByIdFetcher.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22
* This code was auto generated by AfterShip SDK Generator.
33
* Do not edit the class manually.
44
*/
5-
package com.aftership.courier;
5+
package com.aftership.courier_connection;
66

77
import com.aftership.base.Fetcher;
8+
import com.aftership.constant.ErrorEnum;
9+
import com.aftership.exception.ApiException;
810
import com.aftership.http.*;
9-
import com.aftership.model.GetUserCouriersResponse;
11+
import com.aftership.http.Request;
12+
import com.aftership.model.CourierConnection;
1013
import com.google.gson.Gson;
1114
import com.google.gson.reflect.TypeToken;
1215
import java.util.HashMap;
1316
import java.util.Map;
1417

15-
public class GetUserCouriersFetcher extends Fetcher<GetUserCouriersResponse> {
18+
public class GetCourierConnectionsByIdFetcher extends Fetcher<CourierConnection> {
1619
private final Map<String, String> headerParams = new HashMap<>(8);
1720

18-
public GetUserCouriersFetcher addHeaderParam(final String name, final String value) {
21+
public GetCourierConnectionsByIdFetcher addHeaderParam(final String name, final String value) {
1922
if (value == null || value.equals("null")) {
2023
return this;
2124
}
@@ -32,17 +35,29 @@ private void setHeaderParams(final Request request) {
3235
}
3336
}
3437

38+
private String id;
39+
40+
public GetCourierConnectionsByIdFetcher setId(String id) {
41+
this.id = id;
42+
return this;
43+
}
44+
3545
@Override
36-
public GetUserCouriersResponse fetch(AfterShipClient client) throws Exception {
37-
String path = "/tracking/2025-01/couriers";
46+
public CourierConnection fetch(AfterShipClient client) throws Exception {
47+
if (id == null || id.isEmpty()) {
48+
throw new ApiException(
49+
ErrorEnum.BAD_REQUEST.getCode(),
50+
ErrorEnum.BAD_REQUEST.getMessage() + ": `id` is invalid");
51+
}
52+
String path = String.format("/tracking/2025-04/courier-connections/%s", id);
3853
Request request = new Request(HttpMethod.GET, path);
3954
setHeaderParams(request);
4055
Response response = client.request(request);
41-
AfterShipResponse<GetUserCouriersResponse> trackingResponse =
56+
AfterShipResponse<CourierConnection> trackingResponse =
4257
new Gson()
4358
.fromJson(
4459
response.getContent(),
45-
new TypeToken<AfterShipResponse<GetUserCouriersResponse>>() {}.getType());
60+
new TypeToken<AfterShipResponse<CourierConnection>>() {}.getType());
4661
return trackingResponse.getData();
4762
}
4863
}

0 commit comments

Comments
 (0)