Giter Site home page Giter Site logo

dadata-csharp's Introduction

Dadata API Client

Data cleansing, enrichment and suggestions via Dadata API

Nuget Version Downloads

The official Dadata .NET library, supporting .NET Standard 2.0+

Installation

Using the .NET Core command-line interface (CLI) tools:

dotnet add package Newtonsoft.Json
dotnet add package Dadata

Using the NuGet Command Line Interface (CLI):

nuget install Newtonsoft.Json
nuget install Dadata

Using the Package Manager Console:

Install-Package Newtonsoft.Json
Install-Package Dadata

From within Visual Studio:

  1. Open the Solution Explorer.
  2. Right-click on a project within your solution.
  3. Click on Manage NuGet Packages...
  4. Click on the Browse tab and search for "Dadata".
  5. Click on the Dadata package, select the appropriate version in the right-tab and click Install.

Usage

Import namespaces:

using Dadata;
using Dadata.Model;

Create API client instance:

var token = "Replace with Dadata API key";
var secret = "Replace with Dadata secret key";

var api = new CleanClientAsync(token, secret);
// or any of the following, depending on the API method
api = new SuggestClientAsync(token);
api = new OutwardClientAsync(token);
api = new ProfileClientAsync(token, secret);

Then call API methods as specified below.

Examples use async clients: CleanClientAsync, SuggestClientAsync, OutwardClientAsync and ProfileClientAsync. There are sync alternatives with Sync suffixes — they exist for backward compatibility and will be removed in future releases.

Postal Address

var api = new CleanClientAsync(token, secret);
var address = await api.Clean<Address>("мск сухонская 11 89");

Same API method as "validate and cleanse":

var api = new CleanClientAsync(token, secret);
var address = await api.Clean<Address>("москва сухонская 11");
var api = new SuggestClientAsync(token);
var response = await api.Geolocate(lat: 55.878, lon: 37.653);
var address = response.suggestions[0].data;
var api = new SuggestClientAsync(token);
var response = await api.Iplocate("46.226.227.20");
var address = response.location.data;
var api = new SuggestClientAsync(token);
var response = await api.SuggestAddress("самара метал");
var address = response.suggestions[0].data;

Show suggestions in English:

var request = new SuggestAddressRequest("samara metal") { language = "en" };
var response = await api.SuggestAddress(request);
var address = response.suggestions[0].data;

Constrain by city (Yuzhno-Sakhalinsk):

var request = new SuggestAddressRequest("ватутина")
{
    locations = new[] {
        new Address() { kladr_id = "6500000100000" },
    }
};
var response = await api.SuggestAddress(request);
var address = response.suggestions[0].data;

Constrain by specific geo point and radius (in Vologda city):

var request = new SuggestAddressRequest("сухонская")
{
    locations_geo = new[]
    {
        new LocationGeo() { lat=59.244634, lon=39.913355, radius_meters=200}
    }
};
var response = await api.SuggestAddress(request);
var address = response.suggestions[0].data;

Boost city to top (Toliatti):

var request = new SuggestAddressRequest("авто")
{
    locations_boost = new[]
    {
        new Address() { kladr_id = "6300000700000" },
    }
};
var response = await api.SuggestAddress(request);
var address = response.suggestions[0].data;
var api = new SuggestClientAsync(token);
var response = await api.FindAddress("9120b43f-2fae-4838-a144-85e43c2bfb29");
var address = response.suggestions[0].data;

Find by KLADR ID:

var response = await api.FindAddress("77000000000268400");
var address = response.suggestions[0].data;

Suggest postal office by address or code:

var api = new OutwardClientAsync(token);
var response = await api.Suggest<PostalUnit>("дежнева 2а");
var unit = response.suggestions[0].data;

Find postal office by code:

var response = await api.Find<PostalUnit>("127642");
var unit = response.suggestions[0].data;

Find nearest postal office:

var response = await api.Geolocate<PostalUnit>(lat: 55.878, lon: 37.653, radius_meters: 1000);
var unit = response.suggestions[0].data;
var api = new OutwardClientAsync(token);
var response = await api.Find<DeliveryCity>("3100400100000");
var city = response.suggestions[0].data;
var api = new SuggestClientAsync(token);
var response = await api.FindFias("9120b43f-2fae-4838-a144-85e43c2bfb29");
var address = response.suggestions[0].data;
var api = new OutwardClientAsync(token);
var response = await api.Suggest<Country>("та");
var country = response.suggestions[0].data;

Company or individual enterpreneur

var api = new SuggestClientAsync(token);
var response = await api.FindParty("7707083893");
var party = response.suggestions[0].data;

Find by INN and KPP:

var request = new FindPartyRequest(query: "7707083893", kpp: "540602001");
var response = await api.FindParty(request);
var party = response.suggestions[0].data;
var api = new SuggestClientAsync(token);
var response = await api.SuggestParty("сбер");
var party = response.suggestions[0];

