/AftershipAPI

AftershipAPI For .NET Core 2.1

Primary LanguageC#MIT LicenseMIT

AftershipAPI

License - MIT Build Status Issues Latest Nuget Release Latest Nuget Pre-Release Coverage Status Last commit

This is an unofficial Aftership SDK for .NET Standard version 2.1.

Aftership provides a parcel tracking service that works with hundreds of couriers from arround the world.

Simple Examples

using AftershipAPI;
using System;

namespace AftershipAPIExample
{
    class Program
    {
        static int Main(string[] args)
        {
            // Create an instance of ConnectionAPI using the token
            ConnectionAPI connection = new ConnectionAPI("AftershipApiKey");

            // Create a new tracking to search for
            Tracking trackingToFind = new Tracking("trackingnumber"){ Slug = "slug" };

            // Must provide tracking number and slug to search for tracking
            Tracking tracking = GetTrackingByNumber(connection, trackingToFind);

            if(tracking != null)
            {
                Checkpoint checkpoint = GetLastCheckpoint(connection, tracking);
            }
        }

        public Tracking GetTrackingByNumber(ConnectionAPI connection, Tracking trackingToFind)
        {
            try
            {
                var tracking = connection.GetTrackingByNumber(trackingToFind);

                Console.WriteLine($"Tracking active?: {tracking.Active}");

                return tracking;
            }
            catch (Exception ex)
            {
                Console.WriteLine($"There's be an error: {ex.Message}");
                return null;
            }
        }

        public Checkpoint GetLastCheckpoint(ConnectionAPI connection, Tracking tracking)
        {
            var lastCheckpoint = connection.GetLastCheckpoint(tracking);

            Console.WriteLine($"Last checked at: {lastCheckpoint.CheckpointTime}");

            return lastCheckpoint;
        }
    }
}

Tips

  • Use exception handling when using the ConnectionAPI, this calls the Aftership service and can produce errors.