dadata/README.md

66 lines
1.7 KiB
Markdown
Raw Normal View History

2019-04-08 14:49:07 +03:00
# Client for DaData.ru
Forked from https://github.com/webdeskltd/dadata.
2022-03-30 23:30:20 +03:00
[![Build Status](https://travis-ci.org/ekomobile/dadata.svg)](https://travis-ci.com/ekomobile/dadata)
2019-04-08 14:49:07 +03:00
[![GitHub release](https://img.shields.io/github/release/ekomobile/dadata.svg)](https://github.com/ekomobile/dadata/releases)
2022-03-30 23:30:20 +03:00
[![Go Report Card](https://goreportcard.com/badge/github.com/ekomobile/dadata)](https://goreportcard.com/report/github.com/ekomobile/dadata/v2)
[![GoDoc](https://godoc.org/github.com/ekomobile/dadata/v2?status.svg)](https://godoc.org/github.com/ekomobile/dadata/v2)
2019-04-08 14:49:07 +03:00
DaData API v2
Implemented [Clean](https://dadata.ru/api/clean/) and [Suggest](https://dadata.ru/api/suggest/) methods.
## Installation
2021-09-07 12:17:59 +03:00
`go get github.com/ekomobile/dadata/v2`
2019-04-08 14:49:07 +03:00
## Usage
```go
import (
2019-04-09 17:08:32 +03:00
"context"
2019-04-08 14:49:07 +03:00
"fmt"
2019-04-09 17:08:32 +03:00
"github.com/ekomobile/dadata/v2"
"github.com/ekomobile/dadata/v2/api/suggest"
2019-04-08 14:49:07 +03:00
)
2019-04-09 17:08:32 +03:00
func DaDataExample() {
api := dadata.NewSuggestApi()
2019-04-08 14:49:07 +03:00
2019-04-09 17:08:32 +03:00
params := suggest.RequestParams{
Query: "ул Свободы",
2019-04-08 14:49:07 +03:00
}
2019-04-09 17:08:32 +03:00
suggestions, err := api.Address(context.Background(), &params)
if err != nil {
return
2019-04-08 14:49:07 +03:00
}
2019-04-09 17:08:32 +03:00
for _, s := range suggestions {
fmt.Printf("%s", s.Value)
}
2019-04-08 14:49:07 +03:00
}
```
2022-03-30 23:30:20 +03:00
## Credentials
`DADATA_API_KEY` and `DADATA_SECRET_KEY` environment variables are used by default to authenticate client.
Custom credential provider may be used by implementing `client.CredentialProvider` interface.
Also, there is a "simple" credential provider `client.Credentials` you may utilize.
```go
creds := client.Credentials{
ApiKeyValue: "<YOUR_API_KEY>",
SecretKeyValue: "<YOUR_SECRET_KEY>",
}
api := NewSuggestApi(client.WithCredentialProvider(&creds))
```
2019-04-08 14:49:07 +03:00
## Licence
MIT see [LICENSE](LICENSE)