Giter VIP home page Giter VIP logo

transdirect's Introduction

Transdirect Library for .NET Standard

This library is MIT Licensed

Build status MyGet

1. Introduction

The Transdirect Library is a .NET Standard wrapper for Transdirect API v4 (https://www.transdirect.com.au/education/developers-centre/rest-api/, document at http://docs.transdirectapiv4.apiary.io/). The library is compatible with .NET Standard 1.4+ (.NET Core 1.0+, .NETFramework 4.5+).

At the moment the following endpoints are implemented:

  • Simple Quote
  • Bookings (CURD, Confirm, Track)
  • Booking Items (CURD)
  • Members (Get current member)
  • Couriers (Get all supported couriers)

Additional endpoints are in development.

2. Adding reference

NuGet.org package shall be available in the future. At the moment, please either add MyGet package source (built straight from master) or add direct reference to the repo.

2A. Add MyGet package

Following instructions: https://www.myget.org/feed/nkahoang/package/nuget/Transdirect-NetStandard

2B. Add direct reference

  1. Clone this repo:
git clone https://github.com/nkahoang/Transdirect.git
  1. Add preference to this project in your .csproj file:
  <ItemGroup>
    <ProjectReference Include="..\Transdirect\Transdirect.csproj" />
    <!-- [Other preferences]-->
  </ItemGroup>

3. Getting the API Key

Access https://www.transdirect.com.au/members/api/apimodules, create a "Custom Site" module for your project.

4. Using the library

There are two methods to use the library:

4A. Quick and dirty way

var options = new TransdirectOptions() {
    ApiKey = "api-key-goes-here";
    // Other configs
};

var transdirectService = new TransdirectService(options);

// All endpoints are exposed via transdirectService object.

4B. Use DI container and Application startup (Recommended)

Put the following in your appsettings.json (or your application's config file):

{
  // [...] your other settings
  // Put TransDirect section in
  "Transdirect": {
    "ApiKey": "your-api-key",
    "BaseUrl": "https://www.transdirect.com.au/api",
    "CouriersCacheDuration": "00:05:00"
  }
}

Then in your application initialization:

// in your Startup.cs
using Transdirect.Extensions;

/* This should come with a standard ASP.NET Core / Owin startup */
public Startup (IHostingEnvironment env) {
    _currentEnvironment = env;

    var builder = new ConfigurationBuilder ()
        .SetBasePath (env.ContentRootPath)
        .AddJsonFile ("appsettings.json", optional : true, reloadOnChange : true)
        .AddJsonFile ($"appsettings.{env.EnvironmentName}.json", optional : true)
        .AddEnvironmentVariables ();
    Configuration = builder.Build ();
}

/* Then register the PinPayments service */
public void ConfigureServices (IServiceCollection services) {
    services.AddTransdirect(Configuration);
}

From here onward, simply inject in ITransdirectService in your constructor.

5. Examples / Running Test app.

Working examples for Transdirect are in the PinPayments.Test app, specifically under TransdirectTest.cs file.

To run the Test project:

  • Clone this repo.
  • Copy Transdirect.Test\config.sample.json to Transdirect.Test\config.json and set the correct API.
  • Perform a dotnet restore inside Transdirect.Test folder.
  • Run the sample console app: dotnet run.

transdirect's People

Contributors

nkahoang avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.