added all methods for get user fields
This commit is contained in:
parent
5b06e730ab
commit
42413a877f
@ -6,13 +6,17 @@ const (
|
||||
FieldTypeLeads FieldsType = "leads"
|
||||
FieldTypeCompany FieldsType = "company"
|
||||
FieldTypeContact FieldsType = "contact"
|
||||
FieldTypeDeal FieldsType = "deal"
|
||||
)
|
||||
|
||||
type Company struct {
|
||||
type CompanyFields struct {
|
||||
}
|
||||
|
||||
type Lead struct {
|
||||
type LeadFields struct {
|
||||
}
|
||||
|
||||
type Contact struct {
|
||||
type ContactFields struct {
|
||||
}
|
||||
|
||||
type DealFields struct {
|
||||
}
|
||||
|
||||
@ -150,14 +150,14 @@ func (b *Bitrix) GetListFields(fieldType models.FieldsType, accessToken string,
|
||||
return nil, fmt.Errorf(errorMessage)
|
||||
}
|
||||
|
||||
var listFields models.Company
|
||||
var listFields models.CompanyFields
|
||||
err := json.Unmarshal(resBody, &listFields)
|
||||
if err != nil {
|
||||
b.logger.Error("error unmarshal models.Company:", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return string(resBody), nil
|
||||
return listFields, nil
|
||||
|
||||
case models.FieldTypeLeads:
|
||||
fullURL := fmt.Sprintf("https://%s/rest/crm.lead.userfield.list", domain)
|
||||
@ -183,7 +183,7 @@ func (b *Bitrix) GetListFields(fieldType models.FieldsType, accessToken string,
|
||||
return nil, fmt.Errorf(errorMessage)
|
||||
}
|
||||
|
||||
var listFields models.Lead
|
||||
var listFields models.LeadFields
|
||||
err := json.Unmarshal(resBody, &listFields)
|
||||
if err != nil {
|
||||
b.logger.Error("error unmarshal models.Lead:", zap.Error(err))
|
||||
@ -216,7 +216,7 @@ func (b *Bitrix) GetListFields(fieldType models.FieldsType, accessToken string,
|
||||
return nil, fmt.Errorf(errorMessage)
|
||||
}
|
||||
|
||||
var listFields models.Contact
|
||||
var listFields models.ContactFields
|
||||
err := json.Unmarshal(resBody, &listFields)
|
||||
if err != nil {
|
||||
b.logger.Error("error unmarshal models.Contact:", zap.Error(err))
|
||||
@ -224,7 +224,40 @@ func (b *Bitrix) GetListFields(fieldType models.FieldsType, accessToken string,
|
||||
}
|
||||
|
||||
return listFields, nil
|
||||
case models.FieldTypeDeal:
|
||||
fullURL := fmt.Sprintf("https://%s/rest/crm.deal.userfield.list", domain)
|
||||
agent := b.fiberClient.Post(fullURL)
|
||||
agent.Set("Authorization", "Bearer "+accessToken)
|
||||
requestBody := map[string]interface{}{
|
||||
"order": map[string]string{"SORT": "ASC"},
|
||||
"filter": map[string]string{"LANG": "ru"},
|
||||
}
|
||||
agent.JSON(requestBody)
|
||||
|
||||
statusCode, resBody, errs := agent.Bytes()
|
||||
if len(errs) > 0 {
|
||||
for _, err := range errs {
|
||||
b.logger.Error("error sending request in GetListFields", zap.Error(err))
|
||||
}
|
||||
return nil, fmt.Errorf("request GetListFields failed: %v", errs[0])
|
||||
}
|
||||
|
||||
if statusCode != fiber.StatusOK {
|
||||
errorMessage := fmt.Sprintf("received an incorrect response from GetListFields: %s", string(resBody))
|
||||
b.logger.Error(errorMessage, zap.Int("status", statusCode))
|
||||
return nil, fmt.Errorf(errorMessage)
|
||||
}
|
||||
|
||||
fmt.Println(string(resBody))
|
||||
|
||||
var listFields models.DealFields
|
||||
err := json.Unmarshal(resBody, &listFields)
|
||||
if err != nil {
|
||||
b.logger.Error("error unmarshal models.Company:", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return listFields, nil
|
||||
}
|
||||
}
|
||||
time.Sleep(b.rateLimiter.Interval)
|
||||
|
||||
@ -22,7 +22,7 @@ func TestGetListFields(t *testing.T) {
|
||||
RateLimiter: lim,
|
||||
})
|
||||
|
||||
result, err := b.GetListFields(models.FieldTypeCompany, "a89bed660000071b00717f9200000001000007c21c22f62d8182a9139ed2bebb28dc9a", "b24-ld76ub.bitrix24.ru")
|
||||
result, err := b.GetListFields(models.FieldTypeDeal, "e1dcef660000071b00717f92000000010000077366a55cee7db57eae54d2f958526f89", "b24-ld76ub.bitrix24.ru")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user