Constrain by specific regions (Saint Petersburg and Leningradskaya oblast):

var request = new SuggestPartyRequest("сбер")
{
    locations = new[] {
        new Address() { kladr_id = "7800000000000" },
        new Address() { kladr_id = "4700000000000" },
    }
};
var response = await api.SuggestParty(request);
var party = response.suggestions[0];

Constrain by active companies:

var request = new SuggestPartyRequest("сбер")
{
    status = new[] { PartyStatus.ACTIVE }
};
var response = await api.SuggestParty(request);
var party = response.suggestions[0];

Constrain by individual entrepreneurs:

var request = new SuggestPartyRequest("сбер")
{
    type = PartyType.INDIVIDUAL
};
var response = await api.SuggestParty(request);
var party = response.suggestions[0];
var api = new SuggestClientAsync(token);
var response = await api.FindAffiliated("7736207543");
var party = response.suggestions[0].data;

Search only by manager INN:

var request = new FindAffiliatedRequest("773006366201")
{
    scope = new[] { FindAffiliatedScope.MANAGERS }
};
var response = await api.FindAffiliated(request);
var party = response.suggestions[0].data;

Bank

var api = new SuggestClientAsync(token);
var response = await api.FindBank("044525225");
var bank = response.suggestions[0].data;

Find by SWIFT code:

var response = await api.FindBank("SABRRUMM");
var bank = response.suggestions[0].data;

Find by INN:

var response = await api.FindBank("7728168971");
var bank = response.suggestions[0].data;

Find by INN and KPP:

var request = new FindBankRequest(query: "7728168971", kpp: "667102002");
var response = await api.FindBank(request);
var bank = response.suggestions[0].data;

Find by registration number:

var response = await api.FindBank("1481");
var bank = response.suggestions[0].data;
var api = new SuggestClientAsync(token);
var response = await api.SuggestBank("ти");
var bank = response.suggestions[0].data;

Personal name

var api = new CleanClientAsync(token, secret);
var fullname = await api.Clean<Fullname>("Срегей владимерович иванов");
var api = new SuggestClientAsync(token);
var response = await api.SuggestName("викт");
var fullname = response.suggestions[0].data;

Suggest female first name:

var request = new SuggestNameRequest("викт")
{
    parts = new[] { FullnamePart.NAME },
    gender = Gender.FEMALE
};
var response = await api.SuggestName(request);
var fullname = response.suggestions[0].data;

Phone

var api = new CleanClientAsync(token, secret);
var phone = await api.Clean<Phone>("9168-233-454");

Passport

var api = new CleanClientAsync(token, secret);
var passport = await api.Clean<Passport>("4509 235857");
var api = new OutwardClientAsync(token);
var response = await api.Suggest<FmsUnit>("772 053");
var unit = response.suggestions[0].data;

Email

var api = new CleanClientAsync(token, secret);
var email = await api.Clean<Email>("serega@yandex/ru");
var api = new SuggestClientAsync(token);
var response = await api.SuggestEmail("maria@");
var email = response.suggestions[0].data;

Other datasets

var api = new OutwardClientAsync(token);
var response = await api.Find<FnsUnit>("5257");
var unit = response.suggestions[0].data;
var api = new OutwardClientAsync(token);
var response = await api.Suggest<MetroStation>("алек");
var station = response.suggestions[0].data;

Constrain by city (Saint Petersburg):

var request = new SuggestOutwardRequest("алек")
{
    filters = new Dictionary<string, string>() { { "city", "Санкт-Петербург" } }
};
var response = await api.Suggest<MetroStation>(request);
var station = response.suggestions[0].data;
var api = new OutwardClientAsync(token);
var response = await api.Suggest<CarBrand>("фо");
var brand = response.suggestions[0].data;
var api = new OutwardClientAsync(token);
var response = await api.Find<OktmoRecord>("54623425");
var record = response.suggestions[0].data;
var api = new OutwardClientAsync(token);
var response = await api.Suggest<OkvedRecord>("космических");
var record = response.suggestions[0].data;

Profile API

var api = new ProfileClientAsync(token, secret);

Balance:

var response = await api.GetBalance();
var balance = response.balance;

Usage stats:

var response = await api.GetDailyStats();
var cleanCount = response.services.clean;
var suggestionsCount = response.services.suggestions;
var mergingCount = response.services.merging;

Dataset versions:

var response = await api.GetVersions();
var egrulVersion = response.suggestions.resources["ЕГРЮЛ"];
var geoVersion = response.factor.resources["Геокоординаты"];

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Make sure to add or update tests as appropriate.

Use Conventional Commits for commit messages.

This library uses CalVer with YY.MM.MICRO schema. See changelog for details specific to each release.

License

MIT

dadata-csharp's People

Contributors

nalgeon avatar askazakov avatar quaswex avatar aristarkhletskin avatar drshpongl 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.