Skip to content

Commit 8732649

Browse files
Merge pull request #1 from zyLiu-aftership/master
feat: [POM-15844] Init java SDK
1 parent 236fbe5 commit 8732649

File tree

214 files changed

+13156
-1
lines changed

Some content is hidden

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

214 files changed

+13156
-1
lines changed

.github/workflows/maven-publish.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This workflow will build a Java project with Maven
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3+
4+
name: Maven Package
5+
6+
on:
7+
release:
8+
types: [created]
9+
10+
jobs:
11+
publish:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Set up Maven Central Repository
16+
uses: actions/setup-java@v2
17+
with:
18+
java-version: '8'
19+
distribution: 'adopt'
20+
server-id: ossrh
21+
server-username: MAVEN_USERNAME
22+
server-password: MAVEN_PASSWORD
23+
- id: install-secret-key
24+
name: Install gpg secret key
25+
run: |
26+
cat <(echo -e "${{ secrets.GPG_SECRET_KEY }}") | gpg --batch --import
27+
gpg --list-secret-keys --keyid-format LONG
28+
- name: Publish package
29+
env:
30+
MAVEN_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
31+
MAVEN_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
32+
run: mvn --no-transfer-progress --batch-mode -Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }} clean deploy

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 AfterShip
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 487 additions & 1 deletion
Large diffs are not rendered by default.

