Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.idea/
.vs/
src/AfterShipTracking/Test/
src/AfterShipTracking/AfterShipTracking/bin/
src/AfterShipTracking/AfterShipTracking/obj/
Tracking.sln.DotSettings.user
.DS_Store
.config/
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 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.
345 changes: 344 additions & 1 deletion README.md

Large diffs are not rendered by default.

Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/AfterShipTracking/.DS_Store
Binary file not shown.
29 changes: 29 additions & 0 deletions src/AfterShipTracking/AfterShipTracking.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 25.0.1706.9
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AfterShipTracking", "AfterShipTracking\AfterShipTracking.csproj", "{D3099A91-E005-4291-88AD-D7A3B85DDC1D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D3099A91-E005-4291-88AD-D7A3B85DDC1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3099A91-E005-4291-88AD-D7A3B85DDC1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3099A91-E005-4291-88AD-D7A3B85DDC1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3099A91-E005-4291-88AD-D7A3B85DDC1D}.Release|Any CPU.Build.0 = Release|Any CPU
{D2C22390-8325-4493-B940-F89BD8BA19EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D2C22390-8325-4493-B940-F89BD8BA19EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D2C22390-8325-4493-B940-F89BD8BA19EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D2C22390-8325-4493-B940-F89BD8BA19EA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5C216FDA-5980-4A44-A348-7C9B82282CE4}
EndGlobalSection
EndGlobal
55 changes: 55 additions & 0 deletions src/AfterShipTracking/AfterShipTracking/AfterShipTracking.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Label="NuGet">
<TargetFramework>net6.0</TargetFramework>
<OutputPath>bin/Release</OutputPath>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<PackageId>AfterShipTracking</PackageId>
<Description>The official AfterShip Tracking .net API library</Description>
<Copyright>Copyright © AfterShip</Copyright>
<AssemblyTitle>AfterShipTracking</AssemblyTitle>
<NeutralLanguage>en-US</NeutralLanguage>
<VersionPrefix>10.0.0</VersionPrefix>
<VersionSuffix>
</VersionSuffix>
<Authors>AfterShip</Authors>
<NoWarn>CS1587;CS1591;CS1570;CS1573;CS1572;CS8618;CS8603;CS8625;CS8604;CS8765</NoWarn>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<AssemblyName>AfterShipTracking</AssemblyName>
<PackageTags>aftership;tracking;track;fedex;ups;usps;dhl;shipping;fulfillment;couriers;carriers</PackageTags>
<PackageProjectUrl>https://www.aftership.com</PackageProjectUrl>
<RepositoryUrl>https://github.com/aftership/tracking-sdk-net</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<PackageIcon>icon.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
<None Include="../../../README.md" Pack="true" PackagePath="\" />
<None Include="../../../icon.png" Pack="true" PackagePath="\" />
<None Include="../../../LICENSE.txt" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.5.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="Adapter\" />
<Folder Include="Adapter\" />
<Folder Include="Exception\" />
<Folder Include="Models\" />
<Folder Include="Properties\" />
<Folder Include="Public\" />
<Folder Include="RestAPI\" />
</ItemGroup>
</Project>
140 changes: 140 additions & 0 deletions src/AfterShipTracking/AfterShipTracking/AftershipClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
* This code was auto generated by AfterShip SDK Generator.
* Do not edit the class manually.
*/
using System.Linq;

