diff --git a/.travis.yml b/.travis.yml index 0c4d25a..0d375e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 ./... diff --git a/api/suggest/party.go b/api/suggest/party.go new file mode 100644 index 0000000..86467cc --- /dev/null +++ b/api/suggest/party.go @@ -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 +} diff --git a/api/suggest/suggest.go b/api/suggest/suggest.go index b6875bd..755fec7 100644 --- a/api/suggest/suggest.go +++ b/api/suggest/suggest.go @@ -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{} diff --git a/dadata_test.go b/dadata_test.go index b1b446e..06a26c9 100644 --- a/dadata_test.go +++ b/dadata_test.go @@ -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{ diff --git a/go.mod b/go.mod index 177434a..e53bbeb 100644 --- a/go.mod +++ b/go.mod @@ -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