2019-04-09 17:08:32 +03:00
|
|
|
package dadata
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/ekomobile/dadata/v2/api/clean"
|
|
|
|
"github.com/ekomobile/dadata/v2/api/profile"
|
|
|
|
"github.com/ekomobile/dadata/v2/api/stat"
|
|
|
|
"github.com/ekomobile/dadata/v2/api/suggest"
|
|
|
|
"github.com/ekomobile/dadata/v2/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// EndpointURL is a base API endpoint.
|
|
|
|
EndpointURL = "https://dadata.ru/api/v2/"
|
|
|
|
// EndpointURLSuggest is a suggestion API endpoint.
|
|
|
|
EndpointURLSuggest = "https://suggestions.dadata.ru/suggestions/api/4_1/rs/"
|
2024-04-01 00:02:32 +03:00
|
|
|
// EndpointURLClean is a cleaner API endpoint.
|
|
|
|
EndpointURLClean = "https://cleaner.dadata.ru/api/v1/"
|
2019-04-09 17:08:32 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
endpointURL *url.URL
|
|
|
|
endpointURLSuggest *url.URL
|
2024-04-01 00:02:32 +03:00
|
|
|
endpointURLClean *url.URL
|
2019-04-09 17:08:32 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
endpointURL, err = url.Parse(EndpointURL)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
endpointURLSuggest, err = url.Parse(EndpointURLSuggest)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2024-04-01 00:02:32 +03:00
|
|
|
|
|
|
|
endpointURLClean, err = url.Parse(EndpointURLClean)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-04-09 17:08:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewCleanApi provides "clean" API.
|
|
|
|
func NewCleanApi(opts ...client.Option) *clean.Api {
|
|
|
|
return &clean.Api{
|
2024-04-01 00:02:32 +03:00
|
|
|
Client: client.NewClient(endpointURLClean, opts...),
|
2019-04-09 17:08:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewSuggestApi provides suggestion API.
|
|
|
|
func NewSuggestApi(opts ...client.Option) *suggest.Api {
|
|
|
|
return &suggest.Api{
|
|
|
|
Client: client.NewClient(endpointURLSuggest, opts...),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewProfileApi provides profile related API.
|
|
|
|
func NewProfileApi(opts ...client.Option) *profile.Api {
|
|
|
|
return &profile.Api{
|
|
|
|
Client: client.NewClient(endpointURL, opts...),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewStatApi provides statistic API.
|
|
|
|
func NewStatApi(opts ...client.Option) *stat.Api {
|
|
|
|
return &stat.Api{
|
|
|
|
Client: client.NewClient(endpointURL, opts...),
|
|
|
|
}
|
|
|
|
}
|