Skip to content

milad-karimifard/NeshanApi.Dotnet

Repository files navigation

NeshanApi.Dotnet

This library is wrapper to help to use neshan.org in dotnet. all api neshan provide is suported. you can get more information in this link

Installation

You can install it from nuget with this command

Install-Package NeshanApi.Dotnet

Or with dotnet cli with

dotnet add package NeshanApi.Dotnet

Usage

Before to start use this you must get your API KEY from Neshan Platform, then you can start.
for configure your client you must use NeshanConfig class and pass to client instance. the only config currently available is API KEY.
After done all of this you can create a instance of NeshanApiClient. to do that you have 2 option

  1. Create directly
    this is example how you can create your instance

public static INeshanApiClient GetInstance()
{
   return new NeshanApiClient(new HttpClient(), new NeshanConfig()
   {
        ApiKey = Constants.ApiKey
   });
}

  1. With DI Container
    if you want use dependency injection you can register NeshanApiClient as INeshanApiClient.
    for example if you use this in Asp.net Core you registerd as typed client like below

services.AddHttpClient<INeshanApiService, NeshanApiService>();

Methods

Client has 8 method for 7 api:

  1. Direction & DirectionWithOutTraffic methods are for Routing API (Doc link)
  2. LocationBasedSearch method is for Search API (Doc link)
  3. TravelingSalesmanProblem method is for Traveling Salesman Problem API (Doc link)
  4. ReverseGeocoding method is for Reverse Geocoding API (Doc link)
  5. Geocoding method is for Geocoding API (Doc link)
  6. DistanceMatrix method is for Distance Matrix API ( Doc link)
  7. MapMatching method is for Map Matching API (Doc link)

Exception

There are 2 types of Exception in this library.

  1. Neshan Api Error
    these exceptions are neshan api error such as 470(CoordinateParseError) status code. when response status code set 470, NeshanCoordinateParseException will rise.

    Exceptions:
    • 470: NeshanCoordinateParseException
    • 480: NeshanKeyNotFoundException
    • 481: NeshanLimitExceededException
    • 482: NeshanRateExceededException
    • 483: NeshanApiKeyTypeErrorException
    • 484: NeshanApiWhiteListErrorException
    • 485: NeshanApiServiceListErrorException

  2. Internal Exceptions
    these exceptions are rise when response status code are 200 but a error happened.

    Exceptions:
    • NeshanNoResultException: this is happened in Geocoding API
    • NeshanNoRouteFoundException: this is happened in Routing API

About

this library help to use neshan.org in dotnet

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages