Skip to content

Commit

Permalink
Merge pull request #5 from panxl6/2024-10
Browse files Browse the repository at this point in the history
feat: supporting 2024-10 version.
  • Loading branch information
panxl6 authored Oct 25, 2024
2 parents d0078ac + 4f684cd commit ed6c806
Show file tree
Hide file tree
Showing 141 changed files with 14,830 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Maven Package

on:
release:
types: [created]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Maven Central Repository
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
- id: install-secret-key
name: Install gpg secret key
run: |
cat <(echo -e "${{ secrets.GPG_SECRET_KEY }}") | gpg --batch --import
gpg --list-secret-keys --keyid-format LONG
- name: Publish package
env:
MAVEN_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
run: mvn --no-transfer-progress --batch-mode -Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }} clean deploy
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/
.vscode/
target/
22 changes: 22 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2024 AfterShip

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
296 changes: 295 additions & 1 deletion README.md

Large diffs are not rendered by default.

163 changes: 163 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.aftership</groupId>
<artifactId>tracking-sdk</artifactId>
<version>7.0.0</version>

<name>AfterShip Tracking SDK</name>
<description>The official AfterShip Tracking Java API library</description>
<url>https://github.com/AfterShip/tracking-sdk-java</url>

<licenses>
<license>
<name>MIT License</name>
<url>https://github.com/AfterShip/tracking-sdk-java/blob/master/LICENSE.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<issueManagement>
<url>https://github.com/AfterShip/tracking-sdk-java/issues</url>
<system>GitHub</system>
</issueManagement>

<developers>
<developer>
<name>AfterShip</name>
<email>[email protected]</email>
<organizationUrl>https://aftership.com</organizationUrl>
</developer>
</developers>

<scm>
<connection>scm:git:git://github.com/AfterShip/tracking-sdk-java.git</connection>
<developerConnection>scm:git:ssh://github.com:AfterShip/tracking-sdk-java.git</developerConnection>
<url>https://github.com/AfterShip/tracking-sdk-java/tree/master</url>
</scm>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>1.78</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
<exclusions>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.13</version>
</dependency>
</dependencies>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<additionalOptions>
<additionalOption>-Xdoclint:none</additionalOption>
</additionalOptions>
</configuration>
</plugin>
<!-- Source -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<additionalOptions>
<additionalOption>-Xdoclint:none</additionalOption>
</additionalOptions>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<gpgArguments>
<argument>--pinentry-mode</argument>
<argument>loopback</argument>
</gpgArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>

</project>
145 changes: 145 additions & 0 deletions src/main/java/com/aftership/AfterShip.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* This code was auto generated by AfterShip SDK Generator.
* Do not edit the class manually.
*/
package com.aftership;

import com.aftership.auth.AuthType;
import com.aftership.constant.ErrorEnum;
import com.aftership.exception.ApiException;
import com.aftership.http.AfterShipClient;

public class AfterShip {
private static final String DEFAULT_DOMAIN = "https://api.aftership.com";
private static final int DEFAULT_TIMEOUT = 10000;
private static final int DEFAULT_MAX_RETRY = 2;
private static AfterShipClient client;

private static String apiKey = System.getenv("AFTERSHIP_TRACKING_SDK_API_KEY");
private static String apiSecret = System.getenv("AFTERSHIP_TRACKING_SDK_API_SECRET");
private static AuthType authType;

private static String domain = System.getenv("AFTERSHIP_TRACKING_SDK_DOMAIN");
private static Integer maxRetry;
private static Integer timeout;
private static String userAgent = System.getenv("AFTERSHIP_TRACKING_SDK_USER_AGENT");
private static String proxy = System.getenv("AFTERSHIP_TRACKING_SDK_PROXY");

private AfterShip() {
}

public static synchronized void init(final String apiKey) {
AfterShip.apiKey = apiKey;
}

public static synchronized void init(final String apiKey, final String apiSecret, AuthType authType) {
AfterShip.apiKey = apiKey;
AfterShip.apiSecret = apiSecret;
AfterShip.authType = authType;
}

private static void getAuthType() {
if (authType != null) {
return;
}
String auth = System.getenv("AFTERSHIP_TRACKING_SDK_AUTHENTICATION_TYPE");
if (auth != null && !auth.isEmpty()) {
auth = auth.toUpperCase();
if (auth.equals(AuthType.AES.name())) {
authType = AuthType.AES;
return;
}
if (auth.equals(AuthType.RSA.name())) {
authType = AuthType.RSA;
return;
}
}
authType = AuthType.APIKEY;
}

private static Integer getIntegerFromEnv(String envName, Integer defaultValue) {
String envValue = System.getenv(envName);
if (envValue == null) {
return defaultValue;
}
if (envValue.isEmpty()) {
return defaultValue;
}
try {
return Integer.parseInt(envValue);
} catch (NumberFormatException e) {
return defaultValue;
}
}

public static AfterShipClient getRestClient() throws Exception {
if (client == null) {
client = buildRestClient();
}
return client;
}

private static AfterShipClient buildRestClient() throws Exception {
getAuthType();
if (apiKey == null || apiKey.isEmpty()) {
throw new ApiException(ErrorEnum.INVALID_API_KEY.getCode(), "Invalid option `apiKey`");
}
if (AuthType.AES.equals(authType) || AuthType.RSA.equals(authType)) {
if (apiSecret == null || apiSecret.isEmpty()) {
throw new ApiException(ErrorEnum.INVALID_API_KEY.getCode(), "Invalid option `apiSecret`");
}
}
if (timeout == null) {
Integer envTimeout = getIntegerFromEnv("AFTERSHIP_TRACKING_SDK_TIMEOUT", DEFAULT_TIMEOUT);
setTimeout(envTimeout);
}
if (maxRetry == null) {
Integer envMaxRetry = getIntegerFromEnv("AFTERSHIP_TRACKING_SDK_MAX_RETRY", DEFAULT_MAX_RETRY);
setMaxRetry(envMaxRetry);
}
AfterShipClient.Builder builder = new AfterShipClient.Builder(apiKey, apiSecret, authType);
if (domain != null && !domain.isEmpty()) {
builder.setDomain(domain);
} else {
builder.setDomain(DEFAULT_DOMAIN);
}
if (userAgent != null && !userAgent.isEmpty()) {
builder.setUserAgent(userAgent);
}
if (proxy != null && !proxy.isEmpty()) {
builder.setProxy(proxy);
}
return builder.setTimeout(timeout)
.setMaxRetry(maxRetry)
.build();
}

public static void setDomain(final String domain) throws Exception {
if (domain == null || domain.isEmpty()) {
throw new ApiException(ErrorEnum.INVALID_OPTION.getCode(), "Invalid option `domain`");
}
AfterShip.domain = domain;
}

public static void setMaxRetry(final int maxRetry) throws Exception {
if (maxRetry < 0 || maxRetry > 10) {
throw new ApiException(ErrorEnum.INVALID_OPTION.getCode(), "Invalid option `maxRetry`");
}
AfterShip.maxRetry = maxRetry;
}

public static void setTimeout(final int timeout) throws Exception {
if (timeout < 0) {
throw new ApiException(ErrorEnum.INVALID_OPTION.getCode(), "Invalid option `timeout`");
}
AfterShip.timeout = timeout;
}

public static void setUserAgent(final String userAgent) {
AfterShip.userAgent = userAgent;
}

public static void setProxy(final String proxy) {
AfterShip.proxy = proxy;
}
}
Loading

0 comments on commit ed6c806

Please sign in to comment.