pom.xml

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.aftership</groupId>
8+
<artifactId>shipping-sdk</artifactId>
9+
<version>2.0.0</version>
10+
11+
<name>AfterShip Shipping SDK</name>
12+
<description>The official AfterShip Shipping Java API library</description>
13+
<url>https://github.com/AfterShip/shipping-sdk-java</url>
14+
15+
<licenses>
16+
<license>
17+
<name>MIT License</name>
18+
<url>https://github.com/AfterShip/shipping-sdk-java/blob/master/LICENSE.txt</url>
19+
<distribution>repo</distribution>
20+
</license>
21+
</licenses>
22+
23+
<issueManagement>
24+
<url>https://github.com/AfterShip/shipping-sdk-java/issues</url>
25+
<system>GitHub</system>
26+
</issueManagement>
27+
28+
<developers>
29+
<developer>
30+
<name>AfterShip</name>
31+
<email>[email protected]</email>
32+
<organizationUrl>https://aftership.com</organizationUrl>
33+
</developer>
34+
</developers>
35+
36+
<scm>
37+
<connection>scm:git:git://github.com/AfterShip/shipping-sdk-java.git</connection>
38+
<developerConnection>scm:git:ssh://github.com:AfterShip/shipping-sdk-java.git</developerConnection>
39+
<url>https://github.com/AfterShip/shipping-sdk-java/tree/master</url>
40+
</scm>
41+
42+
<properties>
43+
<maven.compiler.source>8</maven.compiler.source>
44+
<maven.compiler.target>8</maven.compiler.target>
45+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
46+
</properties>
47+
<dependencies>
48+
<dependency>
49+
<groupId>org.bouncycastle</groupId>
50+
<artifactId>bcprov-jdk18on</artifactId>
51+
<version>1.78</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>com.google.code.gson</groupId>
55+
<artifactId>gson</artifactId>
56+
<version>2.10.1</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.apache.httpcomponents</groupId>
60+
<artifactId>httpclient</artifactId>
61+
<version>4.5.14</version>
62+
<exclusions>
63+
<exclusion>
64+
<groupId>commons-codec</groupId>
65+
<artifactId>commons-codec</artifactId>
66+
</exclusion>
67+
</exclusions>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.apache.httpcomponents</groupId>
71+
<artifactId>httpcore</artifactId>
72+
<version>4.4.13</version>
73+
</dependency>
74+
</dependencies>
75+
76+
<distributionManagement>
77+
<snapshotRepository>
78+
<id>ossrh</id>
79+
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
80+
</snapshotRepository>
81+
<repository>
82+
<id>ossrh</id>
83+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
84+
</repository>
85+
</distributionManagement>
86+
87+
<build>
88+
<plugins>
89+
<plugin>
90+
<groupId>org.apache.maven.plugins</groupId>
91+
<artifactId>maven-javadoc-plugin</artifactId>
92+
<version>3.0.0</version>
93+
<configuration>
94+
<additionalOptions>
95+
<additionalOption>-Xdoclint:none</additionalOption>
96+
</additionalOptions>
97+
</configuration>
98+
</plugin>
99+
<!-- Source -->
100+
<plugin>
101+
<groupId>org.apache.maven.plugins</groupId>
102+
<artifactId>maven-source-plugin</artifactId>
103+
<executions>
104+
<execution>
105+
<phase>package</phase>
106+
<goals>
107+
<goal>jar-no-fork</goal>
108+
</goals>
109+
</execution>
110+
</executions>
111+
</plugin>
112+
<!-- Javadoc -->
113+
<plugin>
114+
<groupId>org.apache.maven.plugins</groupId>
115+
<artifactId>maven-javadoc-plugin</artifactId>
116+
<version>3.2.0</version>
117+
<configuration>
118+
<additionalOptions>
119+
<additionalOption>-Xdoclint:none</additionalOption>
120+
</additionalOptions>
121+
</configuration>
122+
<executions>
123+
<execution>
124+
<phase>package</phase>
125+
<goals>
126+
<goal>jar</goal>
127+
</goals>
128+
</execution>
129+
</executions>
130+
</plugin>
131+
<plugin>
132+
<groupId>org.apache.maven.plugins</groupId>
133+
<artifactId>maven-gpg-plugin</artifactId>
134+
<executions>
135+
<execution>
136+
<id>sign-artifacts</id>
137+
<phase>verify</phase>
138+
<goals>
139+
<goal>sign</goal>
140+
</goals>
141+
</execution>
142+
</executions>
143+
<configuration>
144+
<gpgArguments>
145+
<argument>--pinentry-mode</argument>
146+
<argument>loopback</argument>
147+
</gpgArguments>
148+
</configuration>
149+
</plugin>
150+
<plugin>
151+
<groupId>org.sonatype.plugins</groupId>
152+
<artifactId>nexus-staging-maven-plugin</artifactId>
153+
<extensions>true</extensions>
154+
<configuration>
155+
<serverId>ossrh</serverId>
156+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
157+
<autoReleaseAfterClose>true</autoReleaseAfterClose>
158+
</configuration>
159+
</plugin>
160+
</plugins>
161+
</build>
162+
163+
</project>
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*
2+
* This code was auto generated by AfterShip SDK Generator.
3+
* Do not edit the class manually.
4+
*/
5+
package com.aftership;
6+
7+
import com.aftership.auth.AuthType;
8+
import com.aftership.constant.ErrorEnum;
9+
import com.aftership.exception.ApiException;
10+
import com.aftership.http.AfterShipClient;
11+
12+
public class AfterShip {
13+
private static final String DEFAULT_DOMAIN = "https://sandbox-api.aftership.com";
14+
private static final int DEFAULT_TIMEOUT = 10000;
15+
private static final int DEFAULT_MAX_RETRY = 2;
16+
private static AfterShipClient client;
17+
18+
private static String apiKey = System.getenv("AFTERSHIP_SHIPPING_SDK_API_KEY");
19+
private static String apiSecret = System.getenv("AFTERSHIP_SHIPPING_SDK_API_SECRET");
20+
private static AuthType authType;
21+
22+
private static String domain = System.getenv("AFTERSHIP_SHIPPING_SDK_DOMAIN");
23+
private static Integer maxRetry;
24+
private static Integer timeout;
25+
private static String userAgent = System.getenv("AFTERSHIP_SHIPPING_SDK_USER_AGENT");
26+
private static String proxy = System.getenv("AFTERSHIP_SHIPPING_SDK_PROXY");
27+
28+
private AfterShip() {
29+
}
30+
31+
public static synchronized void init(final String apiKey) {
32+
AfterShip.apiKey = apiKey;
33+
}
34+
35+
public static synchronized void init(final String apiKey, final String apiSecret, AuthType authType) {
36+
AfterShip.apiKey = apiKey;
37+
AfterShip.apiSecret = apiSecret;
38+
AfterShip.authType = authType;
39+
}
40+
41+
private static void getAuthType() {
42+
if (authType != null) {
43+
return;
44+
}
45+
String auth = System.getenv("AFTERSHIP_SHIPPING_SDK_AUTHENTICATION_TYPE");
46+
if (auth != null && !auth.isEmpty()) {
47+
auth = auth.toUpperCase();
48+
if (auth.equals(AuthType.AES.name())) {
49+
authType = AuthType.AES;
50+
return;
51+
}
52+
if (auth.equals(AuthType.RSA.name())) {
53+
authType = AuthType.RSA;
54+
return;
55+
}
56+
}
57+
authType = AuthType.APIKEY;
58+
}
59+
60+
private static Integer getIntegerFromEnv(String envName, Integer defaultValue) {
61+
String envValue = System.getenv(envName);
62+
if (envValue == null) {
63+
return defaultValue;
64+
}
65+
if (envValue.isEmpty()) {
66+
return defaultValue;
67+
}
68+
try {
69+
return Integer.parseInt(envValue);
70+
} catch (NumberFormatException e) {
71+
return defaultValue;
72+
}
73+
}
74+
75+
public static AfterShipClient getRestClient() throws Exception {
76+
if (client == null) {
77+
client = buildRestClient();
78+
}
79+
return client;
80+
}
81+
82+
private static AfterShipClient buildRestClient() throws Exception {
83+
getAuthType();
84+
if (apiKey == null || apiKey.isEmpty()) {
85+
throw new ApiException(ErrorEnum.INVALID_API_KEY.name(), "Invalid option `apiKey`");
86+
}
87+
if (AuthType.AES.equals(authType) || AuthType.RSA.equals(authType)) {
88+
if (apiSecret == null || apiSecret.isEmpty()) {
89+
throw new ApiException(ErrorEnum.INVALID_API_KEY.name(), "Invalid option `apiSecret`");
90+
}
91+
}
92+
if (timeout == null) {
93+
Integer envTimeout = getIntegerFromEnv("AFTERSHIP_SHIPPING_SDK_TIMEOUT", DEFAULT_TIMEOUT);
94+
setTimeout(envTimeout);
95+
}
96+
if (maxRetry == null) {
97+
Integer envMaxRetry = getIntegerFromEnv("AFTERSHIP_SHIPPING_SDK_MAX_RETRY", DEFAULT_MAX_RETRY);
98+
setMaxRetry(envMaxRetry);
99+
}
100+
AfterShipClient.Builder builder = new AfterShipClient.Builder(apiKey, apiSecret, authType);
101+
if (domain != null && !domain.isEmpty()) {
102+
builder.setDomain(domain);
103+
} else {
104+
builder.setDomain(DEFAULT_DOMAIN);
105+
}
106+
if (userAgent != null && !userAgent.isEmpty()) {
107+
builder.setUserAgent(userAgent);
108+
}
109+
if (proxy != null && !proxy.isEmpty()) {
110+
builder.setProxy(proxy);
111+
}
112+
return builder.setTimeout(timeout)
113+
.setMaxRetry(maxRetry)
114+
.build();
115+
}
116+
117+
public static void setDomain(final String domain) throws Exception {
118+
if (domain == null || domain.isEmpty()) {
119+
throw new ApiException(ErrorEnum.INVALID_OPTION.name(), "Invalid option `domain`");
120+
}
121+
AfterShip.domain = domain;
122+
}
123+
124+
public static void setMaxRetry(final int maxRetry) throws Exception {
125+
if (maxRetry < 0 || maxRetry > 10) {
126+
throw new ApiException(ErrorEnum.INVALID_OPTION.name(), "Invalid option `maxRetry`");
127+
}
128+
AfterShip.maxRetry = maxRetry;
129+
}
130+
131+
public static void setTimeout(final int timeout) throws Exception {
132+
if (timeout < 0) {
133+
throw new ApiException(ErrorEnum.INVALID_OPTION.name(), "Invalid option `timeout`");
134+
}
135+
AfterShip.timeout = timeout;
136+
}
137+
138+
public static void setUserAgent(final String userAgent) {
139+
AfterShip.userAgent = userAgent;
140+
}
141+
142+
public static void setProxy(final String proxy) {
143+
AfterShip.proxy = proxy;
144+
}
145+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* This code was auto generated by AfterShip SDK Generator.
3+
* Do not edit the class manually.
4+
*/
5+
package com.aftership.address_validations_beta;
6+
7+
import com.aftership.base.Resource;
8+
9+
public class AddressValidationsBetaResource extends Resource {
10+
public static PostAddressValidationsCreator postAddressValidations() {
11+
return new PostAddressValidationsCreator();
12+
}
13+
}

0 commit comments

Comments
 (0)