Skip to content

mvpotter/kladr-api-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Dependency Status Build Status Coverage Status Codacy Badge

KLADR API client

Visit https://kladr-api.ru for more info.

Requirements

  • JDK 1.7
  • KLADR API token. You can get it for free here

Maven

kladrapi-client is distributed using jitpack.io, thus it is necessary to add jitpack repository to your pom.xml or setting.xml file.

<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>

<dependencies>
    <dependency>
        <groupId>com.github.mvpotter</groupId>
        <artifactId>kladrapi-client</artifactId>
        <version>${kladrapi-client.version}</version>
    </dependency>
</dependencies>

Usage

Javadoc can be found here.

Create client instance

import com.mvpotter.kladrapi.KladrApiClient;

// If you have free access plan you have to use appropriate URL:
final KladrApiClient freeApiClient = new KladrApiClient(KladrApiClient.FREE_URL, "{ your API token }");
// The short form of the client above
final KladrApiClient anotherFreeApiClient = new KladrApiClient("{ your API token }");

// If you have paid plan, URL is different and client should be created the following way
final KladrApiClient paidApiClient = new KladrApiClient(KladrApiClient.PAID_URL, "{ your API token }");

Perform API request

import com.mvpotter.kladrapi.response.Response;

final Response response = client.search(request);

Requests

Every API request object implements com.mvpotter.kladrapi.request.Request interface, which have single method Map<String, String> toMap() that returns all request specific parameters as a map. Thus, if the client does not have request type for your specific needs you can always implement it yourself. Of course, contributions are always welcome.

Building request

new BuildingRequest("{ street id }", "10");

City request

new CityRequest("Мос");

District request

new DistrinctRequest("Ступинск");

One string request

new OneStringRequest("Ленин");

Region request

new RegionRequest("Московск");

Street request

new StreetRequest("{ cityId }", "Ленин")

Zip request

new ZipRequest("119027")

Request wrappers

Request with type code specified

new RequestWithTypeCode(new CityRequest("Бутынь"), TypeCode.VILLAGE)

Request that requires parent info to be filled in response

new RequestWithParent(new CityRequest("Бутынь"))

Request with limit specified

new RequestWithLimit(new CityRequest("Моск"), { limit }, [{ offset }])

Request with region id specified

new RequestWithRegionId(new OneStringRequest("Моск"), { regionId })

Request with district id specified

new RequestWithDistrictId(new OneStringRequest("Моск"), { districtId })

Request with city id specified

new RequestWithCityId(new OneStringRequest("Ленина"), { cityId })