Merge pull request #1 from ekomobile/party_by_id
Party by ID suggestion.
This commit is contained in:
commit
288cb8399c
@ -1,9 +1,8 @@
|
|||||||
language: go
|
language: go
|
||||||
|
|
||||||
go:
|
go:
|
||||||
- "1.10.x"
|
- "1.14.x"
|
||||||
- "1.11.x"
|
- "1.15.x"
|
||||||
- "1.12.x"
|
|
||||||
- tip
|
- tip
|
||||||
|
|
||||||
#before_script:
|
#before_script:
|
||||||
@ -13,6 +12,7 @@ go:
|
|||||||
# - ./cc-test-reporter before-build
|
# - ./cc-test-reporter before-build
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
- go vet ./...
|
||||||
# - go test -v -race -coverprofile=coverage.out -covermode=atomic
|
# - go test -v -race -coverprofile=coverage.out -covermode=atomic
|
||||||
- go test -v -race ./...
|
- go test -v -race ./...
|
||||||
|
|
||||||
|
86
api/suggest/party.go
Normal file
86
api/suggest/party.go
Normal 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
|
||||||
|
}
|
@ -42,17 +42,6 @@ func (a *Api) Bank(ctx context.Context, params *RequestParams) (ret []*BankSugge
|
|||||||
return
|
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
|
// Email try to return suggest emails by params
|
||||||
func (a *Api) Email(ctx context.Context, params *RequestParams) (ret []*EmailSuggestion, err error) {
|
func (a *Api) Email(ctx context.Context, params *RequestParams) (ret []*EmailSuggestion, err error) {
|
||||||
var result = &EmailResponse{}
|
var result = &EmailResponse{}
|
||||||
|
@ -6,8 +6,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ekomobile/dadata/v2/api/suggest"
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
|
"github.com/ekomobile/dadata/v2/api/suggest"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@ -52,6 +53,51 @@ func (s *ApiSuggestIntegrationTest) TestParty() {
|
|||||||
s.NotEmpty(res)
|
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() {
|
func (s *ApiSuggestIntegrationTest) TestCountry() {
|
||||||
api := NewSuggestApi()
|
api := NewSuggestApi()
|
||||||
params := suggest.RequestParams{
|
params := suggest.RequestParams{
|
||||||
|
Loading…
Reference in New Issue
Block a user