namespace AfterShipTracking
{
public class AfterShipClient
{
/// <summary>Gets the base URL for AfterShip's API.</summary>
/// <value>The base URL for AfterShip's API.</value>
public string ApiBase { get; set; }

/// <summary>
/// Custom API domain.
/// </summary>
public string Domain;

/// <summary>
/// Custom API domain.
/// </summary>
public int MaxRetry { get; set; }

/// <summary>
/// Max request timeout in milliseconds.
/// </summary>
public int Timeout { get; set; }

/// <summary>
/// Custom API domain.
/// </summary>
public string UserAgent { get; set; }

/// <summary>
/// Custom API domain. Only http, socks4, socks4a, socks5 are allowed.
/// </summary>
public string Proxy { get; set; }

/// <summary>
/// Custom API domain.
/// </summary>
public string ApiKey { get; set; }

/// <summary>
/// AfterShip API secret for AES or RSA authentication method.
/// </summary>
public string ApiSecret { get; set; }

/// <summary>
/// AfterShip API Authentication method. Allowed value: API_KEY , AES , RSA
/// </summary>
public string AuthenticationType { get; set; }

/// <summary>
/// AfterShip API version.
/// </summary>
public string Version { get; set; }

/// <summary>
/// AfterShip API Product
/// </summary>
public string Product { get; set; }

public IHttpClient HttpClient { get; }

public TrackingService Tracking { get; set; }
public CourierService Courier { get; set; }
public EstimatedDeliveryDateService EstimatedDeliveryDate { get; set; }
public AfterShipClient(
string domain = null,
string apiKey = null,
string apiSecret = null,
string authenticationType = null,
string userAgent = null,
string proxy = null,
int timeout = 0,
int maxRetry = 0,
IHttpClient httpClient = null
)
{
Domain = domain ?? AfterShipConfiguration.Domain;
ApiBase = Domain;
MaxRetry = maxRetry == 0 ? AfterShipConfiguration.MaxRetry : maxRetry;
Timeout = timeout == 0 ? AfterShipConfiguration.Timeout : timeout;
UserAgent = userAgent ?? AfterShipConfiguration.UserAgent;
Proxy = proxy ?? AfterShipConfiguration.Proxy;
ApiKey = apiKey ?? AfterShipConfiguration.ApiKey;
ApiSecret = apiSecret ?? AfterShipConfiguration.ApiSecret;
AuthenticationType = authenticationType ?? AfterShipConfiguration.AuthenticationType;

CheckConfig();

Authenticator authenticator = new Authenticator(ApiKey, ApiSecret, AuthenticationType);

HttpClient = httpClient ?? new SystemNetHttpClient(this.ApiBase, authenticator, this.MaxRetry, this.Timeout, this.UserAgent, this.Proxy);

Tracking = new TrackingService(HttpClient);
Courier = new CourierService(HttpClient);
EstimatedDeliveryDate = new EstimatedDeliveryDateService(HttpClient);
}

private void CheckConfig()
{
if (string.IsNullOrEmpty(ApiKey))
{
throw ErrorCode.GenSDKError(ErrorCode.INVALID_API_KEY, "apiKey cannot be empty");
}

if (this.Timeout < 0 || this.Timeout > 30000)
{
throw ErrorCode.GenSDKError(ErrorCode.INVALID_OPTION, "timeout invalid, timeout must between 0 and 30000 (milliseconds)");
}

if (this.MaxRetry < 0 || this.MaxRetry > 10)
{
throw ErrorCode.GenSDKError(ErrorCode.INVALID_OPTION, "max retry invalid, max retry must between 0 and 10");
}

string[] array = {
AfterShipConfiguration.AUTHENTICATION_TYPE_API_KEY,
AfterShipConfiguration.AUTHENTICATION_TYPE_AES,
AfterShipConfiguration.AUTHENTICATION_TYPE_RSA,
};
var authenticationType = AuthenticationType;
if (!array.Contains(authenticationType))
{
throw ErrorCode.GenSDKError(ErrorCode.INVALID_OPTION, "Invalid option: authenticationType should be one of API_KEY, AES, RSA");
}

if (authenticationType == AfterShipConfiguration.AUTHENTICATION_TYPE_AES || authenticationType == AfterShipConfiguration.AUTHENTICATION_TYPE_AES)
{
if (string.IsNullOrEmpty(ApiSecret))
{
throw ErrorCode.GenSDKError(ErrorCode.INVALID_API_KEY, "Invalid option: apiSecret cannot be empty");
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* This code was auto generated by AfterShip SDK Generator.
* Do not edit the class manually.
*/
using System;

namespace AfterShipTracking
{
public class AfterShipError : Exception
{
protected string errorCode;
protected int? metaCode;
protected int? statusCode;
protected string message;
protected object responseBody;
protected object responseHeader;

public AfterShipError(string message, string errorCode, int? statusCode, int? metaCode, object responseBody = null, object responseHeader = null)
: base(message)
{
this.metaCode = metaCode;
this.message = message;
this.errorCode = errorCode;
this.statusCode = statusCode;
this.responseBody = responseBody;
this.responseHeader = responseHeader;
}

public string ErrorCode
{
get { return errorCode; }
}

public int? MetaCode
{
get { return metaCode; }
}

public int? StatusCode
{
get { return statusCode; }
}

public object ResponseBody
{
get { return responseBody; }
}

public object ResponseHeader
{
get { return responseHeader; }
}
}
}
Loading