From eb1ceef1e5c97641cdefc2678b06a24c0cb1c8d0 Mon Sep 17 00:00:00 2001
From: Dmitry Dmitriev
Date: Mon, 28 Dec 2020 09:38:40 +0300
Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?=
=?UTF-8?q?=D0=BB=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8=20=D0=B4=D0=B0?=
=?UTF-8?q?=D0=BD=D0=BD=D1=8B=D1=85?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
amo/amocrm.go | 23 +++++++-------
models/companies/companies.go | 38 ++++++++++++++++++++++++
models/contacts/contacts.go | 56 +++++++++++++++++++++++++++++++++++
models/{ => leads}/leads.go | 2 +-
models/{ => users}/users.go | 2 +-
5 files changed, 109 insertions(+), 12 deletions(-)
create mode 100644 models/companies/companies.go
create mode 100644 models/contacts/contacts.go
rename models/{ => leads}/leads.go (99%)
rename models/{ => users}/users.go (93%)
diff --git a/amo/amocrm.go b/amo/amocrm.go
index 02b87a2..4c37618 100644
--- a/amo/amocrm.go
+++ b/amo/amocrm.go
@@ -3,7 +3,10 @@ package amo
import (
"fmt"
"github.com/qdimka/go-amo/api"
- "github.com/qdimka/go-amo/models"
+ "github.com/qdimka/go-amo/models/companies"
+ "github.com/qdimka/go-amo/models/contacts"
+ "github.com/qdimka/go-amo/models/leads"
+ "github.com/qdimka/go-amo/models/users"
)
type AmoClient struct {
@@ -21,8 +24,8 @@ func NewAmoClient(options *api.ClientOptions) (*AmoClient, error) {
}, nil
}
-func (client *AmoClient) GetLead(leadId string, query string) (*models.Lead, error) {
- deal := new(models.Lead)
+func (client *AmoClient) GetLead(leadId string, query string) (*leads.Lead, error) {
+ deal := new(leads.Lead)
resource := fmt.Sprintf("/api/v4/leads/%s", leadId)
if len(query) != 0 {
resource = resource + "?" + query
@@ -32,19 +35,19 @@ func (client *AmoClient) GetLead(leadId string, query string) (*models.Lead, err
return deal, err
}
-func (client *AmoClient) GetUser(userId string) (*models.User, error) {
- user := new(models.User)
+func (client *AmoClient) GetUser(userId string) (*users.User, error) {
+ user := new(users.User)
err := client.api.Get(fmt.Sprintf("/api/v4/users/%s", userId), user)
return user, err
}
-func (client *AmoClient) UpdateLead(lead *models.Lead) error {
+func (client *AmoClient) UpdateLead(lead *leads.Lead) error {
err := client.api.Patch(fmt.Sprintf("/api/v4/leads/%d", lead.ID), lead, nil)
return err
}
-func (client *AmoClient) GetCompany(companyId string, query string) (*models.Lead, error) {
- deal := new(models.Lead)
+func (client *AmoClient) GetCompany(companyId string, query string) (*companies.Company, error) {
+ deal := new(companies.Company)
resource := fmt.Sprintf("/api/v4/companies/%s", companyId)
if len(query) != 0 {
resource = resource + "?" + query
@@ -54,8 +57,8 @@ func (client *AmoClient) GetCompany(companyId string, query string) (*models.Lea
return deal, err
}
-func (client *AmoClient) GetContact(contactId string, query string) (*models.Lead, error) {
- deal := new(models.Lead)
+func (client *AmoClient) GetContact(contactId string, query string) (*contacts.Contact, error) {
+ deal := new(contacts.Contact)
resource := fmt.Sprintf("/api/v4/contacts/%s", contactId)
if len(query) != 0 {
resource = resource + "?" + query
diff --git a/models/companies/companies.go b/models/companies/companies.go
new file mode 100644
index 0000000..1095983
--- /dev/null
+++ b/models/companies/companies.go
@@ -0,0 +1,38 @@
+package companies
+
+type Company struct {
+ ID int `json:"id"`
+ Name string `json:"name"`
+ ResponsibleUserID int `json:"responsible_user_id"`
+ GroupID int `json:"group_id"`
+ CreatedBy int `json:"created_by"`
+ UpdatedBy int `json:"updated_by"`
+ CreatedAt int `json:"created_at"`
+ UpdatedAt int `json:"updated_at"`
+ ClosestTaskAt interface{} `json:"closest_task_at"`
+ CustomFieldsValues []CustomFieldsValues `json:"custom_fields_values"`
+ AccountID int `json:"account_id"`
+ Links Links `json:"_links"`
+ Embedded Embedded `json:"_embedded"`
+}
+type Values struct {
+ Value string `json:"value"`
+ EnumID int `json:"enum_id"`
+ Enum string `json:"enum"`
+}
+type CustomFieldsValues struct {
+ FieldID int `json:"field_id"`
+ FieldName string `json:"field_name"`
+ FieldCode string `json:"field_code"`
+ FieldType string `json:"field_type"`
+ Values []Values `json:"values"`
+}
+type Self struct {
+ Href string `json:"href"`
+}
+type Links struct {
+ Self Self `json:"self"`
+}
+type Embedded struct {
+ Tags []interface{} `json:"tags"`
+}
diff --git a/models/contacts/contacts.go b/models/contacts/contacts.go
new file mode 100644
index 0000000..80b8437
--- /dev/null
+++ b/models/contacts/contacts.go
@@ -0,0 +1,56 @@
+package contacts
+
+type Contact struct {
+ ID int `json:"id"`
+ Name string `json:"name"`
+ FirstName string `json:"first_name"`
+ LastName string `json:"last_name"`
+ ResponsibleUserID int `json:"responsible_user_id"`
+ GroupID int `json:"group_id"`
+ CreatedBy int `json:"created_by"`
+ UpdatedBy int `json:"updated_by"`
+ CreatedAt int `json:"created_at"`
+ UpdatedAt int `json:"updated_at"`
+ ClosestTaskAt interface{} `json:"closest_task_at"`
+ CustomFieldsValues []CustomFieldsValues `json:"custom_fields_values"`
+ AccountID int `json:"account_id"`
+ Links Links `json:"_links"`
+ Embedded Embedded `json:"_embedded"`
+}
+type Values struct {
+ Value string `json:"value"`
+ EnumID int `json:"enum_id"`
+ Enum string `json:"enum"`
+}
+type CustomFieldsValues struct {
+ FieldID int `json:"field_id"`
+ FieldName string `json:"field_name"`
+ FieldCode string `json:"field_code"`
+ FieldType string `json:"field_type"`
+ Values []Values `json:"values"`
+}
+type Self struct {
+ Href string `json:"href"`
+}
+type Links struct {
+ Self Self `json:"self"`
+}
+type Leads struct {
+ ID int `json:"id"`
+ Links Links `json:"_links"`
+}
+type Customers struct {
+ ID int `json:"id"`
+ Links Links `json:"_links"`
+}
+type Companies struct {
+ ID int `json:"id"`
+ Links Links `json:"_links"`
+}
+type Embedded struct {
+ Tags []interface{} `json:"tags"`
+ Leads []Leads `json:"leads"`
+ Customers []Customers `json:"customers"`
+ CatalogElements []interface{} `json:"catalog_elements"`
+ Companies []Companies `json:"companies"`
+}
diff --git a/models/leads.go b/models/leads/leads.go
similarity index 99%
rename from models/leads.go
rename to models/leads/leads.go
index 02a64d7..eb11cf1 100644
--- a/models/leads.go
+++ b/models/leads/leads.go
@@ -1,4 +1,4 @@
-package models
+package leads
type Lead struct {
ID int `json:"id"`
diff --git a/models/users.go b/models/users/users.go
similarity index 93%
rename from models/users.go
rename to models/users/users.go
index 96e6987..b08d497 100644
--- a/models/users.go
+++ b/models/users/users.go
@@ -1,4 +1,4 @@
-package models
+package users
type User struct {
ID int `json:"id"`