Party by ID suggestion.

This commit is contained in:
Alexander Zhuravlev 2020-12-14 19:00:36 +03:00
parent eb367fac33
commit b5758dbbb6
5 changed files with 137 additions and 16 deletions

View File

@ -1,9 +1,8 @@
language: go
go:
- "1.10.x"
- "1.11.x"
- "1.12.x"
- "1.14.x"
- "1.15.x"
- tip
#before_script:
@ -13,6 +12,7 @@ go:
# - ./cc-test-reporter before-build
script:
- go vet ./...
# - go test -v -race -coverprofile=coverage.out -covermode=atomic
- go test -v -race ./...

86
api/suggest/party.go Normal file
View File

@ -0,0 +1,86 @@
package suggest
import (
"context"
)
type (
PartyByIDParams struct {
Query string `json:"query"`
Count *int `json:"count,omitempty"`
KPP *string `json:"kpp,omitempty"`
Type *PartyType `json:"type,omitempty"`
BranchType *PartyBranchType `json:"branch_type,omitempty"`
}
PartyType string
PartyBranchType string
)
const (
PartyTypeLegal PartyType = "LEGAL"
PartyTypeIndividual PartyType = "INDIVIDUAL"
PartyBranchTypeMain PartyBranchType = "MAIN"
PartyBranchTypeBranch PartyBranchType = "BRANCH"
)
func NewPartyByIDParams(query string) *PartyByIDParams {
return &PartyByIDParams{
Query: query,
}
}
func (o *PartyByIDParams) SetQuery(query string) *PartyByIDParams {
o.Query = query
return o
}
func (o *PartyByIDParams) SetCount(count int) *PartyByIDParams {
o.Count = &count
return o
}
func (o *PartyByIDParams) SetKPP(kpp string) *PartyByIDParams {
o.KPP = &kpp
return o
}
func (o *PartyByIDParams) SetType(t PartyType) *PartyByIDParams {
o.Type = &t
return o
}
func (o *PartyByIDParams) SetBranchType(t PartyBranchType) *PartyByIDParams {
o.BranchType = &t
return o
}
// Party try to return suggest parties by params
func (a *Api) Party(ctx context.Context, params *RequestParams) (ret []*PartySuggestion, err error) {
var result = &PartyResponse{}
err = a.Client.Post(ctx, "suggest/party", params, result)
if err != nil {
return
}
ret = result.Suggestions
return
}
// Party find parties by ID
// https://dadata.ru/api/find-party/
func (a *Api) PartyByID(ctx context.Context, params *PartyByIDParams) (ret []*PartySuggestion, err error) {
var result = &PartyResponse{}
err = a.Client.Post(ctx, "findById/party", params, result)
if err != nil {
return
}
ret = result.Suggestions
return
}

View File

@ -42,17 +42,6 @@ func (a *Api) Bank(ctx context.Context, params *RequestParams) (ret []*BankSugge
return
}
// Party try to return suggest parties by params
func (a *Api) Party(ctx context.Context, params *RequestParams) (ret []*PartySuggestion, err error) {
var result = &PartyResponse{}
err = a.Client.Post(ctx, "suggest/party", params, result)
if err != nil {
return
}
ret = result.Suggestions
return
}
// Email try to return suggest emails by params
func (a *Api) Email(ctx context.Context, params *RequestParams) (ret []*EmailSuggestion, err error) {
var result = &EmailResponse{}

View File

@ -6,8 +6,9 @@ import (
"os"
"testing"
"github.com/ekomobile/dadata/v2/api/suggest"
"github.com/stretchr/testify/suite"
"github.com/ekomobile/dadata/v2/api/suggest"
)
type (
@ -52,6 +53,51 @@ func (s *ApiSuggestIntegrationTest) TestParty() {
s.NotEmpty(res)
}
func (s *ApiSuggestIntegrationTest) TestPartyById() {
api := NewSuggestApi()
query := "7707083893"
params := suggest.NewPartyByIDParams(query)
res, err := api.PartyByID(context.Background(), params)
s.NoError(err)
s.NotEmpty(res)
}
func (s *ApiSuggestIntegrationTest) TestPartyByIdWithKPP() {
api := NewSuggestApi()
query := "7707083893"
testKPP := "773601001"
params := suggest.NewPartyByIDParams(query).
SetKPP(testKPP)
res, err := api.PartyByID(context.Background(), params)
s.NoError(err)
s.NotEmpty(res)
s.Equal(query, res[0].Data.Inn)
s.Equal(testKPP, res[0].Data.Kpp)
}
func (s *ApiSuggestIntegrationTest) TestPartyByIdWithBranchType() {
api := NewSuggestApi()
query := "7707083893"
params := suggest.NewPartyByIDParams(query).
SetBranchType(suggest.PartyBranchTypeMain).
SetType(suggest.PartyTypeLegal)
res, err := api.PartyByID(context.Background(), params)
s.NoError(err)
s.NotEmpty(res)
s.Equal(query, res[0].Data.Inn)
}
func (s *ApiSuggestIntegrationTest) TestCountry() {
api := NewSuggestApi()
params := suggest.RequestParams{

2
go.mod
View File

@ -1,6 +1,6 @@
module github.com/ekomobile/dadata/v2
go 1.12
go 1.15
require (
github.com/davecgh/go-spew v1.1.1 // indirect