From a2fdb06219d57901b85ef197f3eb68113c1b2f06 Mon Sep 17 00:00:00 2001 From: DmitryZagorulko Date: Wed, 11 Apr 2018 13:39:43 +0300 Subject: [PATCH 1/5] add methods for costs, customFields, customDictionaries --- v5/client.go | 635 ++++++++++++++++++++++++++++++++++++++++++++++ v5/client_test.go | 390 ++++++++++++++++++++++++++++ v5/filters.go | 36 +++ v5/request.go | 27 ++ v5/response.go | 58 +++++ v5/types.go | 68 +++++ 6 files changed, 1214 insertions(+) diff --git a/v5/client.go b/v5/client.go index 5f34ae0..3746a31 100644 --- a/v5/client.go +++ b/v5/client.go @@ -2062,3 +2062,638 @@ func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, errs.Failure) { return resp, status, err } + +// Getting of the cost list, adequate for the given filter +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Costs(CostsRequest{ +// Filter: CostsFilter{ +// Ids: []string{"1","2","3"}, +// MinSumm: "1000" +// }, +// }) +// +// if err.ErrorMsg != "" { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// for _, value := range data.Costs { +// fmt.Printf("%v\n", value.Summ) +// } +func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, ErrorResponse) { + var resp CostsResponse + + params, _ := query.Values(costs) + + data, status, err := c.GetRequest(fmt.Sprintf("/costs?%s", params.Encode())) + + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// Creation of the cost +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CostCreate( +// v5.CostRecord{ +// DateFrom: "2012-12-12", +// DateTo: "2012-12-12", +// Summ: 12, +// CostItem: "calculation-of-costs", +// Order: Order{ +// Number: "1" +// }, +// Sites: []string{"store"}, +// }, +// "store" +// ) +// +// if err.ErrorMsg != "" { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// If data.Success == true { +// fmt.Printf("%v", data.ID) +// } +func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, int, ErrorResponse) { + var resp CreateResponse + + costJSON, _ := json.Marshal(&cost) + + p := url.Values{ + "cost": {string(costJSON[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest("/costs/create", p) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// Method allows to remove batch up to 50 costs. +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.client.CostsDelete([]int{1, 2, 3, 48, 49, 50}) +// +// if err.ErrorMsg != "" { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// If data.Success == true { +// fmt.Printf("Not removed costs: %v", data.NotRemovedIds) +// } +func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, ErrorResponse) { + var resp CostsDeleteResponse + + costJSON, _ := json.Marshal(&ids) + + p := url.Values{ + "ids": {string(costJSON[:])}, + } + + data, status, err := c.PostRequest("/costs/delete", p) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// Method allows to upload as packet up to 50 costs. +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CostCreate([]v5.CostRecord{ +// { +// DateFrom: "2012-12-12", +// DateTo: "2012-12-12", +// Summ: 12, +// CostItem: "calculation-of-costs", +// Order: Order{ +// Number: "1" +// }, +// Sites: []string{"store"}, +// }, +// { +// DateFrom: "2012-12-13", +// DateTo: "2012-12-13", +// Summ: 13, +// CostItem: "seo", +// } +// }) +// +// if err.ErrorMsg != "" { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// If data.Success == true { +// fmt.Printf("Uploaded costs: %v", data.UploadedCosts) +// } +func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, ErrorResponse) { + var resp CostsUploadResponse + + costJSON, _ := json.Marshal(&cost) + + p := url.Values{ + "costs": {string(costJSON[:])}, + } + + data, status, err := c.PostRequest("/costs/upload", p) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// Getting of cost information +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Cost(1) +// +// if err.ErrorMsg != "" { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// If data.Success == true { +// fmt.Printf("%v", data.Cost) +// } +func (c *Client) Cost(id int) (CostResponse, int, ErrorResponse) { + var resp CostResponse + + data, status, err := c.GetRequest(fmt.Sprintf("/costs/%d", id)) + + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// Cost removing +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CostDelete(1) +// +// if err.ErrorMsg != "" { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ErrorMsg) +// } +func (c *Client) CostDelete(id int) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse + + costJSON, _ := json.Marshal(&id) + + p := url.Values{ + "costs": {string(costJSON[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("/costs/%d/delete", id), p) + + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// Cost editing +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CostEdit(1, v5.Cost{ +// DateFrom: "2012-12-12", +// DateTo: "2018-12-13", +// Summ: 321, +// CostItem: "seo", +// }) +// +// if err.ErrorMsg != "" { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// If data.Success == true { +// fmt.Printf("%v", data.Id) +// } +func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateResponse, int, ErrorResponse) { + var resp CreateResponse + + costJSON, _ := json.Marshal(&cost) + + p := url.Values{ + "cost": {string(costJSON[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest(fmt.Sprintf("/costs/%d/edit", id), p) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// Getting the list of custom fields +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomFields(v5.CustomFieldsRequest{ +// Type: "string", +// Entity: "customer", +// }) +// +// if err.ErrorMsg != "" { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// for _, value := range data.CustomFields { +// fmt.Printf("%v\n", value) +// } +func (c *Client) CustomFields(customFields CustomFieldsRequest) (CustomFieldsResponse, int, ErrorResponse) { + var resp CustomFieldsResponse + + params, _ := query.Values(customFields) + + data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields?%s", params.Encode())) + + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// Getting the list of custom directory +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomDictionaries(v5.CustomDictionariesRequest{ +// Filter: v5.CustomDictionariesFilter{ +// Name: "Dictionary-1", +// }, +// }) +// +// if err.ErrorMsg != "" { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// for _, value := range data.CustomDictionaries { +// fmt.Printf("%v\n", value.Elements) +// } +func (c *Client) CustomDictionaries(customDictionaries CustomDictionariesRequest) (CustomDictionariesResponse, int, ErrorResponse) { + var resp CustomDictionariesResponse + + params, _ := query.Values(customDictionaries) + + data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields/dictionaries?%s", params.Encode())) + + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// Directory fields creation +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomDictionariesCreate(v5.CustomDictionary{ +// Name: "Courier profiles", +// Code: "courier-profiles", +// Elements: []Element{ +// { +// Name: "Name", +// Code: "name", +// }, +// { +// Name: "Lastname", +// Code: "lastname", +// } +// }, +// }) +// +// if err.ErrorMsg != "" { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// If data.Success == true { +// fmt.Printf("%v", data.Code) +// } +func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (CustomResponse, int, ErrorResponse) { + var resp CustomResponse + + costJSON, _ := json.Marshal(&customDictionary) + + p := url.Values{ + "customDictionary": {string(costJSON[:])}, + } + + data, status, err := c.PostRequest("/custom-fields/dictionaries/create", p) + + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// Getting information on directory +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomDictionary("courier-profiles") +// +// if err.ErrorMsg != "" { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// If data.Success == true { +// fmt.Printf("%v", data.CustomDictionary.Name) +// } +func (c *Client) CustomDictionary(code string) (CustomDictionaryResponse, int, ErrorResponse) { + var resp CustomDictionaryResponse + + data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields/dictionaries/%s", code)) + + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// Directory fields editing +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomDictionaryEdit(v5.CustomDictionary{ +// Name: "Courier profiles", +// Code: "courier-profiles", +// Elements: []Element{ +// { +// Name: "Name", +// Code: "name", +// }, +// { +// Name: "Lastname", +// Code: "lastname", +// } +// }, +// }) +// +// if err.ErrorMsg != "" { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// If data.Success == true { +// fmt.Printf("%v", data.Code) +// } +func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (CustomResponse, int, ErrorResponse) { + var resp CustomResponse + + costJSON, _ := json.Marshal(&customDictionary) + + p := url.Values{ + "customDictionary": {string(costJSON[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/dictionaries/%s/edit", customDictionary.Code), p) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// Custom fields creation +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomFieldsCreate(v5.CustomFieldsEditRequest{ +// CustomField: v5.CustomFields{ +// Name: "First order", +// Code: "first-order", +// Type: "bool", +// Entity: "order", +// DisplayArea: "customer", +// }, +// }) +// +// if err.ErrorMsg != "" { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// If data.Success == true { +// fmt.Printf("%v", data.Code) +// } +func (c *Client) CustomFieldsCreate(customFields CustomFieldsEditRequest) (CustomResponse, int, ErrorResponse) { + var resp CustomResponse + + costJSON, _ := json.Marshal(&customFields) + + p := url.Values{ + "customField": {string(costJSON[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/%s/create", customFields.CustomField.Entity), p) + + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// Getting information on custom fields +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomField("order", "first-order") +// +// if err.ErrorMsg != "" { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// If data.Success == true { +// fmt.Printf("%v", data.CustomField) +// } +func (c *Client) CustomField(entity, code string) (CustomFieldResponse, int, ErrorResponse) { + var resp CustomFieldResponse + + data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields/%s/%s", entity, code)) + + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// CustomFieldEdit list method +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomFieldEdit("order", v5.CustomFieldsEditRequest{ +// CustomField: v5.CustomFields{ +// Name: "First customer order", +// Code: "first-order", +// }, +// }) +// +// if err.ErrorMsg != "" { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// If data.Success == true { +// fmt.Printf("%v", data.Code) +// } +func (c *Client) CustomFieldEdit(entity string, customFields CustomFieldsEditRequest) (CustomResponse, int, ErrorResponse) { + var resp CustomResponse + + costJSON, _ := json.Marshal(&customFields) + + p := url.Values{ + "customField": {string(costJSON[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/%s/%s/edit", entity, customFields.CustomField.Code), p) + + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} diff --git a/v5/client_test.go b/v5/client_test.go index f234ebf..f5fe87e 100644 --- a/v5/client_test.go +++ b/v5/client_test.go @@ -14,6 +14,8 @@ import ( var r *rand.Rand // Rand for this package. var user, _ = strconv.Atoi(os.Getenv("RETAILCRM_USER")) var statuses = map[int]bool{http.StatusOK: true, http.StatusCreated: true} +var id int +var ids []int func init() { r = rand.New(rand.NewSource(time.Now().UnixNano())) @@ -1850,3 +1852,391 @@ func TestClient_DeliveryShipments(t *testing.T) { t.Errorf("%v", err.ApiError()) } } + +func TestClient_CostCreate(t *testing.T) { + c := client() + + data, status, err := c.CostCreate(CostRecord{ + DateFrom: "2018-04-02", + DateTo: "2018-04-02", + Summ: 124, + CostItem: "seo", + }) + + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + id = data.ID +} + +func TestClient_Costs(t *testing.T) { + c := client() + + data, status, err := c.Costs(CostsRequest{ + Filter: CostsFilter{ + Ids: []string{strconv.Itoa(id)}, + }, + Limit: 20, + Page: 1, + }) + + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_Cost(t *testing.T) { + c := client() + + data, status, err := c.Cost(id) + + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_CostEdit(t *testing.T) { + c := client() + + data, status, err := c.CostEdit(id, CostRecord{ + DateFrom: "2018-04-09", + DateTo: "2018-04-09", + Summ: 421, + CostItem: "seo", + Order: nil, + }) + + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_CostDelete(t *testing.T) { + c := client() + + data, status, err := c.CostDelete(id) + + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_CostsUpload(t *testing.T) { + c := client() + + data, status, err := c.CostsUpload([]CostRecord{ + { + Source: nil, + DateFrom: "2018-04-02", + DateTo: "2018-04-02", + Summ: 124, + CostItem: "seo", + Order: nil, + }, + { + Source: nil, + DateFrom: "2018-04-03", + DateTo: "2018-04-03", + Summ: 125, + CostItem: "seo", + Order: nil, + Sites: []string{"catalog-test"}, + }, + }) + + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + ids = data.UploadedCosts +} + +func TestClient_CostsDelete(t *testing.T) { + c := client() + data, status, err := c.CostsDelete(ids) + + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_CustomFields(t *testing.T) { + c := client() + + data, status, err := c.CustomFields(CustomFieldsRequest{}) + + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} +func TestClient_CustomDictionaries(t *testing.T) { + c := client() + + data, status, err := c.CustomDictionaries(CustomDictionariesRequest{ + Filter: CustomDictionariesFilter{ + Name: "test", + }, + Limit: 10, + Page: 1, + }) + + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_CustomDictionary(t *testing.T) { + c := client() + + data, status, err := c.CustomDictionary("test2") + + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_CustomDictionariesCreate(t *testing.T) { + c := client() + + data, status, err := c.CustomDictionariesCreate(CustomDictionary{ + Name: "test2", + Code: "test2", + Elements: []Element{ + { + Name: "test", + Code: "test", + }, + }, + }) + + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_CustomDictionaryEdit(t *testing.T) { + c := client() + + data, status, err := c.CustomDictionaryEdit(CustomDictionary{ + Name: "test223", + Code: "test2", + Elements: []Element{ + { + Name: "test3", + Code: "test3", + }, + }, + }) + + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_CustomFieldsCreate(t *testing.T) { + c := client() + + data, status, err := c.CustomFieldsCreate(CustomFieldsEditRequest{ + CustomField: CustomFields{ + Name: "test4", + Code: "test4", + Type: "text", + Entity: "order", + DisplayArea: "customer", + }, + }) + + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_CustomField(t *testing.T) { + c := client() + + data, status, err := c.CustomField("customer", "testtest") + + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_CustomFieldEdit(t *testing.T) { + c := client() + + data, status, err := c.CustomFieldEdit("customer", CustomFieldsEditRequest{ + CustomField: CustomFields{ + Name: "testtesttest", + }, + }) + + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} diff --git a/v5/filters.go b/v5/filters.go index 44ea11b..50f36b9 100644 --- a/v5/filters.go +++ b/v5/filters.go @@ -296,3 +296,39 @@ type ShipmentFilter struct { DeliveryTypes []string `url:"deliveryTypes,omitempty,brackets"` Statuses []string `url:"statuses,omitempty,brackets"` } + +// CostsFilter type +type CostsFilter struct { + MinSumm string `url:"minSumm,omitempty"` + MaxSumm string `url:"maxSumm,omitempty"` + OrderNumber string `url:"orderNumber,omitempty"` + Comment string `url:"orderNumber,omitempty"` + Ids []string `url:"ids,omitempty,brackets"` + Sites []string `url:"sites,omitempty,brackets"` + CreatedBy []string `url:"createdBy,omitempty,brackets"` + CostGroups []string `url:"costGroups,omitempty,brackets"` + CostItems []string `url:"costItems,omitempty,brackets"` + Users []string `url:"users,omitempty,brackets"` + DateFrom string `url:"dateFrom,omitempty"` + DateTo string `url:"dateTo,omitempty"` + CreatedAtFrom string `url:"createdAtFrom,omitempty"` + CreatedAtTo string `url:"createdAtTo,omitempty"` + OrderIds []string `url:"orderIds,omitempty,brackets"` + OrderExternalIds []string `url:"orderIds,omitempty,brackets"` +} + +// CustomFieldsFilter type +type CustomFieldsFilter struct { + Name string `url:"name,omitempty"` + Code string `url:"code,omitempty"` + Type string `url:"type,omitempty"` + Entity string `url:"entity,omitempty"` + ViewMode string `url:"viewMode,omitempty"` + DisplayArea string `url:"displayArea,omitempty"` +} + +// CustomDictionariesFilter type +type CustomDictionariesFilter struct { + Name string `url:"name,omitempty"` + Code string `url:"code,omitempty"` +} diff --git a/v5/request.go b/v5/request.go index 95145ee..9c024a1 100644 --- a/v5/request.go +++ b/v5/request.go @@ -142,3 +142,30 @@ type DeliveryShipmentsRequest struct { Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } + +// CostsRequest type +type CostsRequest struct { + Filter CostsFilter `url:"filter,omitempty"` + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} + +// CustomFieldsRequest type +type CustomFieldsRequest struct { + Filter CustomFieldsFilter `url:"filter,omitempty"` + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} + +// CustomeDictionariesRequest type +type CustomDictionariesRequest struct { + Filter CustomDictionariesFilter `url:"filter,omitempty"` + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} + +// CustomFieldsEditRequest type +type CustomFieldsEditRequest struct { + CustomField CustomFields `url:"customField,omitempty"` + Entity string `url:"entity,omitempty"` +} diff --git a/v5/response.go b/v5/response.go index 84d4fd0..d9cf2b2 100644 --- a/v5/response.go +++ b/v5/response.go @@ -328,3 +328,61 @@ type IntegrationModuleEditResponse struct { Success bool `json:"success"` Info map[string]string `json:"info,omitempty,brackets"` } + +// CostsResponse type +type CostsResponse struct { + Success bool `json:"success"` + Pagination *Pagination `json:"pagination,omitempty"` + Costs []Cost `json:"costs,omitempty,brackets"` +} + +// CostsUploadResponse type +type CostsUploadResponse struct { + Success bool `json:"success"` + UploadedCosts []int `json:"uploadedCosts,omitempty,brackets"` +} + +// CostsDeleteResponse type +type CostsDeleteResponse struct { + Success bool `json:"success"` + Count int `json:"count,omitempty,brackets"` + NotRemovedIds []int `json:"notRemovedIds,omitempty,brackets"` +} + +// CostResponse type +type CostResponse struct { + Success bool `json:"success"` + Cost *Cost `json:"cost,omitempty,brackets"` +} + +// CustomFieldsResponse type +type CustomFieldsResponse struct { + Success bool `json:"success"` + Pagination *Pagination `json:"pagination,omitempty"` + CustomFields []CustomFields `json:"customFields,omitempty,brackets"` +} + +// CustomDictionariesResponse type +type CustomDictionariesResponse struct { + Success bool `json:"success"` + Pagination *Pagination `json:"pagination,omitempty"` + CustomDictionaries *[]CustomDictionary `json:"customDictionaries,omitempty,brackets"` +} + +// CustomDictionariesResponse type +type CustomResponse struct { + Success bool `json:"success"` + Code string `json:"code,omitempty"` +} + +// CustomDictionaryResponse type +type CustomDictionaryResponse struct { + Success bool `json:"success"` + CustomDictionary *CustomDictionary `json:"CustomDictionary,omitempty,brackets"` +} + +// CustomFieldResponse type +type CustomFieldResponse struct { + Success bool `json:"success"` + CustomField CustomFields `json:"customField,omitempty,brackets"` +} diff --git a/v5/types.go b/v5/types.go index 8cec992..76d20b2 100644 --- a/v5/types.go +++ b/v5/types.go @@ -864,3 +864,71 @@ type Action struct { URL string `json:"url,omitempty"` CallPoints []string `json:"callPoints,omitempty"` } + +/** +Cost related types +*/ + +// CostRecord type +type CostRecord struct { + Source *Source `json:"source,omitempty"` + Comment string `json:"comment,omitempty"` + DateFrom string `json:"dateFrom,omitempty"` + DateTo string `json:"dateTo,omitempty"` + Summ float32 `json:"summ,omitempty"` + CostItem string `json:"costItem,omitempty"` + UserId int `json:"userId,omitempty"` + Order *Order `json:"order,omitempty"` + Sites []string `json:"sites,omitempty,brackets"` +} + +// Cost type +type Cost struct { + Source *Source `json:"source,omitempty"` + ID int `json:"id,omitempty"` + DateFrom string `json:"dateFrom,omitempty"` + DateTo string `json:"dateTo,omitempty"` + Summ float32 `json:"summ,omitempty"` + CostItem string `json:"costItem,omitempty"` + Comment string `json:"comment,omitempty"` + CreatedAt string `json:"createdAt,omitempty"` + CreatedBy string `json:"createdBy,omitempty"` + Order *Order `json:"order,omitempty"` + UserId int `json:"userId,omitempty"` + Sites []string `json:"sites,omitempty,brackets"` +} + +// CustomFields type +type CustomFields struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + Required bool `json:"required,omitempty"` + InFilter bool `json:"inFilter,omitempty"` + InList bool `json:"inList,omitempty"` + InGroupActions bool `json:"inGroupActions,omitempty"` + Type string `json:"type,omitempty"` + Entity string `json:"entity,omitempty"` + Default string `json:"default,omitempty"` + Ordering int `json:"ordering,omitempty"` + DisplayArea string `json:"displayArea,omitempty"` + ViewMode string `json:"viewMode,omitempty"` + Dictionary string `json:"dictionary,omitempty"` +} + +/** +CustomeDictionaries related types +*/ + +// customDictionary type +type CustomDictionary struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + Elements []Element `json:"elements,omitempty,brackets"` +} + +// Dictionary Element type +type Element struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + Ordering int `json:"ordering,omitempty"` +} From ed9b0a439650c447053a3e47a92aa9977c2a6894 Mon Sep 17 00:00:00 2001 From: DmitryZagorulko Date: Thu, 12 Apr 2018 16:43:53 +0300 Subject: [PATCH 2/5] add documentation, bug fix --- v5/client.go | 1773 ++++++++++++++++++++++++++++++++++++++++----- v5/client_test.go | 236 +++--- v5/request.go | 7 +- 3 files changed, 1683 insertions(+), 333 deletions(-) diff --git a/v5/client.go b/v5/client.go index 3746a31..ac6bf00 100644 --- a/v5/client.go +++ b/v5/client.go @@ -148,6 +148,8 @@ func fillSite(p *url.Values, site []string) { // APIVersions get all available API versions for exact account // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-api-versions +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") @@ -155,11 +157,11 @@ func fillSite(p *url.Values, site []string) { // data, status, err := client.APIVersions() // // if err.RuntimeErr != nil { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // for _, value := range data.versions { @@ -184,6 +186,8 @@ func (c *Client) APIVersions() (VersionResponse, int, errs.Failure) { // APICredentials get all available API methods for exact account // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-api-versions +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") @@ -191,11 +195,11 @@ func (c *Client) APIVersions() (VersionResponse, int, errs.Failure) { // data, status, err := client.APICredentials() // // if err.RuntimeErr != nil { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // for _, value := range data.credentials { @@ -218,7 +222,32 @@ func (c *Client) APICredentials() (CredentialResponse, int, errs.Failure) { return resp, status, err } -// Customers list method +// Getting the list of customers matched the specified filter +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Customers(v5.CustomersRequest{ +// Filter: CustomersFilter{ +// City: "Moscow", +// }, +// Page: 3, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Customers { +// fmt.Printf("%v\n", value) +// } func (c *Client) Customers(parameters CustomersRequest) (CustomersResponse, int, errs.Failure) { var resp CustomersResponse @@ -238,7 +267,23 @@ func (c *Client) Customers(parameters CustomersRequest) (CustomersResponse, int, return resp, status, err } -// CustomersCombine method +// Combining of customers +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-combine +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomersCombine([]v5.Customer{{ID: 1}, {ID: 2}}, Customer{ID: 3}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -264,7 +309,37 @@ func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) return resp, status, err } -// CustomerCreate method +// Customer creation +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-create +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomersCombine(v5.Customer{ +// FirstName: "Ivan", +// LastName: "Ivanov", +// Patronymic: "Ivanovich", +// ExternalID: 1, +// Email: "ivanov@example.com", +// Address: &v5.Address{ +// City: "Moscow", +// Street: "Kutuzovsky", +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v", err.Id) +// } func (c *Client) CustomerCreate(customer Customer, site ...string) (CustomerChangeResponse, int, errs.Failure) { var resp CustomerChangeResponse @@ -290,7 +365,26 @@ func (c *Client) CustomerCreate(customer Customer, site ...string) (CustomerChan return resp, status, err } -// CustomersFixExternalIds method +// The mass recording of customers external ID +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-fix-external-ids +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomersFixExternalIds([]v5.IdentifiersPair{{ +// ID: 1, +// ExternalID: 12, +// }}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -314,7 +408,31 @@ func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (Successfu return resp, status, err } -// CustomersHistory method +// Getting the customer change history +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers-history +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomersHistory(v5.CustomersHistoryRequest{ +// Filter: v5.CustomersHistoryFilter{ +// SinceID: 20, +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.History { +// fmt.Printf("%v\n", value) +// } func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (CustomersHistoryResponse, int, errs.Failure) { var resp CustomersHistoryResponse @@ -334,7 +452,32 @@ func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (Customers return resp, status, err } -// CustomerNotes list method +// Getting the notes +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers-notes +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomerNotes(v5.NotesRequest{ +// Filter: v5.NotesFilter{ +// CustomerIds: []int{1,2,3} +// }, +// Page: 1, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Notes { +// fmt.Printf("%v\n", value) +// } func (c *Client) CustomerNotes(parameters NotesRequest) (NotesResponse, int, errs.Failure) { var resp NotesResponse @@ -354,7 +497,33 @@ func (c *Client) CustomerNotes(parameters NotesRequest) (NotesResponse, int, err return resp, status, err } -// CustomerNoteCreate method +// Note creation +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-notes-create +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomerNoteCreate(v5.Note{ +// Text: "some text", +// ManagerID: 12, +// Customer: &v5.Customer{ +// ID: 1, +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.ID) +// } func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, int, errs.Failure) { var resp CreateResponse @@ -380,7 +549,23 @@ func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, return resp, status, err } -// CustomerNoteDelete method +// Note removing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-notes-id-delete +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomerNoteDelete(12) + +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) CustomerNoteDelete(id int) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -402,7 +587,42 @@ func (c *Client) CustomerNoteDelete(id int) (SuccessfulResponse, int, errs.Failu return resp, status, err } -// CustomersUpload method +// Packet customers uploading +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-upload +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomersUpload([]v5.Customer{ +// { +// FirstName: "Ivan", +// LastName: "Ivanov", +// Patronymic: "Ivanovich", +// ExternalID: 1, +// Email: "ivanov@example.com", +// }, +// { +// FirstName: "Petr", +// LastName: "Petrov", +// Patronymic: "Petrovich", +// ExternalID: 2, +// Email: "petrov@example.com", +// }, +// }} +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.UploadedCustomers) +// } func (c *Client) CustomersUpload(customers []Customer, site ...string) (CustomersUploadResponse, int, errs.Failure) { var resp CustomersUploadResponse @@ -428,7 +648,27 @@ func (c *Client) CustomersUpload(customers []Customer, site ...string) (Customer return resp, status, err } -// Customer get method +// Getting information on customer +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers-externalId +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Customer(12, "externalId", "") +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.Customer) +// } func (c *Client) Customer(id, by, site string) (CustomerResponse, int, errs.Failure) { var resp CustomerResponse var context = checkBy(by) @@ -450,7 +690,36 @@ func (c *Client) Customer(id, by, site string) (CustomerResponse, int, errs.Fail return resp, status, err } -// CustomerEdit method +// Customer editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-externalId-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomerEdit( +// v5.Customer{ +// FirstName: "Ivan", +// LastName: "Ivanov", +// Patronymic: "Ivanovich", +// ID: 1, +// Email: "ivanov@example.com", +// }, +// "id", +// ) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.Customer) +// } func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (CustomerChangeResponse, int, errs.Failure) { var resp CustomerChangeResponse var uid = strconv.Itoa(customer.ID) @@ -483,7 +752,36 @@ func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (Cus return resp, status, err } -// DeliveryTracking method +// Updating of delivery statuses +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-delivery-generic-subcode-tracking +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.DeliveryTracking( +// v5.DeliveryTrackingRequest{ +// DeliveryID: "1", +// TrackNumber "123", +// History: []DeliveryHistoryRecord{ +// { +// Code: "cancel", +// UpdatedAt: "2012-12-12 12:12:12" +// }, +// } +// }, +// "delivery-1", +// ) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode string) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -507,7 +805,32 @@ func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode st return resp, status, err } -// DeliveryShipments method +// Getting the list of shipments to delivery services +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-delivery-shipments +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.DeliveryShipments(v5.DeliveryShipmentsRequest{ +// Limit: 12, +// Filter: v5.ShipmentFilter{ +// DateFrom: "2012-12-12", +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.DeliveryShipments { +// fmt.Printf("%v\n", value) +// } func (c *Client) DeliveryShipments(parameters DeliveryShipmentsRequest) (DeliveryShipmentsResponse, int, errs.Failure) { var resp DeliveryShipmentsResponse @@ -527,7 +850,37 @@ func (c *Client) DeliveryShipments(parameters DeliveryShipmentsRequest) (Deliver return resp, status, err } -// DeliveryShipmentCreate method +// Shipment creation +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-delivery-shipments-create +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.DeliveryShipmentCreate( +// v5.DeliveryShipment{ +// Date: "2012-12-12", +// Time: v5.DeliveryTime{ +// From: "18:00", +// To: "20:00", +// }, +// Orders: []v5.Order{{Number: "12"}}, +// }, +// "sdek", +// ) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.ID) +// } func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType string, site ...string) (DeliveryShipmentUpdateResponse, int, errs.Failure) { var resp DeliveryShipmentUpdateResponse updateJSON, _ := json.Marshal(&shipment) @@ -553,7 +906,27 @@ func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType return resp, status, err } -// DeliveryShipment method +// Getting information on shipment +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-delivery-shipments-id +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.DeliveryShipment(12) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.DeliveryShipment) +// } func (c *Client) DeliveryShipment(id int) (DeliveryShipmentResponse, int, errs.Failure) { var resp DeliveryShipmentResponse @@ -571,7 +944,29 @@ func (c *Client) DeliveryShipment(id int) (DeliveryShipmentResponse, int, errs.F return resp, status, err } -// DeliveryShipmentEdit method +// Shipment editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-delivery-shipments-id-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.DeliveryShipmentEdit(v5.DeliveryShipment{ +// ID: "12", +// Time: v5.DeliveryTime{ +// From: "14:00", +// To: "18:00", +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) (DeliveryShipmentUpdateResponse, int, errs.Failure) { var resp DeliveryShipmentUpdateResponse updateJSON, _ := json.Marshal(&shipment) @@ -596,7 +991,27 @@ func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) return resp, status, err } -// IntegrationModule method +// Getting the integration module +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-integration-modules-code +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.IntegrationModule("moysklad3") +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.IntegrationModule) +// } func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int, errs.Failure) { var resp IntegrationModuleResponse @@ -614,7 +1029,39 @@ func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int, return resp, status, err } -// IntegrationModuleEdit method +// Integration module creation/editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-integration-modules-code +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") + +// name := "MS" +// code := "moysklad3" + +// data, status, err := client.IntegrationModuleEdit(v5.IntegrationModule{ +// Code: code, +// IntegrationCode: code, +// Active: false, +// Name: fmt.Sprintf("Integration module %s", name), +// AccountURL: fmt.Sprintf("http://example.com/%s/account", name), +// BaseURL: fmt.Sprintf("http://example.com/%s", name), +// ClientID: "123", +// Logo: "https://cdn.worldvectorlogo.com/logos/github-icon.svg", +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.Info) +// } func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (IntegrationModuleEditResponse, int, errs.Failure) { var resp IntegrationModuleEditResponse updateJSON, _ := json.Marshal(&integrationModule) @@ -635,7 +1082,27 @@ func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (Int return resp, status, err } -// Orders list method +// Getting the list of orders matched the specified filter +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Orders(v5.OrdersRequest{Filter: v5.OrdersFilter{City: "Moscow"}, Page: 1}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Orders { +// fmt.Printf("%v\n", value) +// } func (c *Client) Orders(parameters OrdersRequest) (OrdersResponse, int, errs.Failure) { var resp OrdersResponse @@ -655,7 +1122,23 @@ func (c *Client) Orders(parameters OrdersRequest) (OrdersResponse, int, errs.Fai return resp, status, err } -// OrdersCombine method +// Combining of orders +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-combine +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrdersCombine("ours", v5.Order{ID: 1}, v5.Order{ID: 1}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (OperationResponse, int, errs.Failure) { var resp OperationResponse @@ -682,7 +1165,33 @@ func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (Oper return resp, status, err } -// OrderCreate method +// Order creation +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-create +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrderCreate(v5.Order{ +// FirstName: "Ivan", +// LastName: "Ivanov", +// Patronymic: "Ivanovich", +// Email: "ivanov@example.com", +// Items: []v5.OrderItem{{Offer: v5.Offer{ID: 12}, Quantity: 5}}, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.ID) +// } func (c *Client) OrderCreate(order Order, site ...string) (CreateResponse, int, errs.Failure) { var resp CreateResponse orderJSON, _ := json.Marshal(&order) @@ -707,7 +1216,30 @@ func (c *Client) OrderCreate(order Order, site ...string) (CreateResponse, int, return resp, status, err } -// OrdersFixExternalIds method +// The mass recording of orders external ID +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-fix-external-ids +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrdersFixExternalIds(([]v5.IdentifiersPair{{ +//// ID: 1, +//// ExternalID: 12, +//// }}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.ID) +// } func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -731,7 +1263,27 @@ func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulRespo return resp, status, err } -// OrdersHistory method +// Getting the order change history +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-history +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrdersHistory(v5.OrdersHistoryRequest{Filter: v5.OrdersHistoryFilter{SinceID: 20}}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.History { +// fmt.Printf("%v\n", value) +// } func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (CustomersHistoryResponse, int, errs.Failure) { var resp CustomersHistoryResponse @@ -751,7 +1303,33 @@ func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (CustomersHistor return resp, status, err } -// OrderPaymentCreate method +// Payment creation +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-payments-create +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrderPaymentCreate(v5.Payment{ +// Order: &v5.Order{ +// ID: 12, +// }, +// Amount: 300, +// Type: "cash", +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.ID) +// } func (c *Client) OrderPaymentCreate(payment Payment, site ...string) (CreateResponse, int, errs.Failure) { var resp CreateResponse @@ -777,7 +1355,23 @@ func (c *Client) OrderPaymentCreate(payment Payment, site ...string) (CreateResp return resp, status, err } -// OrderPaymentDelete method +// Payment removing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-payments-id-delete +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrderPaymentDelete(12) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) OrderPaymentDelete(id int) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -799,7 +1393,29 @@ func (c *Client) OrderPaymentDelete(id int) (SuccessfulResponse, int, errs.Failu return resp, status, err } -// OrderPaymentEdit method +// Payment editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-payments-id-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrderPaymentEdit( +// v5.Payment{ +// ID: 12, +// Amount: 500, +// }, +// "id", +// ) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse var uid = strconv.Itoa(payment.ID) @@ -831,7 +1447,42 @@ func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (S return resp, status, err } -// OrdersUpload method +// Packet orders uploading +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-upload +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrdersUpload([]v5.Order{ +// { +// FirstName: "Ivan", +// LastName: "Ivanov", +// Patronymic: "Ivanovich", +// Email: "ivanov@example.com", +// Items: []v5.OrderItem{{Offer: v5.Offer{ID: 12}, Quantity: 5}}, +// }, +// { +// FirstName: "Pert", +// LastName: "Petrov", +// Patronymic: "Petrovich", +// Email: "petrov@example.com", +// Items: []v5.OrderItem{{Offer: v5.Offer{ID: 13}, Quantity: 1}}, +// } +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.UploadedOrders) +// } func (c *Client) OrdersUpload(orders []Order, site ...string) (OrdersUploadResponse, int, errs.Failure) { var resp OrdersUploadResponse @@ -857,7 +1508,27 @@ func (c *Client) OrdersUpload(orders []Order, site ...string) (OrdersUploadRespo return resp, status, err } -// Order get method +// Getting information on order +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-externalId +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Order(12, "externalId", "") +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.Order) +// } func (c *Client) Order(id, by, site string) (OrderResponse, int, errs.Failure) { var resp OrderResponse var context = checkBy(by) @@ -879,7 +1550,29 @@ func (c *Client) Order(id, by, site string) (OrderResponse, int, errs.Failure) { return resp, status, err } -// OrderEdit method +// Order editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-externalId-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrderEdit( +// v5.Order{ +// ID: 12, +// Items: []v5.OrderItem{{Offer: v5.Offer{ID: 13}, Quantity: 6}}, +// }, +// "id", +// ) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateResponse, int, errs.Failure) { var resp CreateResponse var uid = strconv.Itoa(order.ID) @@ -912,7 +1605,27 @@ func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateRespon return resp, status, err } -// Packs list method +// Getting the list of packs matched the specified filter +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-packs +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Packs(v5.PacksRequest{Filter: v5.PacksFilter{OrderID: 12}}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Packs { +// fmt.Printf("%v\n", value) +// } func (c *Client) Packs(parameters PacksRequest) (PacksResponse, int, errs.Failure) { var resp PacksResponse @@ -932,7 +1645,31 @@ func (c *Client) Packs(parameters PacksRequest) (PacksResponse, int, errs.Failur return resp, status, err } -// PackCreate method +// Pack creation +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-packs-create +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.PackCreate(Pack{ +// Store: "store-1", +// ItemID: 12, +// Quantity: 1, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.ID) +// } func (c *Client) PackCreate(pack Pack) (CreateResponse, int, errs.Failure) { var resp CreateResponse packJSON, _ := json.Marshal(&pack) @@ -955,7 +1692,27 @@ func (c *Client) PackCreate(pack Pack) (CreateResponse, int, errs.Failure) { return resp, status, err } -// PacksHistory method +// Getting the history of order packing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-packs-history +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.PacksHistory(v5.PacksHistoryRequest{Filter: v5.OrdersHistoryFilter{SinceID: 5}}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.History { +// fmt.Printf("%v\n", value) +// } func (c *Client) PacksHistory(parameters PacksHistoryRequest) (PacksHistoryResponse, int, errs.Failure) { var resp PacksHistoryResponse @@ -975,7 +1732,26 @@ func (c *Client) PacksHistory(parameters PacksHistoryRequest) (PacksHistoryRespo return resp, status, err } -// Pack get method +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-packs-id +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Pack(112) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.Pack) +// } func (c *Client) Pack(id int) (PackResponse, int, errs.Failure) { var resp PackResponse @@ -993,7 +1769,23 @@ func (c *Client) Pack(id int) (PackResponse, int, errs.Failure) { return resp, status, err } -// PackDelete method +// Pack removing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-packs-id-delete +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.PackDelete(112) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) PackDelete(id int) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1011,7 +1803,23 @@ func (c *Client) PackDelete(id int) (SuccessfulResponse, int, errs.Failure) { return resp, status, err } -// PackEdit method +// Pack editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-packs-id-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.PackEdit(Pack{ID: 12, Quantity: 2}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) PackEdit(pack Pack) (CreateResponse, int, errs.Failure) { var resp CreateResponse @@ -1035,7 +1843,9 @@ func (c *Client) PackEdit(pack Pack) (CreateResponse, int, errs.Failure) { return resp, status, err } -// Countries method +// Getting the list of available country codes +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-countries func (c *Client) Countries() (CountriesResponse, int, errs.Failure) { var resp CountriesResponse @@ -1053,7 +1863,9 @@ func (c *Client) Countries() (CountriesResponse, int, errs.Failure) { return resp, status, err } -// CostGroups method +// Getting of the costs groups list +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-cost-groups func (c *Client) CostGroups() (CostGroupsResponse, int, errs.Failure) { var resp CostGroupsResponse @@ -1071,7 +1883,26 @@ func (c *Client) CostGroups() (CostGroupsResponse, int, errs.Failure) { return resp, status, err } -// CostGroupEdit method +// Editing costs groups +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-cost-groups-code-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CostGroupEdit(v5.CostGroup{ +// Code: "group-1", +// Color: "#da5c98", +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) CostGroupEdit(costGroup CostGroup) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1095,7 +1926,9 @@ func (c *Client) CostGroupEdit(costGroup CostGroup) (SuccessfulResponse, int, er return resp, status, err } -// CostItems method +// Getting of the costs items list +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-cost-items func (c *Client) CostItems() (CostItemsResponse, int, errs.Failure) { var resp CostItemsResponse @@ -1113,7 +1946,26 @@ func (c *Client) CostItems() (CostItemsResponse, int, errs.Failure) { return resp, status, err } -// CostItemEdit method +// Editing costs items +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-cost-items-code-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CostItemEdit(v5.CostItem{ +// Code: "seo", +// Active: false, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) CostItemEdit(costItem CostItem) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1137,7 +1989,9 @@ func (c *Client) CostItemEdit(costItem CostItem) (SuccessfulResponse, int, errs. return resp, status, err } -// Couriers method +// Getting the list of couriers +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-couriers func (c *Client) Couriers() (CouriersResponse, int, errs.Failure) { var resp CouriersResponse @@ -1155,7 +2009,32 @@ func (c *Client) Couriers() (CouriersResponse, int, errs.Failure) { return resp, status, err } -// CourierCreate method +// Courier creation +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-couriers +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CostItemEdit(v5.Courier{ +// Active: true, +// Email: "courier1@example.com", +// FirstName: "Ivan", +// LastName: "Ivanov", +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v", data.ID) +// } func (c *Client) CourierCreate(courier Courier) (CreateResponse, int, errs.Failure) { var resp CreateResponse @@ -1179,7 +2058,26 @@ func (c *Client) CourierCreate(courier Courier) (CreateResponse, int, errs.Failu return resp, status, err } -// CourierEdit method +// Courier editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-couriers-id-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CostItemEdit(v5.Courier{ +// ID: 1, +// Patronymic: "Ivanovich", +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) CourierEdit(courier Courier) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1203,7 +2101,9 @@ func (c *Client) CourierEdit(courier Courier) (SuccessfulResponse, int, errs.Fai return resp, status, err } -// DeliveryServices method +// Getting the list of delivery services +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-delivery-services func (c *Client) DeliveryServices() (DeliveryServiceResponse, int, errs.Failure) { var resp DeliveryServiceResponse @@ -1221,7 +2121,26 @@ func (c *Client) DeliveryServices() (DeliveryServiceResponse, int, errs.Failure) return resp, status, err } -// DeliveryServiceEdit method +// Delivery service creation/editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-delivery-services-code-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.DeliveryServiceEdit(v5.DeliveryService{ +// Active: false, +// Code: "delivery-1", +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1245,7 +2164,9 @@ func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (Successfu return resp, status, err } -// DeliveryTypes method +// Getting the list of delivery types +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-delivery-types func (c *Client) DeliveryTypes() (DeliveryTypesResponse, int, errs.Failure) { var resp DeliveryTypesResponse @@ -1263,7 +2184,28 @@ func (c *Client) DeliveryTypes() (DeliveryTypesResponse, int, errs.Failure) { return resp, status, err } -// DeliveryTypeEdit method +// Delivery type creation/editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-delivery-types-code-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.DeliveryTypeEdit(v5.DeliveryType{ +// Active: false, +// Code: "type-1", +// DefaultCost: 300, +// DefaultForCrm: false, +// } +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1287,7 +2229,9 @@ func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (SuccessfulResponse return resp, status, err } -// LegalEntities method +// Getting the list of legal entities +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-legal-entities func (c *Client) LegalEntities() (LegalEntitiesResponse, int, errs.Failure) { var resp LegalEntitiesResponse @@ -1305,7 +2249,26 @@ func (c *Client) LegalEntities() (LegalEntitiesResponse, int, errs.Failure) { return resp, status, err } -// LegalEntityEdit method +// Editing of information on legal entity +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-legal-entities-code-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.LegalEntityEdit(v5.LegalEntity{ +// Code: "legal-entity-1", +// CertificateDate: "2012-12-12", +// } +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1329,7 +2292,9 @@ func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (SuccessfulResponse, i return resp, status, err } -// OrderMethods method +// Getting the list of order methods +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-order-methods func (c *Client) OrderMethods() (OrderMethodsResponse, int, errs.Failure) { var resp OrderMethodsResponse @@ -1347,7 +2312,27 @@ func (c *Client) OrderMethods() (OrderMethodsResponse, int, errs.Failure) { return resp, status, err } -// OrderMethodEdit method +// Order method creation/editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-order-methods-code-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrderMethodEdit(v5.OrderMethod{ +// Code: "method-1", +// Active: false, +// DefaultForCRM: false, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1371,7 +2356,9 @@ func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (SuccessfulResponse, i return resp, status, err } -// OrderTypes method +// Getting the list of order types +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-order-types func (c *Client) OrderTypes() (OrderTypesResponse, int, errs.Failure) { var resp OrderTypesResponse @@ -1389,7 +2376,26 @@ func (c *Client) OrderTypes() (OrderTypesResponse, int, errs.Failure) { return resp, status, err } -// OrderTypeEdit method +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-order-methods-code-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrderTypeEdit(v5.OrderType{ +// Code: "order-type-1", +// Active: false, +// DefaultForCRM: false, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) OrderTypeEdit(orderType OrderType) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1413,7 +2419,9 @@ func (c *Client) OrderTypeEdit(orderType OrderType) (SuccessfulResponse, int, er return resp, status, err } -// PaymentStatuses method +// Getting the list of payment statuses +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-payment-statuses func (c *Client) PaymentStatuses() (PaymentStatusesResponse, int, errs.Failure) { var resp PaymentStatusesResponse @@ -1431,7 +2439,9 @@ func (c *Client) PaymentStatuses() (PaymentStatusesResponse, int, errs.Failure) return resp, status, err } -// PaymentStatusEdit method +// Payment status creation/editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-payment-statuses-code-edit func (c *Client) PaymentStatusEdit(paymentStatus PaymentStatus) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1455,7 +2465,9 @@ func (c *Client) PaymentStatusEdit(paymentStatus PaymentStatus) (SuccessfulRespo return resp, status, err } -// PaymentTypes method +// Getting the list of payment types +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-payment-types func (c *Client) PaymentTypes() (PaymentTypesResponse, int, errs.Failure) { var resp PaymentTypesResponse @@ -1473,7 +2485,9 @@ func (c *Client) PaymentTypes() (PaymentTypesResponse, int, errs.Failure) { return resp, status, err } -// PaymentTypeEdit method +// Payment type creation/editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-payment-types-code-edit func (c *Client) PaymentTypeEdit(paymentType PaymentType) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1497,7 +2511,9 @@ func (c *Client) PaymentTypeEdit(paymentType PaymentType) (SuccessfulResponse, i return resp, status, err } -// PriceTypes method +// Getting the list of price types +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-price-types func (c *Client) PriceTypes() (PriceTypesResponse, int, errs.Failure) { var resp PriceTypesResponse @@ -1515,7 +2531,9 @@ func (c *Client) PriceTypes() (PriceTypesResponse, int, errs.Failure) { return resp, status, err } -// PriceTypeEdit method +// Price type creation/editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-price-types-code-edit func (c *Client) PriceTypeEdit(priceType PriceType) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1539,7 +2557,9 @@ func (c *Client) PriceTypeEdit(priceType PriceType) (SuccessfulResponse, int, er return resp, status, err } -// ProductStatuses method +// Getting the list of item statuses in order +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-product-statuses func (c *Client) ProductStatuses() (ProductStatusesResponse, int, errs.Failure) { var resp ProductStatusesResponse @@ -1557,7 +2577,9 @@ func (c *Client) ProductStatuses() (ProductStatusesResponse, int, errs.Failure) return resp, status, err } -// ProductStatusEdit method +// Item status creation/editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-product-statuses-code-edit func (c *Client) ProductStatusEdit(productStatus ProductStatus) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1581,7 +2603,9 @@ func (c *Client) ProductStatusEdit(productStatus ProductStatus) (SuccessfulRespo return resp, status, err } -// Sites method +// Getting the stores list +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-sites func (c *Client) Sites() (SitesResponse, int, errs.Failure) { var resp SitesResponse @@ -1599,7 +2623,9 @@ func (c *Client) Sites() (SitesResponse, int, errs.Failure) { return resp, status, err } -// SiteEdit method +// Store creation/editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-sites-code-edit func (c *Client) SiteEdit(site Site) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1623,7 +2649,9 @@ func (c *Client) SiteEdit(site Site) (SuccessfulResponse, int, errs.Failure) { return resp, status, err } -// StatusGroups method +// Getting the list of order status groups +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-status-groups func (c *Client) StatusGroups() (StatusGroupsResponse, int, errs.Failure) { var resp StatusGroupsResponse @@ -1641,7 +2669,9 @@ func (c *Client) StatusGroups() (StatusGroupsResponse, int, errs.Failure) { return resp, status, err } -// Statuses method +// Getting the list of order statuses +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-statuses func (c *Client) Statuses() (StatusesResponse, int, errs.Failure) { var resp StatusesResponse @@ -1659,7 +2689,9 @@ func (c *Client) Statuses() (StatusesResponse, int, errs.Failure) { return resp, status, err } -// StatusEdit method +// Order status creation/editing +// +// For more information see www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-sites-code-edit func (c *Client) StatusEdit(st Status) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1683,7 +2715,9 @@ func (c *Client) StatusEdit(st Status) (SuccessfulResponse, int, errs.Failure) { return resp, status, err } -// Stores method +// Getting the list of warehouses +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-stores func (c *Client) Stores() (StoresResponse, int, errs.Failure) { var resp StoresResponse @@ -1701,7 +2735,9 @@ func (c *Client) Stores() (StoresResponse, int, errs.Failure) { return resp, status, err } -// StoreEdit method +// Editing of information on warehouse +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-stores-code-edit func (c *Client) StoreEdit(store Store) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1725,7 +2761,31 @@ func (c *Client) StoreEdit(store Store) (SuccessfulResponse, int, errs.Failure) return resp, status, err } -// Segments get segments +// Get segments +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-segments +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Segments(SegmentsRequest{ +// Filter: v5.SegmentsFilter{ +// Ids: []int{1,2,3} +// } +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Segments { +// fmt.Printf("%v\n", value) +// } func (c *Client) Segments(parameters SegmentsRequest) (SegmentsResponse, int, errs.Failure) { var resp SegmentsResponse @@ -1745,7 +2805,27 @@ func (c *Client) Segments(parameters SegmentsRequest) (SegmentsResponse, int, er return resp, status, err } -// Inventories method +// Getting the leftover stocks and purchasing prices +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-store-inventories +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Inventories(v5.InventoriesRequest{Filter: v5.InventoriesFilter{Details: 1, ProductActive: 1}, Page: 1}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Offers { +// fmt.Printf("%v\n", value) +// } func (c *Client) Inventories(parameters InventoriesRequest) (InventoriesResponse, int, errs.Failure) { var resp InventoriesResponse @@ -1765,7 +2845,44 @@ func (c *Client) Inventories(parameters InventoriesRequest) (InventoriesResponse return resp, status, err } -// InventoriesUpload method +// Updating the leftover stocks and purchasing prices +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-store-inventories-upload +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := clientc.InventoriesUpload( +// []v5.InventoryUpload{ +// { +// XMLID: "pTKIKAeghYzX21HTdzFCe1", +// Stores: []InventoryUploadStore{ +// {Code: "test-store-v5", Available: 10, PurchasePrice: 1500}, +// {Code: "test-store-v4", Available: 20, PurchasePrice: 1530}, +// {Code: "test-store", Available: 30, PurchasePrice: 1510}, +// }, +// }, +// { +// XMLID: "JQIvcrCtiSpOV3AAfMiQB3", +// Stores: []InventoryUploadStore{ +// {Code: "test-store-v5", Available: 45, PurchasePrice: 1500}, +// {Code: "test-store-v4", Available: 32, PurchasePrice: 1530}, +// {Code: "test-store", Available: 46, PurchasePrice: 1510}, +// }, +// }, +// }, +// ) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// fmt.Printf("%v\n", data.NotFoundOffers) func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string) (StoreUploadResponse, int, errs.Failure) { var resp StoreUploadResponse @@ -1791,7 +2908,36 @@ func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string return resp, status, err } -// PricesUpload method +// Offers prices updating +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-store-prices-upload +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.PricesUpload([]v5.OfferPriceUpload{ +// { +// ID 1 +// Site "store-1" +// Prices []PriceUpload{{Code: "price-1"}} +// }, +// { +// ID 2 +// Site "store-1" +// Prices []PriceUpload{{Code: "price-2"}} +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// fmt.Printf("%v\n", data.NotFoundOffers) func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, int, errs.Failure) { var resp StoreUploadResponse @@ -1815,7 +2961,31 @@ func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, i return resp, status, err } -// ProductsGroup method +// Getting the list of product groups +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-store-product-groups +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.ProductsGroup(v5.ProductsGroupsRequest{ +// Filter: v5.ProductsGroupsFilter{ +// Active: 1, +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.ProductGroup { +// fmt.Printf("%v\n", value) +// } func (c *Client) ProductsGroup(parameters ProductsGroupsRequest) (ProductsGroupsResponse, int, errs.Failure) { var resp ProductsGroupsResponse @@ -1835,7 +3005,32 @@ func (c *Client) ProductsGroup(parameters ProductsGroupsRequest) (ProductsGroups return resp, status, err } -// Products method +// Getting the list of products and SKU +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-store-products +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Products(v5.ProductsRequest{ +// Filter: v5.ProductsFilter{ +// Active: 1, +// MinPrice: 1000, +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Products { +// fmt.Printf("%v\n", value) +// } func (c *Client) Products(parameters ProductsRequest) (ProductsResponse, int, errs.Failure) { var resp ProductsResponse @@ -1855,7 +3050,31 @@ func (c *Client) Products(parameters ProductsRequest) (ProductsResponse, int, er return resp, status, err } -// ProductsProperties method +// Getting the list of item properties, matching the specified filter +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-store-products-properties +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.ProductsProperties(v5.ProductsPropertiesRequest{ +// Filter: v5.ProductsPropertiesFilter{ +// Sites: []string["store"], +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Properties { +// fmt.Printf("%v\n", value) +// } func (c *Client) ProductsProperties(parameters ProductsPropertiesRequest) (ProductsPropertiesResponse, int, errs.Failure) { var resp ProductsPropertiesResponse @@ -1875,7 +3094,31 @@ func (c *Client) ProductsProperties(parameters ProductsPropertiesRequest) (Produ return resp, status, err } -// Tasks list method +// Getting the task list +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-tasks +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Tasks(v5.TasksRequest{ +// Filter: TasksFilter{ +// DateFrom: "2012-12-12", +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Tasks { +// fmt.Printf("%v\n", value) +// } func (c *Client) Tasks(parameters TasksRequest) (TasksResponse, int, errs.Failure) { var resp TasksResponse @@ -1895,7 +3138,30 @@ func (c *Client) Tasks(parameters TasksRequest) (TasksResponse, int, errs.Failur return resp, status, err } -// TaskCreate method +// Task creation +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-tasks-create +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Tasks(v5.Task{ +// Text: "task №1", +// PerformerID: 12, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.ID) +// } func (c *Client) TaskCreate(task Task, site ...string) (CreateResponse, int, errs.Failure) { var resp CreateResponse taskJSON, _ := json.Marshal(&task) @@ -1920,7 +3186,27 @@ func (c *Client) TaskCreate(task Task, site ...string) (CreateResponse, int, err return resp, status, err } -// Task get method +// Getting information on task +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-tasks-id +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Task(12) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.Task) +// } func (c *Client) Task(id int) (TaskResponse, int, errs.Failure) { var resp TaskResponse @@ -1937,8 +3223,26 @@ func (c *Client) Task(id int) (TaskResponse, int, errs.Failure) { return resp, status, err } - -// TaskEdit method +// Task editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-tasks-id-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Task(v5.Task{ +// ID: 12 +// Text: "task №2", +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) TaskEdit(task Task, site ...string) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse var uid = strconv.Itoa(task.ID) @@ -1965,7 +3269,27 @@ func (c *Client) TaskEdit(task Task, site ...string) (SuccessfulResponse, int, e return resp, status, err } -// UserGroups list method +// Getting the list of user groups +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-user-groups +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.UserGroups(v5.UserGroupsRequest{Page: 1}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Groups { +// fmt.Printf("%v\n", value) +// } func (c *Client) UserGroups(parameters UserGroupsRequest) (UserGroupsResponse, int, errs.Failure) { var resp UserGroupsResponse @@ -1985,7 +3309,27 @@ func (c *Client) UserGroups(parameters UserGroupsRequest) (UserGroupsResponse, i return resp, status, err } -// Users list method +// Getting the list of users matched the specified filter +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-users +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Users(v5.UsersRequest{Filter: v5.UsersFilter{Active: 1}, Page: 1}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Users { +// fmt.Printf("%v\n", value) +// } func (c *Client) Users(parameters UsersRequest) (UsersResponse, int, errs.Failure) { var resp UsersResponse @@ -2005,7 +3349,27 @@ func (c *Client) Users(parameters UsersRequest) (UsersResponse, int, errs.Failur return resp, status, err } -// User get method +// Getting information on user +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-users-id +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.User(12) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.User) +// } func (c *Client) User(id int) (UserResponse, int, errs.Failure) { var resp UserResponse @@ -2023,7 +3387,23 @@ func (c *Client) User(id int) (UserResponse, int, errs.Failure) { return resp, status, err } -// UserStatus update method +// Change user status +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-users +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.UserStatus(12, "busy") +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) UserStatus(id int, status string) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -2045,7 +3425,9 @@ func (c *Client) UserStatus(id int, status string) (SuccessfulResponse, int, err return resp, st, err } -// StaticticsUpdate update statistic +// Statistics updating +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-statistic-update func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -2065,6 +3447,8 @@ func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, errs.Failure) { // Getting of the cost list, adequate for the given filter // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-costs +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") @@ -2076,25 +3460,25 @@ func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, errs.Failure) { // }, // }) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // for _, value := range data.Costs { // fmt.Printf("%v\n", value.Summ) // } -func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, ErrorResponse) { +func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, errs.Failure) { var resp CostsResponse params, _ := query.Values(costs) data, status, err := c.GetRequest(fmt.Sprintf("/costs?%s", params.Encode())) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2105,6 +3489,8 @@ func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, ErrorResponse) { // Creation of the cost // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-create +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") @@ -2123,18 +3509,18 @@ func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, ErrorResponse) { // "store" // ) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("%v", data.ID) // } -func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, int, ErrorResponse) { +func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, int, errs.Failure) { var resp CreateResponse costJSON, _ := json.Marshal(&cost) @@ -2146,7 +3532,7 @@ func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, in fillSite(&p, site) data, status, err := c.PostRequest("/costs/create", p) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2155,7 +3541,9 @@ func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, in return resp, status, err } -// Method allows to remove batch up to 50 costs. +// Cost removing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-delete // // Example: // @@ -2163,18 +3551,18 @@ func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, in // // data, status, err := client.client.CostsDelete([]int{1, 2, 3, 48, 49, 50}) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("Not removed costs: %v", data.NotRemovedIds) // } -func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, ErrorResponse) { +func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, errs.Failure) { var resp CostsDeleteResponse costJSON, _ := json.Marshal(&ids) @@ -2184,7 +3572,7 @@ func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, ErrorResponse } data, status, err := c.PostRequest("/costs/delete", p) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2193,7 +3581,9 @@ func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, ErrorResponse return resp, status, err } -// Method allows to upload as packet up to 50 costs. +// Batch loading of costs +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-upload // // Example: // @@ -2218,18 +3608,18 @@ func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, ErrorResponse // } // }) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("Uploaded costs: %v", data.UploadedCosts) // } -func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, ErrorResponse) { +func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, errs.Failure) { var resp CostsUploadResponse costJSON, _ := json.Marshal(&cost) @@ -2239,7 +3629,7 @@ func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, Error } data, status, err := c.PostRequest("/costs/upload", p) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2250,29 +3640,31 @@ func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, Error // Getting of cost information // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-costs-id +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") // // data, status, err := client.Cost(1) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("%v", data.Cost) // } -func (c *Client) Cost(id int) (CostResponse, int, ErrorResponse) { +func (c *Client) Cost(id int) (CostResponse, int, errs.Failure) { var resp CostResponse data, status, err := c.GetRequest(fmt.Sprintf("/costs/%d", id)) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2283,20 +3675,22 @@ func (c *Client) Cost(id int) (CostResponse, int, ErrorResponse) { // Cost removing // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-id-delete +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") // // data, status, err := client.CostDelete(1) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } -func (c *Client) CostDelete(id int) (SuccessfulResponse, int, ErrorResponse) { +func (c *Client) CostDelete(id int) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse costJSON, _ := json.Marshal(&id) @@ -2307,7 +3701,7 @@ func (c *Client) CostDelete(id int) (SuccessfulResponse, int, ErrorResponse) { data, status, err := c.PostRequest(fmt.Sprintf("/costs/%d/delete", id), p) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2318,6 +3712,8 @@ func (c *Client) CostDelete(id int) (SuccessfulResponse, int, ErrorResponse) { // Cost editing // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-id-edit +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") @@ -2329,18 +3725,18 @@ func (c *Client) CostDelete(id int) (SuccessfulResponse, int, ErrorResponse) { // CostItem: "seo", // }) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("%v", data.Id) // } -func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateResponse, int, ErrorResponse) { +func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateResponse, int, errs.Failure) { var resp CreateResponse costJSON, _ := json.Marshal(&cost) @@ -2352,7 +3748,7 @@ func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateRespon fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/costs/%d/edit", id), p) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2363,6 +3759,8 @@ func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateRespon // Getting the list of custom fields // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-custom-fields +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") @@ -2372,25 +3770,25 @@ func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateRespon // Entity: "customer", // }) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // for _, value := range data.CustomFields { // fmt.Printf("%v\n", value) // } -func (c *Client) CustomFields(customFields CustomFieldsRequest) (CustomFieldsResponse, int, ErrorResponse) { +func (c *Client) CustomFields(customFields CustomFieldsRequest) (CustomFieldsResponse, int, errs.Failure) { var resp CustomFieldsResponse params, _ := query.Values(customFields) data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields?%s", params.Encode())) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2401,6 +3799,8 @@ func (c *Client) CustomFields(customFields CustomFieldsRequest) (CustomFieldsRes // Getting the list of custom directory // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-custom-fields-dictionaries +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") @@ -2411,25 +3811,25 @@ func (c *Client) CustomFields(customFields CustomFieldsRequest) (CustomFieldsRes // }, // }) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // for _, value := range data.CustomDictionaries { // fmt.Printf("%v\n", value.Elements) // } -func (c *Client) CustomDictionaries(customDictionaries CustomDictionariesRequest) (CustomDictionariesResponse, int, ErrorResponse) { +func (c *Client) CustomDictionaries(customDictionaries CustomDictionariesRequest) (CustomDictionariesResponse, int, errs.Failure) { var resp CustomDictionariesResponse params, _ := query.Values(customDictionaries) data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields/dictionaries?%s", params.Encode())) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2440,6 +3840,8 @@ func (c *Client) CustomDictionaries(customDictionaries CustomDictionariesRequest // Directory fields creation // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-custom-fields-dictionaries-create +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") @@ -2459,18 +3861,18 @@ func (c *Client) CustomDictionaries(customDictionaries CustomDictionariesRequest // }, // }) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("%v", data.Code) // } -func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (CustomResponse, int, ErrorResponse) { +func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (CustomResponse, int, errs.Failure) { var resp CustomResponse costJSON, _ := json.Marshal(&customDictionary) @@ -2481,7 +3883,7 @@ func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (Cu data, status, err := c.PostRequest("/custom-fields/dictionaries/create", p) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2492,29 +3894,31 @@ func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (Cu // Getting information on directory // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-custom-fields-entity-code +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") // // data, status, err := client.CustomDictionary("courier-profiles") // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("%v", data.CustomDictionary.Name) // } -func (c *Client) CustomDictionary(code string) (CustomDictionaryResponse, int, ErrorResponse) { +func (c *Client) CustomDictionary(code string) (CustomDictionaryResponse, int, errs.Failure) { var resp CustomDictionaryResponse data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields/dictionaries/%s", code)) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2525,6 +3929,8 @@ func (c *Client) CustomDictionary(code string) (CustomDictionaryResponse, int, E // Directory fields editing // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-custom-fields-dictionaries-code-edit +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") @@ -2544,18 +3950,18 @@ func (c *Client) CustomDictionary(code string) (CustomDictionaryResponse, int, E // }, // }) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("%v", data.Code) // } -func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (CustomResponse, int, ErrorResponse) { +func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (CustomResponse, int, errs.Failure) { var resp CustomResponse costJSON, _ := json.Marshal(&customDictionary) @@ -2565,7 +3971,7 @@ func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (Custom } data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/dictionaries/%s/edit", customDictionary.Code), p) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2576,32 +3982,32 @@ func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (Custom // Custom fields creation // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-custom-fields-entity-create +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") // -// data, status, err := client.CustomFieldsCreate(v5.CustomFieldsEditRequest{ -// CustomField: v5.CustomFields{ -// Name: "First order", -// Code: "first-order", -// Type: "bool", -// Entity: "order", -// DisplayArea: "customer", -// }, +// data, status, err := client.CustomFieldsCreate(CustomFields{ +// Name: "First order", +// Code: "first-order", +// Type: "bool", +// Entity: "order", +// DisplayArea: "customer", // }) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("%v", data.Code) // } -func (c *Client) CustomFieldsCreate(customFields CustomFieldsEditRequest) (CustomResponse, int, ErrorResponse) { +func (c *Client) CustomFieldsCreate(customFields CustomFields) (CustomResponse, int, errs.Failure) { var resp CustomResponse costJSON, _ := json.Marshal(&customFields) @@ -2610,9 +4016,9 @@ func (c *Client) CustomFieldsCreate(customFields CustomFieldsEditRequest) (Custo "customField": {string(costJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/%s/create", customFields.CustomField.Entity), p) + data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/%s/create", customFields.Entity), p) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2623,29 +4029,31 @@ func (c *Client) CustomFieldsCreate(customFields CustomFieldsEditRequest) (Custo // Getting information on custom fields // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-custom-fields-entity-code +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") // // data, status, err := client.CustomField("order", "first-order") // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("%v", data.CustomField) // } -func (c *Client) CustomField(entity, code string) (CustomFieldResponse, int, ErrorResponse) { +func (c *Client) CustomField(entity, code string) (CustomFieldResponse, int, errs.Failure) { var resp CustomFieldResponse data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields/%s/%s", entity, code)) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2656,29 +4064,30 @@ func (c *Client) CustomField(entity, code string) (CustomFieldResponse, int, Err // CustomFieldEdit list method // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-custom-fields-entity-code-edit +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") // -// data, status, err := client.CustomFieldEdit("order", v5.CustomFieldsEditRequest{ -// CustomField: v5.CustomFields{ -// Name: "First customer order", -// Code: "first-order", -// }, -// }) +// data, status, err := client.CustomFieldEdit(CustomFields{ +// Code: "first-order", +// Entity: "order", +// DisplayArea: "delivery", +// }) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("%v", data.Code) // } -func (c *Client) CustomFieldEdit(entity string, customFields CustomFieldsEditRequest) (CustomResponse, int, ErrorResponse) { +func (c *Client) CustomFieldEdit(customFields CustomFields) (CustomResponse, int, errs.Failure) { var resp CustomResponse costJSON, _ := json.Marshal(&customFields) @@ -2687,9 +4096,9 @@ func (c *Client) CustomFieldEdit(entity string, customFields CustomFieldsEditReq "customField": {string(costJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/%s/%s/edit", entity, customFields.CustomField.Code), p) + data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/%s/%s/edit", customFields.Entity, customFields.Code), p) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } diff --git a/v5/client_test.go b/v5/client_test.go index f5fe87e..5548a75 100644 --- a/v5/client_test.go +++ b/v5/client_test.go @@ -16,6 +16,7 @@ var user, _ = strconv.Atoi(os.Getenv("RETAILCRM_USER")) var statuses = map[int]bool{http.StatusOK: true, http.StatusCreated: true} var id int var ids []int +var codeCustomField string func init() { r = rand.New(rand.NewSource(time.Now().UnixNano())) @@ -49,7 +50,6 @@ func TestGetRequest(t *testing.T) { _, status, _ := c.GetRequest("/fake-method") if status != http.StatusNotFound { - t.Fail() } } @@ -58,7 +58,6 @@ func TestPostRequest(t *testing.T) { _, status, _ := c.PostRequest("/fake-method", url.Values{}) if status != http.StatusNotFound { - t.Fail() } } @@ -118,7 +117,6 @@ func TestClient_ApiCredentialsCredentials(t *testing.T) { data, status, err := c.APICredentials() if err.RuntimeErr != nil { - t.Fail() } if status >= http.StatusBadRequest { @@ -1534,7 +1532,7 @@ func TestClient_PackChange(t *testing.T) { Patronymic: "Аристархович", ExternalID: RandomString(8), Email: fmt.Sprintf("%s@example.com", RandomString(8)), - Items: []OrderItem{{Offer: Offer{ID: 1609}, Quantity: 5}}, + Items: []OrderItem{{Offer: Offer{ID: 25472}, Quantity: 5}}, }) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1740,28 +1738,22 @@ func TestClient_IntegrationModuleFail(t *testing.T) { Code: code, }) if err.RuntimeErr == nil { - t.Fail() } if status < http.StatusBadRequest { - t.Fail() } if m.Success != false { - t.Fail() } g, status, err := c.IntegrationModule(RandomString(12)) if err.RuntimeErr == nil { - t.Fail() } if status < http.StatusBadRequest { - t.Fail() } if g.Success != false { - t.Fail() } } @@ -1863,19 +1855,16 @@ func TestClient_CostCreate(t *testing.T) { CostItem: "seo", }) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } id = data.ID @@ -1892,19 +1881,16 @@ func TestClient_Costs(t *testing.T) { Page: 1, }) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } @@ -1913,19 +1899,16 @@ func TestClient_Cost(t *testing.T) { data, status, err := c.Cost(id) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } @@ -1940,19 +1923,16 @@ func TestClient_CostEdit(t *testing.T) { Order: nil, }) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } @@ -1961,19 +1941,16 @@ func TestClient_CostDelete(t *testing.T) { data, status, err := c.CostDelete(id) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } @@ -1996,23 +1973,20 @@ func TestClient_CostsUpload(t *testing.T) { Summ: 125, CostItem: "seo", Order: nil, - Sites: []string{"catalog-test"}, + Sites: []string{"retailcrm-ru"}, }, }) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } ids = data.UploadedCosts @@ -2022,19 +1996,16 @@ func TestClient_CostsDelete(t *testing.T) { c := client() data, status, err := c.CostsDelete(ids) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } @@ -2043,19 +2014,16 @@ func TestClient_CustomFields(t *testing.T) { data, status, err := c.CustomFields(CustomFieldsRequest{}) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } func TestClient_CustomDictionaries(t *testing.T) { @@ -2069,19 +2037,16 @@ func TestClient_CustomDictionaries(t *testing.T) { Page: 1, }) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } @@ -2090,19 +2055,16 @@ func TestClient_CustomDictionary(t *testing.T) { data, status, err := c.CustomDictionary("test2") - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } @@ -2111,7 +2073,7 @@ func TestClient_CustomDictionariesCreate(t *testing.T) { data, status, err := c.CustomDictionariesCreate(CustomDictionary{ Name: "test2", - Code: "test2", + Code: RandomString(8), Elements: []Element{ { Name: "test", @@ -2120,19 +2082,16 @@ func TestClient_CustomDictionariesCreate(t *testing.T) { }, }) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } @@ -2150,93 +2109,80 @@ func TestClient_CustomDictionaryEdit(t *testing.T) { }, }) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } func TestClient_CustomFieldsCreate(t *testing.T) { c := client() + codeCustomField = RandomString(8) - data, status, err := c.CustomFieldsCreate(CustomFieldsEditRequest{ - CustomField: CustomFields{ - Name: "test4", - Code: "test4", - Type: "text", - Entity: "order", - DisplayArea: "customer", - }, + data, status, err := c.CustomFieldsCreate(CustomFields{ + Name: codeCustomField, + Code: codeCustomField, + Type: "text", + Entity: "order", + DisplayArea: "customer", }) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } func TestClient_CustomField(t *testing.T) { c := client() - data, status, err := c.CustomField("customer", "testtest") + data, status, err := c.CustomField("order", codeCustomField) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } func TestClient_CustomFieldEdit(t *testing.T) { c := client() - data, status, err := c.CustomFieldEdit("customer", CustomFieldsEditRequest{ - CustomField: CustomFields{ - Name: "testtesttest", - }, + data, status, err := c.CustomFieldEdit(CustomFields{ + Code: codeCustomField, + Entity: "order", + DisplayArea: "delivery", }) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } diff --git a/v5/request.go b/v5/request.go index 9c024a1..3bf4fb5 100644 --- a/v5/request.go +++ b/v5/request.go @@ -88,7 +88,7 @@ type TasksRequest struct { // NotesRequest type type NotesRequest struct { - Filter TasksFilter `url:"filter,omitempty"` + Filter NotesFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } @@ -164,8 +164,3 @@ type CustomDictionariesRequest struct { Page int `url:"page,omitempty"` } -// CustomFieldsEditRequest type -type CustomFieldsEditRequest struct { - CustomField CustomFields `url:"customField,omitempty"` - Entity string `url:"entity,omitempty"` -} From a0f74fcad8f3d87cb09b840ebb34aed0003d4bdf Mon Sep 17 00:00:00 2001 From: DmitryZagorulko Date: Mon, 16 Apr 2018 17:02:27 +0300 Subject: [PATCH 3/5] fail tests, bug fix --- v5/request.go | 1 - v5/response.go | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/v5/request.go b/v5/request.go index 3bf4fb5..1f580f1 100644 --- a/v5/request.go +++ b/v5/request.go @@ -163,4 +163,3 @@ type CustomDictionariesRequest struct { Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } - diff --git a/v5/response.go b/v5/response.go index d9cf2b2..cc5764d 100644 --- a/v5/response.go +++ b/v5/response.go @@ -338,15 +338,15 @@ type CostsResponse struct { // CostsUploadResponse type type CostsUploadResponse struct { - Success bool `json:"success"` - UploadedCosts []int `json:"uploadedCosts,omitempty,brackets"` + Success bool `json:"success"` + UploadedCosts []int `json:"uploadedCosts,omitempty,brackets"` } // CostsDeleteResponse type type CostsDeleteResponse struct { - Success bool `json:"success"` - Count int `json:"count,omitempty,brackets"` - NotRemovedIds []int `json:"notRemovedIds,omitempty,brackets"` + Success bool `json:"success"` + Count int `json:"count,omitempty,brackets"` + NotRemovedIds []int `json:"notRemovedIds,omitempty,brackets"` } // CostResponse type From b5d420b68e8e9c3c679868a12ab3c40a77f560a8 Mon Sep 17 00:00:00 2001 From: DmitryZagorulko Date: Fri, 20 Apr 2018 17:59:26 +0300 Subject: [PATCH 4/5] add mock in tests --- errs/error.go | 4 +- errs/types.go | 4 +- v5/client_test.go | 3524 ++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 3200 insertions(+), 332 deletions(-) diff --git a/errs/error.go b/errs/error.go index ca3b44e..ff9578c 100644 --- a/errs/error.go +++ b/errs/error.go @@ -19,8 +19,8 @@ func (f *Failure) ApiError() string { func (f *Failure) ApiErrors() []string { var errors []string - for i := 0; i < len(f.ApiErrs); i++ { - errors = append(errors, fmt.Sprintf("%v", f.ApiErrs[i])) + for k, i := range f.ApiErrs { + errors = append(errors, fmt.Sprintf("%v: %v", k, i)) } return errors diff --git a/errs/types.go b/errs/types.go index e390d92..21b4d17 100644 --- a/errs/types.go +++ b/errs/types.go @@ -4,11 +4,11 @@ package errs type Failure struct { RuntimeErr error ApiErr string - ApiErrs []string + ApiErrs map[string]string } // FailureResponse convert json error response into object type FailureResponse struct { ErrorMsg string `json:"errorMsg,omitempty"` - Errors []string `json:"errors,omitempty"` + Errors map[string]string `json:"errors,omitempty"` } diff --git a/v5/client_test.go b/v5/client_test.go index 5548a75..72e087c 100644 --- a/v5/client_test.go +++ b/v5/client_test.go @@ -1,6 +1,7 @@ package v5 import ( + "encoding/json" "fmt" "math/rand" "net/http" @@ -9,14 +10,23 @@ import ( "strconv" "testing" "time" + + "github.com/h2non/gock" ) -var r *rand.Rand // Rand for this package. -var user, _ = strconv.Atoi(os.Getenv("RETAILCRM_USER")) -var statuses = map[int]bool{http.StatusOK: true, http.StatusCreated: true} -var id int -var ids []int -var codeCustomField string +var ( + r *rand.Rand // Rand for this package. + user, _ = strconv.Atoi(os.Getenv("RETAILCRM_USER")) + statuses = map[int]bool{http.StatusOK: true, http.StatusCreated: true} + crmUrl = os.Getenv("RETAILCRM_URL") + badUrl = "https://qwertypoiu.retailcrm.ru" + + errFail = "FailTest: error empty" + statusFail = "FailTest: status < 400" + successFail = "FailTest: Success == true" + codeFail = "test-12345" + iCodeFail = 123123 +) func init() { r = rand.New(rand.NewSource(time.Now().UnixNano())) @@ -34,11 +44,11 @@ func RandomString(strlen int) string { } func client() *Client { - return New(os.Getenv("RETAILCRM_URL"), os.Getenv("RETAILCRM_KEY")) + return New(crmUrl, os.Getenv("RETAILCRM_KEY")) } func badurlclient() *Client { - return New("https://qwertypoiu.retailcrm.ru", os.Getenv("RETAILCRM_KEY")) + return New(badUrl, os.Getenv("RETAILCRM_KEY")) } func badkeyclient() *Client { @@ -50,6 +60,7 @@ func TestGetRequest(t *testing.T) { _, status, _ := c.GetRequest("/fake-method") if status != http.StatusNotFound { + t.Fail() } } @@ -58,6 +69,7 @@ func TestPostRequest(t *testing.T) { _, status, _ := c.PostRequest("/fake-method", url.Values{}) if status != http.StatusNotFound { + t.Fail() } } @@ -81,6 +93,13 @@ func TestClient_ApiVersionsVersions(t *testing.T) { func TestClient_ApiVersionsVersionsBadUrl(t *testing.T) { c := badurlclient() + defer gock.Off() + + gock.New(badUrl). + Get("/api/api-versions"). + Reply(200). + BodyString(`{"success": false, "errorMsg" : "Account does not exist"}`) + data, status, err := c.APIVersions() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -90,33 +109,48 @@ func TestClient_ApiVersionsVersionsBadUrl(t *testing.T) { t.Errorf("%v", err.ApiError()) } - if data.Success != true { + if data.Success != false { t.Logf("%v", err.ApiError()) } } -func TestClient_ApiVersionsVersionsBadKey(t *testing.T) { +func TestClient_ApiCredentialsCredentialsBadKey(t *testing.T) { + defer gock.Off() + + gock.New(crmUrl). + Get("/api/credentials"). + Reply(403). + BodyString(`{"success": false, "errorMsg": "Wrong \"apiKey\" value"}`) + c := badkeyclient() - data, status, err := c.APIVersions() + data, status, err := c.APICredentials() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } - if status >= http.StatusBadRequest { + if status < http.StatusBadRequest { t.Logf("%v", err.ApiError()) } - if data.Success != true { + if data.Success != false { t.Logf("%v", err.ApiError()) } } func TestClient_ApiCredentialsCredentials(t *testing.T) { + defer gock.Off() + + gock.New(crmUrl). + Get("/api/credentials"). + Reply(200). + BodyString(`{"success": true}`) + c := client() data, status, err := c.APICredentials() if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } if status >= http.StatusBadRequest { @@ -129,6 +163,15 @@ func TestClient_ApiCredentialsCredentials(t *testing.T) { } func TestClient_CustomersCustomers(t *testing.T) { + defer gock.Off() + + gock.New(crmUrl). + Get("/api/v5/customers"). + MatchParam("filter[city]", "Москва"). + MatchParam("page", "3"). + Reply(200). + BodyString(`{"success": true}`) + c := client() data, status, err := c.Customers(CustomersRequest{ @@ -143,11 +186,41 @@ func TestClient_CustomersCustomers(t *testing.T) { } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Logf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Logf("%v", err.ApiError()) + } +} + +func TestClient_CustomersCustomers_Fail(t *testing.T) { + defer gock.Off() + + gock.New(crmUrl). + Get("/api/v5/customers"). + MatchParam("filter[ids][]", codeFail). + Reply(400). + BodyString(`{"success": false,"errorMsg": "Internal Server Error"}`) + + c := client() + + data, status, err := c.Customers(CustomersRequest{ + Filter: CustomersFilter{ + Ids: []string{codeFail}, + }, + }) + + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) } } @@ -167,6 +240,21 @@ func TestClient_CustomerChange(t *testing.T) { }, } + defer gock.Off() + + str, _ := json.Marshal(f) + + p := url.Values{ + "customer": {string(str)}, + } + + gock.New(crmUrl). + Post("/api/v5/customers/create"). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true, "id": 123}`) + cr, sc, err := c.CustomerCreate(f) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -183,6 +271,20 @@ func TestClient_CustomerChange(t *testing.T) { f.ID = cr.ID f.Vip = true + str, _ = json.Marshal(f) + + p = url.Values{ + "by": {string("id")}, + "customer": {string(str)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/customers/%v/edit", cr.ID)). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + ed, se, err := c.CustomerEdit(f, "id") if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -196,6 +298,12 @@ func TestClient_CustomerChange(t *testing.T) { t.Errorf("%v", err.ApiError()) } + gock.New(crmUrl). + Get(fmt.Sprintf("/api/v5/customers/%v", f.ExternalID)). + MatchParam("by", "externalId"). + Reply(200). + BodyString(`{"success": true}`) + data, status, err := c.Customer(f.ExternalID, "externalId", "") if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -208,9 +316,90 @@ func TestClient_CustomerChange(t *testing.T) { if data.Success != true { t.Errorf("%v", err.ApiError()) } +} - if data.Customer.ExternalID != f.ExternalID { - t.Errorf("%v", err.ApiError()) +func TestClient_CustomerChange_Fail(t *testing.T) { + c := client() + + f := Customer{ + FirstName: "Понтелей", + } + + defer gock.Off() + + str, _ := json.Marshal(f) + + p := url.Values{ + "customer": {string(str)}, + } + + gock.New(crmUrl). + Post("/api/v5/customers/create"). + MatchType("url"). + BodyString(p.Encode()). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Parameter 'externalId' in 'customer' is missing"}`) + + cr, sc, err := c.CustomerCreate(f) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if sc < http.StatusBadRequest { + t.Error(statusFail) + } + + if cr.Success != false { + t.Error(successFail) + } + + f.ID = cr.ID + f.Vip = true + + str, _ = json.Marshal(f) + + p = url.Values{ + "by": {string("id")}, + "customer": {string(str)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/customers/%v/edit", cr.ID)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "Not found"}`) + + ed, se, err := c.CustomerEdit(f, "id") + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if se < http.StatusBadRequest { + t.Error(statusFail) + } + + if ed.Success != false { + t.Error(successFail) + } + + gock.New(crmUrl). + Get(fmt.Sprintf("/api/v5/customers/%v", codeFail)). + MatchParam("by", "externalId"). + Reply(404). + BodyString(`{"success": false, "errorMsg": "Not found"}`) + + data, status, err := c.Customer(codeFail, "externalId", "") + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) } } @@ -227,6 +416,21 @@ func TestClient_CustomersUpload(t *testing.T) { } } + defer gock.Off() + + str, _ := json.Marshal(customers) + + p := url.Values{ + "customers": {string(str)}, + } + + gock.New(crmUrl). + Post("/api/v5/customers/upload"). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + data, status, err := c.CustomersUpload(customers) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -241,64 +445,63 @@ func TestClient_CustomersUpload(t *testing.T) { } } +func TestClient_CustomersUpload_Fail(t *testing.T) { + c := client() + + customers := []Customer{{ExternalID: strconv.Itoa(iCodeFail)}} + + defer gock.Off() + + str, _ := json.Marshal(customers) + p := url.Values{ + "customers": {string(str)}, + } + + gock.New(crmUrl). + Post("/api/v5/customers/upload"). + MatchType("url"). + BodyString(p.Encode()). + Reply(460). + BodyString(`{"success": false, "errorMsg": "Customers are loaded with errors"}`) + + data, status, err := c.CustomersUpload(customers) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_CustomersCombine(t *testing.T) { c := client() - dataFirst, status, err := c.CustomerCreate(Customer{ - FirstName: fmt.Sprintf("Name_%s", RandomString(8)), - LastName: fmt.Sprintf("Test_%s", RandomString(8)), - ExternalID: RandomString(8), - Email: fmt.Sprintf("%s@example.com", RandomString(8)), - }) - if err.RuntimeErr != nil { - t.Errorf("%v", err.Error()) + defer gock.Off() + + customers := []Customer{{ID: 1}, {ID: 2}} + resultCustomer := Customer{ID: 3} + + jr, _ := json.Marshal(&customers) + combineJSONOut, _ := json.Marshal(&resultCustomer) + + p := url.Values{ + "customers": {string(jr[:])}, + "resultCustomer": {string(combineJSONOut[:])}, } - if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) - } + gock.New(crmUrl). + Post("/customers/combine"). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) - if dataFirst.Success != true { - t.Errorf("%v", err.ApiError()) - } - - dataSecond, status, err := c.CustomerCreate(Customer{ - FirstName: fmt.Sprintf("Name_%s", RandomString(8)), - LastName: fmt.Sprintf("Test_%s", RandomString(8)), - ExternalID: RandomString(8), - Email: fmt.Sprintf("%s@example.com", RandomString(8)), - }) - if err.RuntimeErr != nil { - t.Errorf("%v", err.Error()) - } - - if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) - } - - if dataSecond.Success != true { - t.Errorf("%v", err.ApiError()) - } - - dataThird, status, err := c.CustomerCreate(Customer{ - FirstName: fmt.Sprintf("Name_%s", RandomString(8)), - LastName: fmt.Sprintf("Test_%s", RandomString(8)), - ExternalID: RandomString(8), - Email: fmt.Sprintf("%s@example.com", RandomString(8)), - }) - if err.RuntimeErr != nil { - t.Errorf("%v", err.Error()) - } - - if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) - } - - if dataThird.Success != true { - t.Errorf("%v", err.ApiError()) - } - - data, status, err := c.CustomersCombine([]Customer{{ID: dataFirst.ID}, {ID: dataSecond.ID}}, Customer{ID: dataThird.ID}) + data, status, err := c.CustomersCombine(customers, resultCustomer) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } @@ -312,33 +515,66 @@ func TestClient_CustomersCombine(t *testing.T) { } } -func TestClient_CustomersFixExternalIds(t *testing.T) { +func TestClient_CustomersCombine_Fail(t *testing.T) { c := client() - f := Customer{ - FirstName: fmt.Sprintf("Name_%s", RandomString(8)), - LastName: fmt.Sprintf("Test_%s", RandomString(8)), - ExternalID: RandomString(8), - Email: fmt.Sprintf("%s@example.com", RandomString(8)), + + defer gock.Off() + + customers := []Customer{{}, {}} + resultCustomer := Customer{} + + jr, _ := json.Marshal(&customers) + combineJSONOut, _ := json.Marshal(&resultCustomer) + + p := url.Values{ + "customers": {string(jr[:])}, + "resultCustomer": {string(combineJSONOut[:])}, } - cr, sc, err := c.CustomerCreate(f) + gock.New(crmUrl). + Post("/customers/combine"). + MatchType("url"). + BodyString(p.Encode()). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Invalid input parameters"}`) + + data, status, err := c.CustomersCombine([]Customer{{}, {}}, Customer{}) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } - if sc != http.StatusCreated { - t.Errorf("%v", err.ApiError()) + if status < http.StatusBadRequest { + t.Error(statusFail) } - if cr.Success != true { - t.Errorf("%v", err.ApiError()) + if data.Success != false { + t.Error(successFail) } +} + +func TestClient_CustomersFixExternalIds(t *testing.T) { + c := client() customers := []IdentifiersPair{{ - ID: cr.ID, + ID: 123, ExternalID: RandomString(8), }} + defer gock.Off() + + jr, _ := json.Marshal(&customers) + + p := url.Values{ + "customers": {string(jr[:])}, + } + + gock.New(crmUrl). + Post("/customers/fix-external-ids"). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + fx, fe, err := c.CustomersFixExternalIds(customers) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -353,6 +589,40 @@ func TestClient_CustomersFixExternalIds(t *testing.T) { } } +func TestClient_CustomersFixExternalIds_Fail(t *testing.T) { + c := client() + + customers := []IdentifiersPair{{ExternalID: RandomString(8)}} + + defer gock.Off() + + jr, _ := json.Marshal(&customers) + + p := url.Values{ + "customers": {string(jr[:])}, + } + + gock.New(crmUrl). + Post("/customers/fix-external-ids"). + MatchType("url"). + BodyString(p.Encode()). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters", "errors": {"id": "ID must be an integer"}}`) + + data, status, err := c.CustomersFixExternalIds(customers) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_CustomersHistory(t *testing.T) { c := client() f := CustomersHistoryRequest{ @@ -360,6 +630,13 @@ func TestClient_CustomersHistory(t *testing.T) { SinceID: 20, }, } + defer gock.Off() + + gock.New(crmUrl). + Get("/customers/history"). + MatchParam("filter[sinceId]", "20"). + Reply(200). + BodyString(`{"success": true, "history": [{"id": 1}]}`) data, status, err := c.CustomersHistory(f) if err.RuntimeErr != nil { @@ -379,9 +656,47 @@ func TestClient_CustomersHistory(t *testing.T) { } } +func TestClient_CustomersHistory_Fail(t *testing.T) { + c := client() + f := CustomersHistoryRequest{ + Filter: CustomersHistoryFilter{ + StartDate: "2020-13-12", + }, + } + + defer gock.Off() + + gock.New(crmUrl). + Get("/customers/history"). + MatchParam("filter[startDate]", "2020-13-12"). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters", "errors": {"children[startDate]": "Значение недопустимо."}}`) + + data, status, err := c.CustomersHistory(f) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_NotesNotes(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/customers/notes"). + MatchParam("page", "1"). + Reply(200). + BodyString(`{"success": true, "notes": [{"id": 1}]}`) + data, status, err := c.CustomerNotes(NotesRequest{Page: 1}) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -394,37 +709,66 @@ func TestClient_NotesNotes(t *testing.T) { if data.Success != true { t.Errorf("%v", err.ApiError()) } + + if len(data.Notes) == 0 { + t.Errorf("%v", err.ApiError()) + } } -func TestClient_NotesCreateDelete(t *testing.T) { +func TestClient_NotesNotes_Fail(t *testing.T) { c := client() - createCustomerResponse, createCustomerStatus, err := c.CustomerCreate(Customer{ - FirstName: "Понтелей", - LastName: "Турбин", - Patronymic: "Аристархович", - ExternalID: RandomString(8), - Email: fmt.Sprintf("%s@example.com", RandomString(8)), + defer gock.Off() + + gock.New(crmUrl). + Get("/customers/notes"). + MatchParam("filter[createdAtFrom]", "2020-13-12"). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters", "errors": {"children[createdAtFrom]": "This value is not valid."}}`) + + data, status, err := c.CustomerNotes(NotesRequest{ + Filter: NotesFilter{CreatedAtFrom: "2020-13-12"}, }) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } - if createCustomerStatus != http.StatusCreated { - t.Errorf("%v", err.ApiError()) + if status < http.StatusBadRequest { + t.Error(statusFail) } - if createCustomerResponse.Success != true { - t.Errorf("%v", err.ApiError()) + if data.Success != false { + t.Error(successFail) } +} - noteCreateResponse, noteCreateStatus, err := c.CustomerNoteCreate(Note{ +func TestClient_NotesCreateDelete(t *testing.T) { + c := client() + + note := Note{ Text: "some text", ManagerID: user, Customer: &Customer{ - ID: createCustomerResponse.ID, + ID: 123, }, - }) + } + + defer gock.Off() + + jr, _ := json.Marshal(¬e) + + p := url.Values{ + "note": {string(jr[:])}, + } + + gock.New(crmUrl). + Post("/customers/notes/create"). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true, "id": 1}`) + + noteCreateResponse, noteCreateStatus, err := c.CustomerNoteCreate(note) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } @@ -437,6 +781,17 @@ func TestClient_NotesCreateDelete(t *testing.T) { t.Errorf("%v", err.ApiError()) } + p = url.Values{ + "id": {string(1)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/api/v5/customers/notes/%d/delete", 1)). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + noteDeleteResponse, noteDeleteStatus, err := c.CustomerNoteDelete(noteCreateResponse.ID) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -447,13 +802,84 @@ func TestClient_NotesCreateDelete(t *testing.T) { } if noteDeleteResponse.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_NotesCreateDelete_Fail(t *testing.T) { + c := client() + defer gock.Off() + + note := Note{ + Text: "some text", + ManagerID: user, + Customer: &Customer{}, + } + + jr, _ := json.Marshal(¬e) + + p := url.Values{ + "note": {string(jr[:])}, + } + + gock.New(crmUrl). + Post("/customers/notes/create"). + MatchType("url"). + BodyString(p.Encode()). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the entity format", "errors": {"customer": "Set one of the following fields: id, externalId"}}`) + + data, status, err := c.CustomerNoteCreate(note) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } + + p = url.Values{ + "id": {string(iCodeFail)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/customers/notes/%d/delete", iCodeFail)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "Note not found map"}`) + + noteDeleteResponse, noteDeleteStatus, err := c.CustomerNoteDelete(iCodeFail) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if noteDeleteStatus < http.StatusBadRequest { + t.Error(statusFail) + } + + if noteDeleteResponse.Success != false { + t.Error(successFail) + } +} + func TestClient_OrdersOrders(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/orders"). + MatchParam("filter[city]", "Москва"). + MatchParam("page", "1"). + Reply(200). + BodyString(`{"success": true, "orders": [{"id": 1}]}`) + data, status, err := c.Orders(OrdersRequest{Filter: OrdersFilter{City: "Москва"}, Page: 1}) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -464,10 +890,36 @@ func TestClient_OrdersOrders(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_OrdersOrders_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + gock.New(crmUrl). + Get("/orders"). + MatchParam("filter[attachments]", "7"). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameterst", "errors": {"children[attachments]": "SThis value is not valid."}}`) + + data, status, err := c.Orders(OrdersRequest{Filter: OrdersFilter{Attachments: 7}}) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_OrderChange(t *testing.T) { c := client() @@ -481,6 +933,21 @@ func TestClient_OrderChange(t *testing.T) { Email: fmt.Sprintf("%s@example.com", random), } + defer gock.Off() + + jr, _ := json.Marshal(&f) + + p := url.Values{ + "order": {string(jr[:])}, + } + + gock.New(crmUrl). + Post("/orders/create"). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true, "id": 1}`) + cr, sc, err := c.OrderCreate(f) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -497,6 +964,20 @@ func TestClient_OrderChange(t *testing.T) { f.ID = cr.ID f.CustomerComment = "test comment" + jr, _ = json.Marshal(&f) + + p = url.Values{ + "by": {string("id")}, + "order": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/orders/%d/edit", f.ID)). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + ed, se, err := c.OrderEdit(f, "id") if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -510,6 +991,12 @@ func TestClient_OrderChange(t *testing.T) { t.Errorf("%v", err.ApiError()) } + gock.New(crmUrl). + Get(fmt.Sprintf("/orders/%s", f.ExternalID)). + MatchParam("by", "externalId"). + Reply(200). + BodyString(`{"success": true}`) + data, status, err := c.Order(f.ExternalID, "externalId", "") if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -522,9 +1009,49 @@ func TestClient_OrderChange(t *testing.T) { if data.Success != true { t.Errorf("%v", err.ApiError()) } +} - if data.Order.ExternalID != f.ExternalID { - t.Errorf("%v", err.ApiError()) +func TestClient_OrderChange_Fail(t *testing.T) { + c := client() + + random := RandomString(8) + + f := Order{ + FirstName: "Понтелей", + LastName: "Турбин", + Patronymic: "Аристархович", + ExternalID: random, + Email: fmt.Sprintf("%s@example.com", random), + CustomerComment: "test comment", + } + + defer gock.Off() + + jr, _ := json.Marshal(&f) + + p := url.Values{ + "by": {string("id")}, + "order": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/orders/%d/edit", f.ID)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "Not found map"}`) + + data, status, err := c.OrderEdit(f, "id") + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) } } @@ -541,6 +1068,21 @@ func TestClient_OrdersUpload(t *testing.T) { } } + defer gock.Off() + + jr, _ := json.Marshal(&orders) + + p := url.Values{ + "orders": {string(jr[:])}, + } + + gock.New(crmUrl). + Post("/orders/upload"). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + data, status, err := c.OrdersUpload(orders) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -551,50 +1093,73 @@ func TestClient_OrdersUpload(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_OrdersUpload_Fail(t *testing.T) { + c := client() + + orders := []Order{ + { + FirstName: fmt.Sprintf("Name_%s", RandomString(8)), + LastName: fmt.Sprintf("Test_%s", RandomString(8)), + ExternalID: strconv.Itoa(iCodeFail), + Email: fmt.Sprintf("%s@example.com", RandomString(8)), + }, + } + + defer gock.Off() + + jr, _ := json.Marshal(&orders) + + p := url.Values{ + "orders": {string(jr[:])}, + } + + gock.New(crmUrl). + Post("/orders/upload"). + MatchType("url"). + BodyString(p.Encode()). + Reply(460). + BodyString(`{"success": false, "errorMsg": "Orders are loaded with errors"}`) + + data, status, err := c.OrdersUpload(orders) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_OrdersCombine(t *testing.T) { c := client() - dataFirst, status, err := c.OrderCreate(Order{ - FirstName: fmt.Sprintf("Name_%s", RandomString(8)), - LastName: fmt.Sprintf("Test_%s", RandomString(8)), - ExternalID: RandomString(8), - Email: fmt.Sprintf("%s@example.com", RandomString(8)), - }) - if err.RuntimeErr != nil { - t.Errorf("%v", err.Error()) + defer gock.Off() + + jr1, _ := json.Marshal(&Order{ID: 1}) + jr2, _ := json.Marshal(&Order{ID: 2}) + p := url.Values{ + "technique": {"ours"}, + "order": {string(jr1)}, + "resultOrder": {string(jr2)}, } - if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) - } + gock.New(crmUrl). + Post("/orders/combine"). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) - if dataFirst.Success != true { - t.Errorf("%v", err.ApiError()) - } - - dataSecond, status, err := c.OrderCreate(Order{ - FirstName: fmt.Sprintf("Name_%s", RandomString(8)), - LastName: fmt.Sprintf("Test_%s", RandomString(8)), - ExternalID: RandomString(8), - Email: fmt.Sprintf("%s@example.com", RandomString(8)), - }) - if err.RuntimeErr != nil { - t.Errorf("%v", err.Error()) - } - - if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) - } - - if dataSecond.Success != true { - t.Errorf("%v", err.ApiError()) - } - - data, status, err := c.OrdersCombine("ours", Order{ID: dataFirst.ID}, Order{ID: dataSecond.ID}) + data, status, err := c.OrdersCombine("ours", Order{ID: 1}, Order{ID: 2}) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } @@ -604,37 +1169,66 @@ func TestClient_OrdersCombine(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_OrdersCombine_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + jr, _ := json.Marshal(&Order{}) + p := url.Values{ + "technique": {"ours"}, + "order": {string(jr)}, + "resultOrder": {string(jr)}, + } + + gock.New(crmUrl). + Post("/orders/combine"). + MatchType("url"). + BodyString(p.Encode()). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Invalid input parameters"}`) + + data, status, err := c.OrdersCombine("ours", Order{}, Order{}) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_OrdersFixExternalIds(t *testing.T) { c := client() - f := Order{ - FirstName: fmt.Sprintf("Name_%s", RandomString(8)), - LastName: fmt.Sprintf("Test_%s", RandomString(8)), - ExternalID: RandomString(8), - Email: fmt.Sprintf("%s@example.com", RandomString(8)), - } - - cr, sc, err := c.OrderCreate(f) - if err.RuntimeErr != nil { - t.Errorf("%v", err.Error()) - } - - if sc != http.StatusCreated { - t.Errorf("%v", err.ApiError()) - } - - if cr.Success != true { - t.Errorf("%v", err.ApiError()) - } orders := []IdentifiersPair{{ - ID: cr.ID, + ID: 123, ExternalID: RandomString(8), }} + defer gock.Off() + + jr, _ := json.Marshal(orders) + p := url.Values{ + "orders": {string(jr)}, + } + + gock.New(crmUrl). + Post("/orders/fix-external-ids"). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + fx, fe, err := c.OrdersFixExternalIds(orders) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -645,13 +1239,54 @@ func TestClient_OrdersFixExternalIds(t *testing.T) { } if fx.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_OrdersFixExternalIds_Fail(t *testing.T) { + c := client() + orders := []IdentifiersPair{{ExternalID: RandomString(8)}} + + defer gock.Off() + + jr, _ := json.Marshal(orders) + p := url.Values{ + "orders": {string(jr)}, + } + + gock.New(crmUrl). + Post("/orders/fix-external-ids"). + MatchType("url"). + BodyString(p.Encode()). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Invalid input parameters"}`) + + data, status, err := c.OrdersFixExternalIds(orders) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_OrdersHistory(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/orders/history"). + MatchParam("filter[sinceId]", "20"). + Reply(200). + BodyString(`{"success": true, "history": [{"id": 1}]}`) + data, status, err := c.OrdersHistory(OrdersHistoryRequest{Filter: OrdersHistoryFilter{SinceID: 20}}) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -666,42 +1301,61 @@ func TestClient_OrdersHistory(t *testing.T) { } if len(data.History) == 0 { + t.Errorf("%v", err.ApiError()) } } +func TestClient_OrdersHistory_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + gock.New(crmUrl). + Get("/orders/history"). + MatchParam("filter[startDate]", "2020-13-12"). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters", "errors": {"children[startDate]": "Значение недопустимо."}}`) + + data, status, err := c.OrdersHistory(OrdersHistoryRequest{Filter: OrdersHistoryFilter{StartDate: "2020-13-12"}}) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_PaymentCreateEditDelete(t *testing.T) { c := client() - order := Order{ - FirstName: "Понтелей", - LastName: "Турбин", - Patronymic: "Аристархович", - ExternalID: RandomString(8), - Email: fmt.Sprintf("%s@example.com", RandomString(8)), - } - - createOrderResponse, status, err := c.OrderCreate(order) - if err.RuntimeErr != nil { - t.Errorf("%v", err.Error()) - } - - if status != http.StatusCreated { - t.Errorf("%v", err.ApiError()) - } - - if createOrderResponse.Success != true { - t.Errorf("%v", err.ApiError()) - } - f := Payment{ Order: &Order{ - ID: createOrderResponse.ID, + ID: 123, }, Amount: 300, Type: "cash", } + defer gock.Off() + + jr, _ := json.Marshal(f) + p := url.Values{ + "payment": {string(jr)}, + } + + gock.New(crmUrl). + Post("/orders/payments/create"). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true, "id": 1}`) + paymentCreateResponse, status, err := c.OrderPaymentCreate(f) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -720,6 +1374,18 @@ func TestClient_PaymentCreateEditDelete(t *testing.T) { Amount: 500, } + jr, _ = json.Marshal(k) + p = url.Values{ + "payment": {string(jr)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/orders/payments/%d/edit", paymentCreateResponse.ID)). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + paymentEditResponse, status, err := c.OrderPaymentEdit(k, "id") if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -733,6 +1399,17 @@ func TestClient_PaymentCreateEditDelete(t *testing.T) { t.Errorf("%v", err.ApiError()) } + p = url.Values{ + "id": {string(paymentCreateResponse.ID)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/orders/payments/%d/delete", paymentCreateResponse.ID)). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + paymentDeleteResponse, status, err := c.OrderPaymentDelete(paymentCreateResponse.ID) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -747,15 +1424,114 @@ func TestClient_PaymentCreateEditDelete(t *testing.T) { } } +func TestClient_PaymentCreateEditDelete_Fail(t *testing.T) { + c := client() + + f := Payment{ + Order: &Order{}, + Amount: 300, + Type: "cash", + } + + defer gock.Off() + + jr, _ := json.Marshal(f) + p := url.Values{ + "payment": {string(jr)}, + } + + gock.New(crmUrl). + Post("/orders/payments/create"). + MatchType("url"). + BodyString(p.Encode()). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the entity format", "errors": {"order": "Set one of the following fields: id, externalId, number"}}`) + + data, status, err := c.OrderPaymentCreate(f) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } + + k := Payment{ + ID: iCodeFail, + Amount: 500, + } + + jr, _ = json.Marshal(k) + p = url.Values{ + "payment": {string(jr)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/orders/payments/%d/edit", iCodeFail)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "Payment not found"}`) + + paymentEditResponse, status, err := c.OrderPaymentEdit(k, "id") + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if paymentEditResponse.Success != false { + t.Error(successFail) + } + + p = url.Values{ + "id": {string(iCodeFail)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/orders/payments/%d/delete", iCodeFail)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "Payment not found"}`) + + paymentDeleteResponse, status, err := c.OrderPaymentDelete(iCodeFail) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if paymentDeleteResponse.Success != false { + t.Error(successFail) + } +} + func TestClient_TasksTasks(t *testing.T) { c := client() f := TasksRequest{ Filter: TasksFilter{ - Creators: []int{user}, + Creators: []int{123}, }, Page: 1, } + defer gock.Off() + + gock.New(crmUrl). + Get("/api/v5/tasks"). + MatchParam("filter[creators][]", "123"). + MatchParam("page", "1"). + Reply(200). + BodyString(`{"success": true}`) data, status, err := c.Tasks(f) if err.RuntimeErr != nil { @@ -771,6 +1547,36 @@ func TestClient_TasksTasks(t *testing.T) { } } +func TestClient_TasksTasks_Fail(t *testing.T) { + c := client() + + f := TasksRequest{ + Filter: TasksFilter{ + Creators: []int{123123}, + }, + } + defer gock.Off() + + gock.New(crmUrl). + Get("/api/v5/tasks"). + MatchParam("filter[creators][]", "123123"). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) + + data, status, err := c.Tasks(f) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_TaskChange(t *testing.T) { c := client() @@ -778,6 +1584,19 @@ func TestClient_TaskChange(t *testing.T) { Text: RandomString(15), PerformerID: user, } + defer gock.Off() + + jr, _ := json.Marshal(f) + p := url.Values{ + "task": {string(jr)}, + } + + gock.New(crmUrl). + Post("/tasks/create"). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true, "id": 1}`) cr, sc, err := c.TaskCreate(f) if err.RuntimeErr != nil { @@ -795,6 +1614,11 @@ func TestClient_TaskChange(t *testing.T) { f.ID = cr.ID f.Commentary = RandomString(20) + gock.New(crmUrl). + Get(fmt.Sprintf("/tasks/%d", f.ID)). + Reply(200). + BodyString(`{"success": true}`) + gt, sg, err := c.Task(f.ID) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -808,6 +1632,18 @@ func TestClient_TaskChange(t *testing.T) { t.Errorf("%v", err.ApiError()) } + jr, _ = json.Marshal(f) + p = url.Values{ + "task": {string(jr)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/tasks/%d/edit", f.ID)). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + data, status, err := c.TaskEdit(f) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -818,13 +1654,59 @@ func TestClient_TaskChange(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_TaskChange_Fail(t *testing.T) { + c := client() + + f := Task{ + Text: RandomString(15), + Commentary: RandomString(20), + } + + defer gock.Off() + + jr, _ := json.Marshal(f) + p := url.Values{ + "task": {string(jr)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/tasks/%d/edit", f.ID)). + MatchType("url"). + BodyString(p.Encode()). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Task is not loade", "errors": {"performerId": "This value should not be blank."}}`) + + data, status, err := c.TaskEdit(f) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_UsersUsers(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/users"). + MatchParam("filter[active]", "1"). + MatchParam("page", "1"). + Reply(200). + BodyString(`{"success": true}`) + data, status, err := c.Users(UsersRequest{Filter: UsersFilter{Active: 1}, Page: 1}) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -835,13 +1717,47 @@ func TestClient_UsersUsers(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_UsersUsers_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + gock.New(crmUrl). + Get("/users"). + MatchParam("filter[active]", "3"). + MatchParam("page", "1"). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters", "errors": {"active": "he value you selected is not a valid choice."}}`) + + data, status, err := c.Users(UsersRequest{Filter: UsersFilter{Active: 3}, Page: 1}) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_UsersUser(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get(fmt.Sprintf("/users/%d", user)). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.User(user) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -852,13 +1768,46 @@ func TestClient_UsersUser(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_UsersUser_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + gock.New(crmUrl). + Get(fmt.Sprintf("/users/%d", iCodeFail)). + Reply(404). + BodyString(`{"success": false, "errorMsg": "Not found"}`) + + data, status, err := c.User(iCodeFail) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_UsersGroups(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/user-groups"). + MatchParam("page", "1"). + Reply(200). + BodyString(`{"success": true}`) + data, status, err := c.UserGroups(UserGroupsRequest{Page: 1}) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -876,6 +1825,19 @@ func TestClient_UsersGroups(t *testing.T) { func TestClient_UsersUpdate(t *testing.T) { c := client() + defer gock.Off() + + p := url.Values{ + "status": {string("busy")}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/users/%d/status", user)). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.UserStatus(user, "busy") if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -886,13 +1848,51 @@ func TestClient_UsersUpdate(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_UsersUpdate_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + p := url.Values{ + "status": {string("busy")}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/users/%d/status", iCodeFail)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "Not found"}`) + + data, status, err := c.UserStatus(iCodeFail, "busy") + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_StaticticsUpdate(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/statistic/update"). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.StaticticsUpdate() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -910,6 +1910,13 @@ func TestClient_StaticticsUpdate(t *testing.T) { func TestClient_Countries(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/reference/couriers"). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.Couriers() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -927,6 +1934,13 @@ func TestClient_Countries(t *testing.T) { func TestClient_CostGroups(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/reference/cost-groups"). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.CostGroups() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -944,6 +1958,13 @@ func TestClient_CostGroups(t *testing.T) { func TestClient_CostItems(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/reference/cost-items"). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.CostItems() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -961,6 +1982,13 @@ func TestClient_CostItems(t *testing.T) { func TestClient_Couriers(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/reference/couriers"). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.Couriers() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -978,6 +2006,13 @@ func TestClient_Couriers(t *testing.T) { func TestClient_DeliveryService(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/reference/delivery-services"). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.DeliveryServices() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -995,6 +2030,13 @@ func TestClient_DeliveryService(t *testing.T) { func TestClient_DeliveryTypes(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/reference/delivery-types"). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.DeliveryTypes() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1012,6 +2054,13 @@ func TestClient_DeliveryTypes(t *testing.T) { func TestClient_LegalEntities(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/reference/legal-entities"). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.LegalEntities() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1029,6 +2078,13 @@ func TestClient_LegalEntities(t *testing.T) { func TestClient_OrderMethods(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/reference/order-methods"). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.OrderMethods() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1046,6 +2102,13 @@ func TestClient_OrderMethods(t *testing.T) { func TestClient_OrderTypes(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/reference/order-types"). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.OrderTypes() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1063,6 +2126,13 @@ func TestClient_OrderTypes(t *testing.T) { func TestClient_PaymentStatuses(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/reference/payment-statuses"). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.PaymentStatuses() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1080,6 +2150,13 @@ func TestClient_PaymentStatuses(t *testing.T) { func TestClient_PaymentTypes(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/reference/payment-types"). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.PaymentTypes() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1097,6 +2174,13 @@ func TestClient_PaymentTypes(t *testing.T) { func TestClient_PriceTypes(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/reference/price-types"). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.PriceTypes() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1114,6 +2198,13 @@ func TestClient_PriceTypes(t *testing.T) { func TestClient_ProductStatuses(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/reference/product-statuses"). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.ProductStatuses() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1131,6 +2222,13 @@ func TestClient_ProductStatuses(t *testing.T) { func TestClient_Statuses(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/reference/statuses"). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.Statuses() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1148,6 +2246,13 @@ func TestClient_Statuses(t *testing.T) { func TestClient_StatusGroups(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/reference/status-groups"). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.StatusGroups() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1165,6 +2270,13 @@ func TestClient_StatusGroups(t *testing.T) { func TestClient_Sites(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/reference/sites"). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.Sites() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1182,6 +2294,13 @@ func TestClient_Sites(t *testing.T) { func TestClient_Stores(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/reference/stores"). + Reply(200). + BodyString(`{"success": true}`) + data, st, err := c.Stores() if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1201,12 +2320,29 @@ func TestClient_CostGroupItemEdit(t *testing.T) { uid := RandomString(4) - data, st, err := c.CostGroupEdit(CostGroup{ + costGroup := CostGroup{ Code: fmt.Sprintf("cost-gr-%s", uid), Active: false, Color: "#da5c98", Name: fmt.Sprintf("CostGroup-%s", uid), - }) + } + + defer gock.Off() + + jr, _ := json.Marshal(&costGroup) + + p := url.Values{ + "costGroup": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/api/v5/reference/cost-groups/%s/edit", costGroup.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + + data, st, err := c.CostGroupEdit(costGroup) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } @@ -1219,14 +2355,29 @@ func TestClient_CostGroupItemEdit(t *testing.T) { t.Errorf("%v", err.ApiError()) } - idata, st, err := c.CostItemEdit(CostItem{ + costItem := CostItem{ Code: fmt.Sprintf("cost-it-%s", uid), Name: fmt.Sprintf("CostItem-%s", uid), Group: fmt.Sprintf("cost-gr-%s", uid), Type: "const", AppliesToOrders: true, Active: false, - }) + } + + jr, _ = json.Marshal(&costItem) + + p = url.Values{ + "costItem": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/api/v5/reference/cost-items/%s/edit", costItem.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + + idata, st, err := c.CostItemEdit(costItem) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } @@ -1236,10 +2387,85 @@ func TestClient_CostGroupItemEdit(t *testing.T) { } if idata.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_CostGroupItemEdit_Fail(t *testing.T) { + c := client() + + uid := RandomString(4) + costGroup := CostGroup{ + Code: fmt.Sprintf("cost-gr-%s", uid), + Active: false, + Name: fmt.Sprintf("CostGroup-%s", uid), + } + + defer gock.Off() + + jr, _ := json.Marshal(&costGroup) + + p := url.Values{ + "costGroup": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/cost-groups/%s/edit", costGroup.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) + + data, status, err := c.CostGroupEdit(costGroup) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } + + costItem := CostItem{ + Code: fmt.Sprintf("666cost-it-%s", uid), + Name: fmt.Sprintf("CostItem-%s", uid), + Group: fmt.Sprintf("cost-gr-%s", uid), + Type: "const", + AppliesToOrders: true, + Active: false, + } + + jr, _ = json.Marshal(&costItem) + + p = url.Values{ + "costItem": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/cost-items/%s/edit", costItem.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) + + idata, st, err := c.CostItemEdit(costItem) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if st < http.StatusBadRequest { + t.Error(statusFail) + } + + if idata.Success != false { + t.Error(successFail) + } +} + func TestClient_Courier(t *testing.T) { c := client() @@ -1250,6 +2476,21 @@ func TestClient_Courier(t *testing.T) { LastName: fmt.Sprintf("%s", RandomString(5)), } + defer gock.Off() + + jr, _ := json.Marshal(&cur) + + p := url.Values{ + "courier": {string(jr[:])}, + } + + gock.New(crmUrl). + Post("/api/v5/reference/couriers/create"). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true, "id": 1}`) + data, st, err := c.CourierCreate(cur) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1266,6 +2507,19 @@ func TestClient_Courier(t *testing.T) { cur.ID = data.ID cur.Patronymic = fmt.Sprintf("%s", RandomString(5)) + jr, _ = json.Marshal(&cur) + + p = url.Values{ + "courier": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/couriers/%d/edit", cur.ID)). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + idata, st, err := c.CourierEdit(cur) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1276,18 +2530,95 @@ func TestClient_Courier(t *testing.T) { } if idata.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_Courier_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + jr, _ := json.Marshal(&Courier{}) + + p := url.Values{ + "courier": {string(jr[:])}, + } + + gock.New(crmUrl). + Post("/api/v5/reference/couriers/create"). + MatchType("url"). + BodyString(p.Encode()). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the entity format", "errors": {"firstName": "Specify the first name"}}`) + + data, st, err := c.CourierCreate(Courier{}) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if st < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } + + cur := Courier{Patronymic: fmt.Sprintf("%s", RandomString(5))} + jr, _ = json.Marshal(&cur) + + p = url.Values{ + "courier": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/couriers/%d/edit", cur.ID)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "An attempt was made to edit a nonexistent record"}`) + + idata, st, err := c.CourierEdit(cur) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if st < http.StatusBadRequest { + t.Error(statusFail) + } + + if idata.Success != false { + t.Error(successFail) + } +} + func TestClient_DeliveryServiceEdit(t *testing.T) { c := client() - data, st, err := c.DeliveryServiceEdit(DeliveryService{ + defer gock.Off() + + deliveryService := DeliveryService{ Active: false, Code: RandomString(5), Name: RandomString(5), - }) + } + + jr, _ := json.Marshal(&deliveryService) + + p := url.Values{ + "deliveryService": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/delivery-services/%s/edit", deliveryService.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true, "id": 1}`) + + data, st, err := c.DeliveryServiceEdit(deliveryService) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } @@ -1297,23 +2628,77 @@ func TestClient_DeliveryServiceEdit(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_DeliveryServiceEdit_Fail(t *testing.T) { + c := client() + defer gock.Off() + + deliveryService := DeliveryService{ + Active: false, + Name: RandomString(5), + } + + jr, _ := json.Marshal(&deliveryService) + + p := url.Values{ + "deliveryService": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/delivery-services/%s/edit", deliveryService.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "API method not found"}`) + + data, st, err := c.DeliveryServiceEdit(deliveryService) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if st < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_DeliveryTypeEdit(t *testing.T) { c := client() x := []string{"cash", "bank-card"} - data, st, err := c.DeliveryTypeEdit(DeliveryType{ + defer gock.Off() + + deliveryType := DeliveryType{ Active: false, Code: RandomString(5), Name: RandomString(5), DefaultCost: 300, PaymentTypes: x, DefaultForCrm: false, - }) + } + + jr, _ := json.Marshal(&deliveryType) + + p := url.Values{ + "deliveryType": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/delivery-types/%s/edit", deliveryType.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true}`) + + data, st, err := c.DeliveryTypeEdit(deliveryType) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } @@ -1323,19 +2708,76 @@ func TestClient_DeliveryTypeEdit(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_DeliveryTypeEdit_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + deliveryType := DeliveryType{ + Active: false, + Name: RandomString(5), + DefaultCost: 300, + PaymentTypes: []string{"cash", "bank-card"}, + DefaultForCrm: false, + } + + jr, _ := json.Marshal(&deliveryType) + + p := url.Values{ + "deliveryType": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/delivery-types/%s/edit", deliveryType.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "API method not found"}`) + + data, st, err := c.DeliveryTypeEdit(deliveryType) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if st < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_OrderMethodEdit(t *testing.T) { c := client() + defer gock.Off() - data, st, err := c.OrderMethodEdit(OrderMethod{ + orderMethod := OrderMethod{ Code: RandomString(5), Name: RandomString(5), Active: false, DefaultForCRM: false, - }) + } + + jr, _ := json.Marshal(&orderMethod) + + p := url.Values{ + "orderMethod": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/order-methods/%s/edit", orderMethod.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true}`) + + data, st, err := c.OrderMethodEdit(orderMethod) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } @@ -1345,19 +2787,74 @@ func TestClient_OrderMethodEdit(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_OrderMethodEdit_Fail(t *testing.T) { + c := client() + defer gock.Off() + + orderMethod := OrderMethod{ + Name: RandomString(5), + Active: false, + DefaultForCRM: false, + } + + jr, _ := json.Marshal(&orderMethod) + + p := url.Values{ + "orderMethod": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/order-methods/%s/edit", orderMethod.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "API method not found"}`) + + data, st, err := c.OrderMethodEdit(orderMethod) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if st < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_OrderTypeEdit(t *testing.T) { c := client() - data, st, err := c.OrderTypeEdit(OrderType{ + defer gock.Off() + + orderType := OrderType{ Code: RandomString(5), Name: RandomString(5), Active: false, DefaultForCRM: false, - }) + } + + jr, _ := json.Marshal(&orderType) + + p := url.Values{ + "orderType": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/order-types/%s/edit", orderType.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true}`) + + data, st, err := c.OrderTypeEdit(orderType) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } @@ -1367,21 +2864,75 @@ func TestClient_OrderTypeEdit(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_OrderTypeEdit_Fail(t *testing.T) { + c := client() + defer gock.Off() + + orderType := OrderType{ + Name: RandomString(5), + Active: false, + DefaultForCRM: false, + } + jr, _ := json.Marshal(&orderType) + + p := url.Values{ + "orderType": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/order-types/%s/edit", orderType.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "API method not found"}`) + + data, st, err := c.OrderTypeEdit(orderType) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if st < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_PaymentStatusEdit(t *testing.T) { c := client() - data, st, err := c.PaymentStatusEdit(PaymentStatus{ + defer gock.Off() + + paymentStatus := PaymentStatus{ Code: RandomString(5), Name: RandomString(5), Active: false, DefaultForCRM: false, PaymentTypes: []string{"cash"}, PaymentComplete: false, - }) + } + + jr, _ := json.Marshal(&paymentStatus) + + p := url.Values{ + "paymentStatus": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/payment-statuses/%s/edit", paymentStatus.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true}`) + + data, st, err := c.PaymentStatusEdit(paymentStatus) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } @@ -1391,19 +2942,75 @@ func TestClient_PaymentStatusEdit(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_PaymentStatusEdit_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + paymentStatus := PaymentStatus{ + Name: RandomString(5), + Active: false, + DefaultForCRM: false, + PaymentTypes: []string{"cash"}, + PaymentComplete: false, + } + jr, _ := json.Marshal(&paymentStatus) + + p := url.Values{ + "paymentStatus": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/payment-statuses/%s/edit", paymentStatus.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "API method not found"}`) + + data, st, err := c.PaymentStatusEdit(paymentStatus) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if st < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_PaymentTypeEdit(t *testing.T) { c := client() - data, st, err := c.PaymentTypeEdit(PaymentType{ + defer gock.Off() + + paymentType := PaymentType{ Code: RandomString(5), Name: RandomString(5), Active: false, DefaultForCRM: false, - }) + } + jr, _ := json.Marshal(&paymentType) + + p := url.Values{ + "paymentType": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/payment-types/%s/edit", paymentType.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true}`) + + data, st, err := c.PaymentTypeEdit(paymentType) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } @@ -1413,18 +3020,72 @@ func TestClient_PaymentTypeEdit(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_PaymentTypeEdit_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + paymentType := PaymentType{ + Name: RandomString(5), + Active: false, + DefaultForCRM: false, + } + jr, _ := json.Marshal(&paymentType) + + p := url.Values{ + "paymentType": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/payment-types/%s/edit", paymentType.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "API method not found"}`) + + data, st, err := c.PaymentTypeEdit(paymentType) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if st < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_PriceTypeEdit(t *testing.T) { c := client() - data, st, err := c.PriceTypeEdit(PriceType{ + defer gock.Off() + + priceType := PriceType{ Code: RandomString(5), Name: RandomString(5), Active: false, - }) + } + jr, _ := json.Marshal(&priceType) + + p := url.Values{ + "priceType": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/price-types/%s/edit", priceType.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true}`) + + data, st, err := c.PriceTypeEdit(priceType) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } @@ -1438,15 +3099,67 @@ func TestClient_PriceTypeEdit(t *testing.T) { } } +func TestClient_PriceTypeEdit_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + priceType := PriceType{ + Name: RandomString(5), + Active: false, + } + jr, _ := json.Marshal(&priceType) + + p := url.Values{ + "priceType": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/price-types/%s/edit", priceType.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "API method not found"}`) + + data, st, err := c.PriceTypeEdit(priceType) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if st < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_ProductStatusEdit(t *testing.T) { c := client() - data, st, err := c.ProductStatusEdit(ProductStatus{ + defer gock.Off() + + productStatus := ProductStatus{ Code: RandomString(5), Name: RandomString(5), Active: false, CancelStatus: false, - }) + } + jr, _ := json.Marshal(&productStatus) + + p := url.Values{ + "productStatus": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/product-statuses/%s/edit", productStatus.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true}`) + + data, st, err := c.ProductStatusEdit(productStatus) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } @@ -1460,15 +3173,68 @@ func TestClient_ProductStatusEdit(t *testing.T) { } } +func TestClient_ProductStatusEdit_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + productStatus := ProductStatus{ + Name: RandomString(5), + Active: false, + CancelStatus: false, + } + jr, _ := json.Marshal(&productStatus) + + p := url.Values{ + "productStatus": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/product-statuses/%s/edit", productStatus.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "API method not found"}`) + + data, st, err := c.ProductStatusEdit(productStatus) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if st < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_StatusEdit(t *testing.T) { c := client() - data, st, err := c.StatusEdit(Status{ + defer gock.Off() + + status := Status{ Code: RandomString(5), Name: RandomString(5), Active: false, Group: "new", - }) + } + jr, _ := json.Marshal(&status) + + p := url.Values{ + "status": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/statuses/%s/edit", status.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true}`) + + data, st, err := c.StatusEdit(status) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } @@ -1478,38 +3244,144 @@ func TestClient_StatusEdit(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_StatusEdit_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + status := Status{ + Name: RandomString(5), + Active: false, + Group: "new", + } + + jr, _ := json.Marshal(&status) + + p := url.Values{ + "status": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/statuses/%s/edit", status.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "API method not found"}`) + + data, st, err := c.StatusEdit(status) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if st < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_SiteEdit(t *testing.T) { c := client() - data, _, err := c.SiteEdit(Site{ + defer gock.Off() + + site := Site{ Code: RandomString(5), Name: RandomString(5), URL: fmt.Sprintf("https://%s.example.com", RandomString(4)), LoadFromYml: false, - }) + } + jr, _ := json.Marshal(&site) + + p := url.Values{ + "site": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/sites/%s/edit", site.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true}`) + + data, _, err := c.SiteEdit(site) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if data.Success == false { + t.Errorf("%v", err.ApiError()) + } +} + +func TestClient_SiteEdit_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + site := Site{ + Code: RandomString(5), + Name: RandomString(5), + LoadFromYml: false, + } + + jr, _ := json.Marshal(&site) + + p := url.Values{ + "site": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/sites/%s/edit", site.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(405). + BodyString(`{"success": false, "errorMsg": "Method Not Allowed"}`) + + data, _, err := c.SiteEdit(site) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } if data.Success != false { - t.Errorf("%v", err.ApiError()) + t.Error(successFail) } } func TestClient_StoreEdit(t *testing.T) { c := client() - data, st, err := c.StoreEdit(Store{ + defer gock.Off() + + store := Store{ Code: RandomString(5), Name: RandomString(5), Active: false, Type: "store-type-warehouse", InventoryType: "integer", - }) + } + + jr, _ := json.Marshal(&store) + + p := url.Values{ + "store": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/stores/%s/edit", store.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true}`) + + data, st, err := c.StoreEdit(store) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } @@ -1523,47 +3395,69 @@ func TestClient_StoreEdit(t *testing.T) { } } -func TestClient_PackChange(t *testing.T) { +func TestClient_StoreEdit_Fail(t *testing.T) { c := client() - o, status, err := c.OrderCreate(Order{ - FirstName: "Понтелей", - LastName: "Турбин", - Patronymic: "Аристархович", - ExternalID: RandomString(8), - Email: fmt.Sprintf("%s@example.com", RandomString(8)), - Items: []OrderItem{{Offer: Offer{ID: 25472}, Quantity: 5}}, - }) + defer gock.Off() + + store := Store{ + Name: RandomString(5), + Active: false, + Type: "store-type-warehouse", + InventoryType: "integer", + } + + jr, _ := json.Marshal(&store) + + p := url.Values{ + "store": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/reference/stores/%s/edit", store.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "API method not found"}`) + + data, st, err := c.StoreEdit(store) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } - if status != http.StatusCreated { - t.Errorf("%v", err.ApiError()) + if st < http.StatusBadRequest { + t.Error(statusFail) } - if o.Success != true { - t.Errorf("%v", err.ApiError()) + if data.Success != false { + t.Error(successFail) } +} - g, status, err := c.Order(strconv.Itoa(o.ID), "id", "") - if err.RuntimeErr != nil { - t.Errorf("%v", err.Error()) - } +func TestClient_PackChange(t *testing.T) { + c := client() + defer gock.Off() - if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) - } - - if o.Success != true { - t.Errorf("%v", err.ApiError()) - } - - p, status, err := c.PackCreate(Pack{ + pack := Pack{ Store: "test-store", - ItemID: g.Order.Items[0].ID, + ItemID: 123, Quantity: 1, - }) + } + + jr, _ := json.Marshal(&pack) + + pr := url.Values{ + "pack": {string(jr[:])}, + } + + gock.New(crmUrl). + Post("/orders/packs/create"). + MatchType("url"). + BodyString(pr.Encode()). + Reply(201). + BodyString(`{"success": true, "id": 1}`) + + p, status, err := c.PackCreate(pack) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } @@ -1576,6 +3470,11 @@ func TestClient_PackChange(t *testing.T) { t.Errorf("%v", err.ApiError()) } + gock.New(crmUrl). + Get(fmt.Sprintf("/orders/packs/%d", p.ID)). + Reply(200). + BodyString(`{"success": true}`) + s, status, err := c.Pack(p.ID) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1589,6 +3488,19 @@ func TestClient_PackChange(t *testing.T) { t.Errorf("%v", err.ApiError()) } + jr, _ = json.Marshal(&Pack{ID: p.ID, Quantity: 2}) + + pr = url.Values{ + "pack": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/orders/packs/%d/edit", p.ID)). + MatchType("url"). + BodyString(pr.Encode()). + Reply(200). + BodyString(`{"success": true}`) + e, status, err := c.PackEdit(Pack{ID: p.ID, Quantity: 2}) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1602,6 +3514,12 @@ func TestClient_PackChange(t *testing.T) { t.Errorf("%v", err.ApiError()) } + gock.New(crmUrl). + Post(fmt.Sprintf("/orders/packs/%d/delete", p.ID)). + MatchType("url"). + Reply(200). + BodyString(`{"success": true}`) + d, status, err := c.PackDelete(p.ID) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1616,9 +3534,118 @@ func TestClient_PackChange(t *testing.T) { } } +func TestClient_PackChange_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + pack := Pack{ + Store: "test-store", + ItemID: iCodeFail, + Quantity: 1, + } + + jr, _ := json.Marshal(&pack) + + pr := url.Values{ + "pack": {string(jr[:])}, + } + + gock.New(crmUrl). + Post("/orders/packs/create"). + MatchType("url"). + BodyString(pr.Encode()). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the entity format"}`) + + p, status, err := c.PackCreate(pack) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if p.Success != false { + t.Error(successFail) + } + + gock.New(crmUrl). + Get(fmt.Sprintf("/orders/packs/%d", iCodeFail)). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the entity format"}`) + + s, status, err := c.Pack(iCodeFail) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if s.Success != false { + t.Error(successFail) + } + + jr, _ = json.Marshal(&Pack{ID: iCodeFail, Quantity: 2}) + + pr = url.Values{ + "pack": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/orders/packs/%d/edit", iCodeFail)). + MatchType("url"). + BodyString(pr.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "Pack with id 123123 not found"}`) + + e, status, err := c.PackEdit(Pack{ID: iCodeFail, Quantity: 2}) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if e.Success != false { + t.Error(successFail) + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/orders/packs/%d/delete", iCodeFail)). + MatchType("url"). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Pack not found"}`) + + d, status, err := c.PackDelete(iCodeFail) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if d.Success != false { + t.Error(successFail) + } +} + func TestClient_PacksHistory(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/orders/packs/history"). + MatchParam("filter[sinceId]", "5"). + Reply(200). + BodyString(`{"success": true, "history": [{"id": 1}]}`) + data, status, err := c.PacksHistory(PacksHistoryRequest{Filter: OrdersHistoryFilter{SinceID: 5}}) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1633,13 +3660,47 @@ func TestClient_PacksHistory(t *testing.T) { } if len(data.History) == 0 { + t.Errorf("%v", err.ApiError()) } } +func TestClient_PacksHistory_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + gock.New(crmUrl). + Get("/orders/packs/history"). + MatchParam("filter[startDate]", "2020-13-12"). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) + + data, status, err := c.PacksHistory(PacksHistoryRequest{Filter: OrdersHistoryFilter{StartDate: "2020-13-12"}}) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_Packs(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/orders/packs"). + MatchParam("page", "1"). + Reply(200). + BodyString(`{"success": true}`) + data, status, err := c.Packs(PacksRequest{Filter: PacksFilter{}, Page: 1}) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1650,13 +3711,48 @@ func TestClient_Packs(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_Packs_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + gock.New(crmUrl). + Get("/orders/packs"). + MatchParam("filter[shipmentDateFrom]", "2020-13-12"). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) + + data, status, err := c.Packs(PacksRequest{Filter: PacksFilter{ShipmentDateFrom: "2020-13-12"}}) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_Inventories(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/store/inventories"). + MatchParam("filter[details]", "1"). + MatchParam("page", "1"). + Reply(200). + BodyString(`{"success": true, "id": 1}`) + data, status, err := c.Inventories(InventoriesRequest{Filter: InventoriesFilter{Details: 1}, Page: 1}) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1667,13 +3763,46 @@ func TestClient_Inventories(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_Inventories_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + gock.New(crmUrl). + Get("/store/inventories"). + MatchParam("filter[sites][]", codeFail). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) + + data, status, err := c.Inventories(InventoriesRequest{Filter: InventoriesFilter{Sites: []string{codeFail}}}) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_Segments(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/segments"). + Reply(200). + BodyString(`{"success": true, "id": 1}`) + data, status, err := c.Segments(SegmentsRequest{}) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1684,17 +3813,45 @@ func TestClient_Segments(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_Segments_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + gock.New(crmUrl). + Get("/segments"). + MatchParam("filter[active]", "3"). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) + + data, status, err := c.Segments(SegmentsRequest{Filter: SegmentsFilter{Active: 3}}) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + func TestClient_IntegrationModule(t *testing.T) { c := client() name := RandomString(5) code := RandomString(8) - m, status, err := c.IntegrationModuleEdit(IntegrationModule{ + defer gock.Off() + + integrationModule := IntegrationModule{ Code: code, IntegrationCode: code, Active: false, @@ -1703,7 +3860,22 @@ func TestClient_IntegrationModule(t *testing.T) { BaseURL: fmt.Sprintf("http://example.com/%s", name), ClientID: RandomString(10), Logo: "https://cdn.worldvectorlogo.com/logos/github-icon.svg", - }) + } + + jr, _ := json.Marshal(&integrationModule) + + pr := url.Values{ + "integrationModule": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/integration-modules/%s/edit", integrationModule.Code)). + MatchType("url"). + BodyString(pr.Encode()). + Reply(201). + BodyString(`{"success": true}`) + + m, status, err := c.IntegrationModuleEdit(integrationModule) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } @@ -1716,6 +3888,11 @@ func TestClient_IntegrationModule(t *testing.T) { t.Errorf("%v", err.ApiError()) } + gock.New(crmUrl). + Get(fmt.Sprintf("/integration-modules/%s", code)). + Reply(200). + BodyString(`{"success": true}`) + g, status, err := c.IntegrationModule(code) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1730,36 +3907,80 @@ func TestClient_IntegrationModule(t *testing.T) { } } -func TestClient_IntegrationModuleFail(t *testing.T) { +func TestClient_IntegrationModule_Fail(t *testing.T) { c := client() + + name := RandomString(5) code := RandomString(8) - m, status, err := c.IntegrationModuleEdit(IntegrationModule{ - Code: code, - }) - if err.RuntimeErr == nil { + defer gock.Off() + + integrationModule := IntegrationModule{ + IntegrationCode: code, + Active: false, + Name: fmt.Sprintf("Integration module %s", name), + AccountURL: fmt.Sprintf("http://example.com/%s/account", name), + BaseURL: fmt.Sprintf("http://example.com/%s", name), + ClientID: RandomString(10), + Logo: "https://cdn.worldvectorlogo.com/logos/github-icon.svg", + } + + jr, _ := json.Marshal(&integrationModule) + + pr := url.Values{ + "integrationModule": {string(jr[:])}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/integration-modules/%s/edit", integrationModule.Code)). + MatchType("url"). + BodyString(pr.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "API method not found"}`) + + m, status, err := c.IntegrationModuleEdit(integrationModule) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } if status < http.StatusBadRequest { + t.Error(statusFail) } if m.Success != false { + t.Error(successFail) } - g, status, err := c.IntegrationModule(RandomString(12)) - if err.RuntimeErr == nil { + gock.New(crmUrl). + Get(fmt.Sprintf("/integration-modules/%s", code)). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) + + g, status, err := c.IntegrationModule(code) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } if status < http.StatusBadRequest { + t.Error(statusFail) } if g.Success != false { + t.Error(successFail) } } func TestClient_ProductsGroup(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/store/product-groups"). + MatchParam("filter[active]", "1"). + Reply(200). + BodyString(`{"success": true}`) + g, status, err := c.ProductsGroup(ProductsGroupsRequest{ Filter: ProductsGroupsFilter{ Active: 1, @@ -1774,13 +3995,52 @@ func TestClient_ProductsGroup(t *testing.T) { } if g.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_ProductsGroup_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + gock.New(crmUrl). + Get("/store/product-groups"). + MatchParam("filter[active]", "3"). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) + + g, status, err := c.ProductsGroup(ProductsGroupsRequest{ + Filter: ProductsGroupsFilter{ + Active: 3, + }, + }) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if g.Success != false { + t.Error(successFail) + } +} + func TestClient_Products(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/store/products"). + MatchParam("filter[active]", "1"). + MatchParam("filter[minPrice]", "1"). + Reply(200). + BodyString(`{"success": true}`) + g, status, err := c.Products(ProductsRequest{ Filter: ProductsFilter{ Active: 1, @@ -1796,16 +4056,52 @@ func TestClient_Products(t *testing.T) { } if g.Success != true { + t.Errorf("%v", err.ApiError()) } } +func TestClient_Products_Fail(t *testing.T) { + c := client() + + defer gock.Off() + + gock.New(crmUrl). + Get("/store/products"). + MatchParam("filter[active]", "3"). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) + + g, status, err := c.Products(ProductsRequest{ + Filter: ProductsFilter{Active: 3}, + }) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if g.Success != false { + t.Error(successFail) + } +} + func TestClient_ProductsProperties(t *testing.T) { c := client() sites := make([]string, 1) sites[0] = os.Getenv("RETAILCRM_SITE") + defer gock.Off() + + gock.New(crmUrl). + Get("/store/products"). + MatchParam("filter[sites][]", sites[0]). + Reply(200). + BodyString(`{"success": true}`) + g, status, err := c.ProductsProperties(ProductsPropertiesRequest{ Filter: ProductsPropertiesFilter{ Sites: sites, @@ -1827,6 +4123,14 @@ func TestClient_ProductsProperties(t *testing.T) { func TestClient_DeliveryShipments(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/delivery/shipments"). + MatchParam("filter[dateFrom]", "2017-10-10"). + Reply(200). + BodyString(`{"success": true}`) + g, status, err := c.DeliveryShipments(DeliveryShipmentsRequest{ Filter: ShipmentFilter{ DateFrom: "2017-10-10", @@ -1845,15 +4149,61 @@ func TestClient_DeliveryShipments(t *testing.T) { } } -func TestClient_CostCreate(t *testing.T) { +func TestClient_DeliveryShipments_Fail(t *testing.T) { c := client() - data, status, err := c.CostCreate(CostRecord{ + defer gock.Off() + + gock.New(crmUrl). + Get("/delivery/shipments"). + MatchParam("filter[stores][]", codeFail). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) + + g, status, err := c.DeliveryShipments(DeliveryShipmentsRequest{ + Filter: ShipmentFilter{ + Stores: []string{codeFail}, + }, + }) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if g.Success != false { + t.Error(successFail) + } +} + +func TestClient_Cost(t *testing.T) { + c := client() + + costRecord := CostRecord{ DateFrom: "2018-04-02", DateTo: "2018-04-02", Summ: 124, CostItem: "seo", - }) + } + + defer gock.Off() + + str, _ := json.Marshal(costRecord) + + p := url.Values{ + "cost": {string(str)}, + } + + gock.New(crmUrl). + Post("/costs/create"). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true, "id": 123}`) + + data, status, err := c.CostCreate(costRecord) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1867,13 +4217,17 @@ func TestClient_CostCreate(t *testing.T) { t.Errorf("%v", err.ApiError()) } - id = data.ID -} + id := data.ID -func TestClient_Costs(t *testing.T) { - c := client() + gock.New(crmUrl). + Get("/costs"). + MatchParam("filter[ids][]", strconv.Itoa(id)). + MatchParam("limit", "20"). + MatchParam("page", "1"). + Reply(200). + BodyString(`{"success": true}`) - data, status, err := c.Costs(CostsRequest{ + costs, status, err := c.Costs(CostsRequest{ Filter: CostsFilter{ Ids: []string{strconv.Itoa(id)}, }, @@ -1889,15 +4243,16 @@ func TestClient_Costs(t *testing.T) { t.Errorf("%v", err.ApiError()) } - if data.Success != true { + if costs.Success != true { t.Errorf("%v", err.ApiError()) } -} -func TestClient_Cost(t *testing.T) { - c := client() + gock.New(crmUrl). + Get(fmt.Sprintf("/costs/%d", id)). + Reply(200). + BodyString(`{"success": true}`) - data, status, err := c.Cost(id) + cost, status, err := c.Cost(id) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1907,57 +4262,211 @@ func TestClient_Cost(t *testing.T) { t.Errorf("%v", err.ApiError()) } - if data.Success != true { + if cost.Success != true { + t.Errorf("%v", err.ApiError()) + } + + costRecord.DateFrom = "2018-04-09" + costRecord.DateTo = "2018-04-09" + costRecord.Summ = 421 + + str, _ = json.Marshal(costRecord) + + p = url.Values{ + "cost": {string(str)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/costs/%d/edit", id)). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + + costEdit, status, err := c.CostEdit(id, costRecord) + + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if !statuses[status] { + t.Errorf("%v", err.ApiError()) + } + + if costEdit.Success != true { + t.Errorf("%v", err.ApiError()) + } + + j, _ := json.Marshal(&id) + + p = url.Values{ + "costs": {string(j)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/costs/%d/delete", id)). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + + costDelete, status, err := c.CostDelete(id) + + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if !statuses[status] { + t.Errorf("%v", err.ApiError()) + } + + if costDelete.Success != true { t.Errorf("%v", err.ApiError()) } } -func TestClient_CostEdit(t *testing.T) { +func TestClient_Cost_Fail(t *testing.T) { c := client() - data, status, err := c.CostEdit(id, CostRecord{ - DateFrom: "2018-04-09", - DateTo: "2018-04-09", - Summ: 421, + defer gock.Off() + + costRecord := CostRecord{ + DateFrom: "2018-13-13", + DateTo: "2012-04-02", + Summ: 124, CostItem: "seo", - Order: nil, + } + + str, _ := json.Marshal(costRecord) + + p := url.Values{ + "cost": {string(str)}, + } + + gock.New(crmUrl). + Post("/costs/create"). + MatchType("url"). + BodyString(p.Encode()). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Cost is not loaded"}`) + + data, status, err := c.CostCreate(costRecord) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + id := data.ID + + gock.New(crmUrl). + Get("/costs"). + MatchParam("filter[sites][]", codeFail). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) + + costs, status, err := c.Costs(CostsRequest{ + Filter: CostsFilter{Sites: []string{codeFail}}, }) - if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } - if !statuses[status] { - t.Errorf("%v", err.ApiError()) + if status < http.StatusBadRequest { + t.Error(statusFail) } - if data.Success != true { - t.Errorf("%v", err.ApiError()) + if costs.Success != false { + t.Error(successFail) } -} -func TestClient_CostDelete(t *testing.T) { - c := client() - - data, status, err := c.CostDelete(id) + gock.New(crmUrl). + Get(fmt.Sprintf("/costs/%d", id)). + Reply(404). + BodyString(`{"success": false, "errorMsg": "Not found"}`) + cost, status, err := c.Cost(id) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } - if !statuses[status] { - t.Errorf("%v", err.ApiError()) + if status < http.StatusBadRequest { + t.Error(statusFail) } - if data.Success != true { - t.Errorf("%v", err.ApiError()) + if cost.Success != false { + t.Error(successFail) + } + + costRecord.DateFrom = "2020-13-12" + costRecord.DateTo = "2012-04-09" + costRecord.Summ = 421 + costRecord.Sites = []string{codeFail} + + str, _ = json.Marshal(costRecord) + + p = url.Values{ + "cost": {string(str)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/costs/%d/edit", id)). + MatchType("url"). + BodyString(p.Encode()). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Cost is not loaded"}`) + + costEdit, status, err := c.CostEdit(id, costRecord) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if costEdit.Success != false { + t.Error(successFail) + } + + j, _ := json.Marshal(&id) + + p = url.Values{ + "costs": {string(j)}, + } + gock.New(crmUrl). + Post(fmt.Sprintf("/costs/%d/delete", id)). + MatchType("url"). + BodyString(p.Encode()). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Not found"}`) + + costDelete, status, err := c.CostDelete(id) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if costDelete.Success != false { + t.Error(successFail) } } func TestClient_CostsUpload(t *testing.T) { c := client() - data, status, err := c.CostsUpload([]CostRecord{ + defer gock.Off() + + costsUpload := []CostRecord{ { Source: nil, DateFrom: "2018-04-02", @@ -1975,7 +4484,22 @@ func TestClient_CostsUpload(t *testing.T) { Order: nil, Sites: []string{"retailcrm-ru"}, }, - }) + } + + j, _ := json.Marshal(&costsUpload) + + p := url.Values{ + "costs": {string(j)}, + } + + gock.New(crmUrl). + Post("/costs/upload"). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true, "uploadedCosts": [1, 2]}`) + + data, status, err := c.CostsUpload(costsUpload) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1986,32 +4510,122 @@ func TestClient_CostsUpload(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } - ids = data.UploadedCosts + ids := data.UploadedCosts + + j, _ = json.Marshal(&ids) + + p = url.Values{ + "ids": {string(j)}, + } + + gock.New(crmUrl). + Post("/costs/delete"). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + + costsDelete, status, err := c.CostsDelete(ids) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if !statuses[status] { + t.Errorf("%v", err.ApiError()) + } + + if costsDelete.Success != true { + + t.Errorf("%v", err.ApiError()) + } } -func TestClient_CostsDelete(t *testing.T) { +func TestClient_CostsUpload_Fail(t *testing.T) { c := client() - data, status, err := c.CostsDelete(ids) + defer gock.Off() + + costsUpload := []CostRecord{ + { + Source: nil, + DateFrom: "2018-04-03", + DateTo: "2018-04-03", + Summ: 125, + CostItem: "seo", + Order: nil, + Sites: []string{codeFail}, + }, + } + + j, _ := json.Marshal(&costsUpload) + + p := url.Values{ + "costs": {string(j)}, + } + + gock.New(crmUrl). + Post("/costs/upload"). + MatchType("url"). + BodyString(p.Encode()). + Reply(460). + BodyString(`{"success": false, "errorMsg": "Costs are loaded with errors"}`) + + data, status, err := c.CostsUpload(costsUpload) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } - if !statuses[status] { - t.Errorf("%v", err.ApiError()) + if status < http.StatusBadRequest { + t.Error(statusFail) } - if data.Success != true { - t.Errorf("%v", err.ApiError()) + if data.Success != false { + t.Error(successFail) + } + + ids := data.UploadedCosts + + j, _ = json.Marshal(&ids) + + p = url.Values{ + "ids": {string(j)}, + } + + gock.New(crmUrl). + Post("/costs/delete"). + MatchType("url"). + BodyString(p.Encode()). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Expected array, but got NULL: null"}`) + + costsDelete, status, err := c.CostsDelete(ids) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if costsDelete.Success != false { + t.Error(successFail) } } func TestClient_CustomFields(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmUrl). + Get("/custom-fields"). + Reply(200). + BodyString(`{"success": true}`) + data, status, err := c.CustomFields(CustomFieldsRequest{}) if err.RuntimeErr != nil { @@ -2026,10 +4640,86 @@ func TestClient_CustomFields(t *testing.T) { t.Errorf("%v", err.ApiError()) } } -func TestClient_CustomDictionaries(t *testing.T) { + +func TestClient_CustomFields_Fail(t *testing.T) { c := client() - data, status, err := c.CustomDictionaries(CustomDictionariesRequest{ + defer gock.Off() + + gock.New(crmUrl). + Get("/custom-fields"). + MatchParam("filter[type]", codeFail). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) + + data, status, err := c.CustomFields(CustomFieldsRequest{Filter: CustomFieldsFilter{Type: codeFail}}) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if data.Success != false { + t.Error(successFail) + } +} + +func TestClient_CustomDictionariesCreate(t *testing.T) { + c := client() + + code := "test_" + RandomString(8) + + defer gock.Off() + + customDictionary := CustomDictionary{ + Name: "test2", + Code: code, + Elements: []Element{ + { + Name: "test", + Code: "test", + }, + }, + } + + j, _ := json.Marshal(&customDictionary) + + p := url.Values{ + "customDictionary": {string(j)}, + } + + gock.New(crmUrl). + Post("/custom-fields/dictionaries/create"). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true, "id": 1}`) + + data, status, err := c.CustomDictionariesCreate(customDictionary) + + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if !statuses[status] { + t.Errorf("%v", err.ApiError()) + } + + if data.Success != true { + t.Errorf("%v", err.ApiError()) + } + + gock.New(crmUrl). + Get("/custom-fields/dictionaries"). + MatchParam("filter[name]", "test"). + MatchParam("limit", "10"). + MatchParam("page", "1"). + Reply(200). + BodyString(`{"success": true}`) + + cds, status, err := c.CustomDictionaries(CustomDictionariesRequest{ Filter: CustomDictionariesFilter{ Name: "test", }, @@ -2042,18 +4732,51 @@ func TestClient_CustomDictionaries(t *testing.T) { } if !statuses[status] { + t.Errorf("%v", err.ApiError()) } - if data.Success != true { + if cds.Success != true { t.Errorf("%v", err.ApiError()) } -} -func TestClient_CustomDictionary(t *testing.T) { - c := client() + gock.New(crmUrl). + Get(fmt.Sprintf("/custom-fields/dictionaries/%s", code)). + Reply(200). + BodyString(`{"success": true}`) - data, status, err := c.CustomDictionary("test2") + cd, status, err := c.CustomDictionary(code) + + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if cd.Success != true { + t.Errorf("%v", err.ApiError()) + } + + customDictionary.Name = "test223" + customDictionary.Elements = []Element{ + { + Name: "test3", + Code: "test3", + }, + } + + j, _ = json.Marshal(&customDictionary) + + p = url.Values{ + "customDictionary": {string(j)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/custom-fields/dictionaries/%s/edit", customDictionary.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + + cde, status, err := c.CustomDictionaryEdit(customDictionary) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -2063,15 +4786,17 @@ func TestClient_CustomDictionary(t *testing.T) { t.Errorf("%v", err.ApiError()) } - if data.Success != true { + if cde.Success != true { t.Errorf("%v", err.ApiError()) } } -func TestClient_CustomDictionariesCreate(t *testing.T) { +func TestClient_CustomDictionariesCreate_Fail(t *testing.T) { c := client() - data, status, err := c.CustomDictionariesCreate(CustomDictionary{ + defer gock.Off() + + customDictionary := CustomDictionary{ Name: "test2", Code: RandomString(8), Elements: []Element{ @@ -2080,59 +4805,106 @@ func TestClient_CustomDictionariesCreate(t *testing.T) { Code: "test", }, }, - }) + } + j, _ := json.Marshal(&customDictionary) + + p := url.Values{ + "customDictionary": {string(j)}, + } + + gock.New(crmUrl). + Post("/custom-fields/dictionaries/create"). + MatchType("url"). + BodyString(p.Encode()). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) + + data, status, err := c.CustomDictionariesCreate(customDictionary) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } - if !statuses[status] { - t.Errorf("%v", err.ApiError()) + if data.Success != false { + t.Error(successFail) } - if data.Success != true { - t.Errorf("%v", err.ApiError()) + gock.New(crmUrl). + Get(fmt.Sprintf("/custom-fields/dictionaries/%s", codeFail)). + Reply(404). + BodyString(`{"success": false, "errorMsg": "Not found"}`) + + cd, status, err := c.CustomDictionary(codeFail) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } -} -func TestClient_CustomDictionaryEdit(t *testing.T) { - c := client() + if cd.Success != false { + t.Error(successFail) + } - data, status, err := c.CustomDictionaryEdit(CustomDictionary{ - Name: "test223", - Code: "test2", - Elements: []Element{ - { - Name: "test3", - Code: "test3", - }, + customDictionary.Name = "test223" + customDictionary.Elements = []Element{ + { + Name: "test3", }, - }) + } + j, _ = json.Marshal(&customDictionary) + + p = url.Values{ + "customDictionary": {string(j)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/custom-fields/dictionaries/%s/edit", customDictionary.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "API method not found"}`) + + cde, status, err := c.CustomDictionaryEdit(customDictionary) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } - if !statuses[status] { + if status < http.StatusBadRequest{ t.Errorf("%v", err.ApiError()) } - if data.Success != true { - t.Errorf("%v", err.ApiError()) + if cde.Success != false { + t.Error(successFail) } } func TestClient_CustomFieldsCreate(t *testing.T) { c := client() - codeCustomField = RandomString(8) + codeCustomField := RandomString(8) - data, status, err := c.CustomFieldsCreate(CustomFields{ + defer gock.Off() + + customFields := CustomFields{ Name: codeCustomField, Code: codeCustomField, Type: "text", Entity: "order", DisplayArea: "customer", - }) + } + + j, _ := json.Marshal(&customFields) + + p := url.Values{ + "customField": {string(j)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/custom-fields/%s/create", customFields.Entity)). + MatchType("url"). + BodyString(p.Encode()). + Reply(201). + BodyString(`{"success": true, "id": 1}`) + + data, status, err := c.CustomFieldsCreate(customFields) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -2143,14 +4915,16 @@ func TestClient_CustomFieldsCreate(t *testing.T) { } if data.Success != true { + t.Errorf("%v", err.ApiError()) } -} -func TestClient_CustomField(t *testing.T) { - c := client() + gock.New(crmUrl). + Get(fmt.Sprintf("/custom-fields/%s/%s", "order", codeCustomField)). + Reply(200). + BodyString(`{"success": true}`) - data, status, err := c.CustomField("order", codeCustomField) + customField, status, err := c.CustomField("order", codeCustomField) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -2160,29 +4934,123 @@ func TestClient_CustomField(t *testing.T) { t.Errorf("%v", err.ApiError()) } - if data.Success != true { + if customField.Success != true { + t.Errorf("%v", err.ApiError()) + } + + customFields.DisplayArea = "delivery" + + j, _ = json.Marshal(&customFields) + + p = url.Values{ + "customField": {string(j)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/custom-fields/%s/%s/edit", customFields.Entity, customFields.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + + customFieldEdit, status, err := c.CustomFieldEdit(customFields) + + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if !statuses[status] { + t.Errorf("%v", err.ApiError()) + } + + if customFieldEdit.Success != true { t.Errorf("%v", err.ApiError()) } } -func TestClient_CustomFieldEdit(t *testing.T) { +func TestClient_CustomFieldsCreate_Fail(t *testing.T) { c := client() - data, status, err := c.CustomFieldEdit(CustomFields{ - Code: codeCustomField, + codeCustomField := "test_" + RandomString(8) + + defer gock.Off() + + customFields := CustomFields{ + Name: codeCustomField, + Type: "text", Entity: "order", - DisplayArea: "delivery", - }) + DisplayArea: "customer", + } + j, _ := json.Marshal(&customFields) + + p := url.Values{ + "customField": {string(j)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/custom-fields/%s/create", customFields.Entity)). + MatchType("url"). + BodyString(p.Encode()). + Reply(400). + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) + + data, status, err := c.CustomFieldsCreate(customFields) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) } - if !statuses[status] { - t.Errorf("%v", err.ApiError()) + if status < http.StatusBadRequest { + t.Error(statusFail) } - if data.Success != true { - t.Errorf("%v", err.ApiError()) + if data.Success != false { + t.Error(successFail) + } + + gock.New(crmUrl). + Get(fmt.Sprintf("/custom-fields/%s/%s", "order", codeCustomField)). + Reply(404). + BodyString(`{"success": false, "errorMsg": "Not found"}`) + + customField, status, err := c.CustomField("order", codeCustomField) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if customField.Success != false { + t.Error(successFail) + } + + customFields.DisplayArea = "delivery" + + j, _ = json.Marshal(&customFields) + + p = url.Values{ + "customField": {string(j)}, + } + + gock.New(crmUrl). + Post(fmt.Sprintf("/custom-fields/%s/%s/edit", customFields.Entity, customFields.Code)). + MatchType("url"). + BodyString(p.Encode()). + Reply(404). + BodyString(`{"success": false, "errorMsg": "API method not found"}`) + + customFieldEdit, status, err := c.CustomFieldEdit(customFields) + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) + } + + if status < http.StatusBadRequest { + t.Error(statusFail) + } + + if customFieldEdit.Success != false { + t.Error(successFail) } } From d0c3f3bb005571e116528edb5046fbea4e570ca2 Mon Sep 17 00:00:00 2001 From: DmitryZagorulko Date: Mon, 23 Apr 2018 16:28:54 +0300 Subject: [PATCH 5/5] formatting docs and bug fix --- .travis.yml | 1 + README.md | 76 +++++++---- errs/error.go | 10 +- errs/interfaces.go | 2 +- errs/types.go | 2 +- v5/client.go | 329 +++++++++++++++++++++++---------------------- v5/client_test.go | 2 +- 7 files changed, 221 insertions(+), 201 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4ce84ac..f39aae2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,5 @@ go: - '1.10' before_install: - go get -v github.com/google/go-querystring/query + - go get -v github.com/h2non/gock script: go test -v ./... diff --git a/README.md b/README.md index b16934a..9d95ac4 100644 --- a/README.md +++ b/README.md @@ -48,34 +48,58 @@ func main() { fmt.Println(data.Orders[1].FirstName) idata, status, err := c.InventoriesUpload( - []InventoryUpload{ - { - XMLID: "pTKIKAeghYzX21HTdzFCe1", - Stores: []InventoryUploadStore{ - {Code: "test-store-v5", Available: 10, PurchasePrice: 1500}, - {Code: "test-store-v4", Available: 20, PurchasePrice: 1530}, - {Code: "test-store", Available: 30, PurchasePrice: 1510}, - }, - }, - { - XMLID: "JQIvcrCtiSpOV3AAfMiQB3", - Stores: []InventoryUploadStore{ - {Code: "test-store-v5", Available: 45, PurchasePrice: 1500}, - {Code: "test-store-v4", Available: 32, PurchasePrice: 1530}, - {Code: "test-store", Available: 46, PurchasePrice: 1510}, - }, - }, - }, - ) - if err.RuntimeErr != nil { - fmt.Printf("%v", err.Error()) - } + []InventoryUpload{ + { + XMLID: "pTKIKAeghYzX21HTdzFCe1", + Stores: []InventoryUploadStore{ + { + Code: "test-store-v5", + Available: 10, + PurchasePrice: 1500, + }, + { + Code: "test-store-v4", + Available: 20, + PurchasePrice: 1530, + }, + { + Code: "test-store", + Available: 30, + PurchasePrice: 1510, + }, + }, + }, + { + XMLID: "JQIvcrCtiSpOV3AAfMiQB3", + Stores: []InventoryUploadStore{ + { + Code: "test-store-v5", + Available: 45, + PurchasePrice: 1500, + }, + { + Code: "test-store-v4", + Available: 32, + PurchasePrice: 1530, + }, + { + Code: "test-store", + Available: 46, + PurchasePrice: 1510, + }, + }, + }, + }, + ) + if err.RuntimeErr != nil { + fmt.Printf("%v", err.Error()) + } - if status >= http.StatusBadRequest { - fmt.Printf("%v", err.ApiError()) - } + if status >= http.StatusBadRequest { + fmt.Printf("%v", err.ApiError()) + } - fmt.Println(idata.processedOffersCount) + fmt.Println(idata.processedOffersCount) } ``` diff --git a/errs/error.go b/errs/error.go index ff9578c..2582574 100644 --- a/errs/error.go +++ b/errs/error.go @@ -16,14 +16,8 @@ func (f *Failure) ApiError() string { } // ApiErrors returns array of formatted strings that represents API errors -func (f *Failure) ApiErrors() []string { - var errors []string - - for k, i := range f.ApiErrs { - errors = append(errors, fmt.Sprintf("%v: %v", k, i)) - } - - return errors +func (f *Failure) ApiErrors() map[string]string { + return f.ApiErrs } // ErrorResponse method diff --git a/errs/interfaces.go b/errs/interfaces.go index 497b6c1..371eec4 100644 --- a/errs/interfaces.go +++ b/errs/interfaces.go @@ -4,5 +4,5 @@ package errs type Error interface { error ApiError() string - ApiErrors() []string + ApiErrors() map[string]string } diff --git a/errs/types.go b/errs/types.go index 21b4d17..1029675 100644 --- a/errs/types.go +++ b/errs/types.go @@ -9,6 +9,6 @@ type Failure struct { // FailureResponse convert json error response into object type FailureResponse struct { - ErrorMsg string `json:"errorMsg,omitempty"` + ErrorMsg string `json:"errorMsg,omitempty"` Errors map[string]string `json:"errors,omitempty"` } diff --git a/v5/client.go b/v5/client.go index ac6bf00..2b9c0c5 100644 --- a/v5/client.go +++ b/v5/client.go @@ -161,7 +161,7 @@ func fillSite(p *url.Values, site []string) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.versions { @@ -199,7 +199,7 @@ func (c *Client) APIVersions() (VersionResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.credentials { @@ -242,7 +242,7 @@ func (c *Client) APICredentials() (CredentialResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.Customers { @@ -282,7 +282,7 @@ func (c *Client) Customers(parameters CustomersRequest) (CustomersResponse, int, // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -334,7 +334,7 @@ func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // if data.Success == true { @@ -383,7 +383,7 @@ func (c *Client) CustomerCreate(customer Customer, site ...string) (CustomerChan // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -427,7 +427,7 @@ func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (Successfu // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.History { @@ -472,7 +472,7 @@ func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (Customers // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.Notes { @@ -518,7 +518,7 @@ func (c *Client) CustomerNotes(parameters NotesRequest) (NotesResponse, int, err // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // if data.Success == true { @@ -564,7 +564,7 @@ func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) CustomerNoteDelete(id int) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -617,7 +617,7 @@ func (c *Client) CustomerNoteDelete(id int) (SuccessfulResponse, int, errs.Failu // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // if data.Success == true { @@ -663,7 +663,7 @@ func (c *Client) CustomersUpload(customers []Customer, site ...string) (Customer // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // if data.Success == true { @@ -696,10 +696,10 @@ func (c *Client) Customer(id, by, site string) (CustomerResponse, int, errs.Fail // // Example: // -// var client = v5.New("https://demo.url", "09jIJ") +// var client = v5.New("https://demo.url", "09jIJ") // -// data, status, err := client.CustomerEdit( -// v5.Customer{ +// data, status, err := client.CustomerEdit( +// v5.Customer{ // FirstName: "Ivan", // LastName: "Ivanov", // Patronymic: "Ivanovich", @@ -707,14 +707,14 @@ func (c *Client) Customer(id, by, site string) (CustomerResponse, int, errs.Fail // Email: "ivanov@example.com", // }, // "id", -// ) +// ) // // if err.RuntimeErr != nil { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // if data.Success == true { @@ -760,8 +760,8 @@ func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (Cus // // var client = v5.New("https://demo.url", "09jIJ") // -// data, status, err := client.DeliveryTracking( -// v5.DeliveryTrackingRequest{ +// data, status, err := client.DeliveryTracking( +// v5.DeliveryTrackingRequest{ // DeliveryID: "1", // TrackNumber "123", // History: []DeliveryHistoryRecord{ @@ -772,14 +772,14 @@ func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (Cus // } // }, // "delivery-1", -// ) +// ) // // if err.RuntimeErr != nil { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode string) (SuccessfulResponse, int, errs.Failure) { @@ -825,7 +825,7 @@ func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode st // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.DeliveryShipments { @@ -858,24 +858,24 @@ func (c *Client) DeliveryShipments(parameters DeliveryShipmentsRequest) (Deliver // // var client = v5.New("https://demo.url", "09jIJ") // -// data, status, err := client.DeliveryShipmentCreate( -// v5.DeliveryShipment{ +// data, status, err := client.DeliveryShipmentCreate( +// v5.DeliveryShipment{ // Date: "2012-12-12", // Time: v5.DeliveryTime{ // From: "18:00", // To: "20:00", -// }, +// }, // Orders: []v5.Order{{Number: "12"}}, -// }, -// "sdek", -// ) +// }, +// "sdek", +// ) // // if err.RuntimeErr != nil { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // if data.Success == true { @@ -921,7 +921,7 @@ func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // if data.Success == true { @@ -965,7 +965,7 @@ func (c *Client) DeliveryShipment(id int) (DeliveryShipmentResponse, int, errs.F // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) (DeliveryShipmentUpdateResponse, int, errs.Failure) { var resp DeliveryShipmentUpdateResponse @@ -1006,7 +1006,7 @@ func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // if data.Success == true { @@ -1035,12 +1035,12 @@ func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int, // // Example: // -// var client = v5.New("https://demo.url", "09jIJ") - +// var client = v5.New("https://demo.url", "09jIJ") +// // name := "MS" // code := "moysklad3" - -// data, status, err := client.IntegrationModuleEdit(v5.IntegrationModule{ +// +// data, status, err := client.IntegrationModuleEdit(v5.IntegrationModule{ // Code: code, // IntegrationCode: code, // Active: false, @@ -1051,17 +1051,17 @@ func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int, // Logo: "https://cdn.worldvectorlogo.com/logos/github-icon.svg", // }) // -// if err.RuntimeErr != nil { -// fmt.Printf("%v", err.RuntimeErr) -// } +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } // -// if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) -// } +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ApiErr()) +// } // -// if data.Success == true { -// fmt.Printf("%v\n", data.Info) -// } +// if data.Success == true { +// fmt.Printf("%v\n", data.Info) +// } func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (IntegrationModuleEditResponse, int, errs.Failure) { var resp IntegrationModuleEditResponse updateJSON, _ := json.Marshal(&integrationModule) @@ -1097,7 +1097,7 @@ func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (Int // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.Orders { @@ -1137,7 +1137,7 @@ func (c *Client) Orders(parameters OrdersRequest) (OrdersResponse, int, errs.Fai // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (OperationResponse, int, errs.Failure) { var resp OperationResponse @@ -1186,7 +1186,7 @@ func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (Oper // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // if data.Success == true { @@ -1222,24 +1222,24 @@ func (c *Client) OrderCreate(order Order, site ...string) (CreateResponse, int, // // Example: // -// var client = v5.New("https://demo.url", "09jIJ") +// var client = v5.New("https://demo.url", "09jIJ") // -// data, status, err := client.OrdersFixExternalIds(([]v5.IdentifiersPair{{ -//// ID: 1, -//// ExternalID: 12, -//// }}) +// data, status, err := client.OrdersFixExternalIds(([]v5.IdentifiersPair{{ +// ID: 1, +// ExternalID: 12, +// }}) // -// if err.RuntimeErr != nil { -// fmt.Printf("%v", err.RuntimeErr) -// } +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } // -// if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) -// } +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ApiErr()) +// } // -// if data.Success == true { -// fmt.Printf("%v\n", data.ID) -// } +// if data.Success == true { +// fmt.Printf("%v\n", data.ID) +// } func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1278,7 +1278,7 @@ func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulRespo // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.History { @@ -1324,7 +1324,7 @@ func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (CustomersHistor // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // if data.Success == true { @@ -1370,7 +1370,7 @@ func (c *Client) OrderPaymentCreate(payment Payment, site ...string) (CreateResp // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) OrderPaymentDelete(id int) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1414,7 +1414,7 @@ func (c *Client) OrderPaymentDelete(id int) (SuccessfulResponse, int, errs.Failu // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1477,7 +1477,7 @@ func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (S // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // if data.Success == true { @@ -1523,7 +1523,7 @@ func (c *Client) OrdersUpload(orders []Order, site ...string) (OrdersUploadRespo // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // if data.Success == true { @@ -1571,7 +1571,7 @@ func (c *Client) Order(id, by, site string) (OrderResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateResponse, int, errs.Failure) { var resp CreateResponse @@ -1620,7 +1620,7 @@ func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateRespon // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.Packs { @@ -1664,7 +1664,7 @@ func (c *Client) Packs(parameters PacksRequest) (PacksResponse, int, errs.Failur // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // if data.Success == true { @@ -1707,7 +1707,7 @@ func (c *Client) PackCreate(pack Pack) (CreateResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.History { @@ -1746,7 +1746,7 @@ func (c *Client) PacksHistory(parameters PacksHistoryRequest) (PacksHistoryRespo // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // if data.Success == true { @@ -1784,7 +1784,7 @@ func (c *Client) Pack(id int) (PackResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) PackDelete(id int) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1818,7 +1818,7 @@ func (c *Client) PackDelete(id int) (SuccessfulResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) PackEdit(pack Pack) (CreateResponse, int, errs.Failure) { var resp CreateResponse @@ -1901,7 +1901,7 @@ func (c *Client) CostGroups() (CostGroupsResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) CostGroupEdit(costGroup CostGroup) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1964,7 +1964,7 @@ func (c *Client) CostItems() (CostItemsResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) CostItemEdit(costItem CostItem) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -2029,7 +2029,7 @@ func (c *Client) Couriers() (CouriersResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // if data.Success == true { @@ -2076,7 +2076,7 @@ func (c *Client) CourierCreate(courier Courier) (CreateResponse, int, errs.Failu // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) CourierEdit(courier Courier) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -2139,7 +2139,7 @@ func (c *Client) DeliveryServices() (DeliveryServiceResponse, int, errs.Failure) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -2204,7 +2204,7 @@ func (c *Client) DeliveryTypes() (DeliveryTypesResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -2267,7 +2267,7 @@ func (c *Client) LegalEntities() (LegalEntitiesResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -2331,7 +2331,7 @@ func (c *Client) OrderMethods() (OrderMethodsResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -2394,7 +2394,7 @@ func (c *Client) OrderTypes() (OrderTypesResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) OrderTypeEdit(orderType OrderType) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -2767,25 +2767,25 @@ func (c *Client) StoreEdit(store Store) (SuccessfulResponse, int, errs.Failure) // // Example: // -// var client = v5.New("https://demo.url", "09jIJ") +// var client = v5.New("https://demo.url", "09jIJ") // -// data, status, err := client.Segments(SegmentsRequest{ -// Filter: v5.SegmentsFilter{ -// Ids: []int{1,2,3} -// } -// }) +// data, status, err := client.Segments(SegmentsRequest{ +// Filter: v5.SegmentsFilter{ +// Ids: []int{1,2,3} +// } +// }) // -// if err.RuntimeErr != nil { -// fmt.Printf("%v", err.RuntimeErr) -// } +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } // -// if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) -// } +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ApiErr()) +// } // // for _, value := range data.Segments { -// fmt.Printf("%v\n", value) -// } +// fmt.Printf("%v\n", value) +// } func (c *Client) Segments(parameters SegmentsRequest) (SegmentsResponse, int, errs.Failure) { var resp SegmentsResponse @@ -2820,7 +2820,7 @@ func (c *Client) Segments(parameters SegmentsRequest) (SegmentsResponse, int, er // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.Offers { @@ -2851,38 +2851,38 @@ func (c *Client) Inventories(parameters InventoriesRequest) (InventoriesResponse // // Example: // -// var client = v5.New("https://demo.url", "09jIJ") +// var client = v5.New("https://demo.url", "09jIJ") // -// data, status, err := clientc.InventoriesUpload( -// []v5.InventoryUpload{ -// { -// XMLID: "pTKIKAeghYzX21HTdzFCe1", -// Stores: []InventoryUploadStore{ -// {Code: "test-store-v5", Available: 10, PurchasePrice: 1500}, -// {Code: "test-store-v4", Available: 20, PurchasePrice: 1530}, -// {Code: "test-store", Available: 30, PurchasePrice: 1510}, -// }, -// }, -// { -// XMLID: "JQIvcrCtiSpOV3AAfMiQB3", -// Stores: []InventoryUploadStore{ -// {Code: "test-store-v5", Available: 45, PurchasePrice: 1500}, -// {Code: "test-store-v4", Available: 32, PurchasePrice: 1530}, -// {Code: "test-store", Available: 46, PurchasePrice: 1510}, -// }, -// }, -// }, -// ) +// data, status, err := clientc.InventoriesUpload( +// []v5.InventoryUpload{ +// { +// XMLID: "pTKIKAeghYzX21HTdzFCe1", +// Stores: []InventoryUploadStore{ +// {Code: "test-store-v5", Available: 10, PurchasePrice: 1500}, +// {Code: "test-store-v4", Available: 20, PurchasePrice: 1530}, +// {Code: "test-store", Available: 30, PurchasePrice: 1510}, +// }, +// }, +// { +// XMLID: "JQIvcrCtiSpOV3AAfMiQB3", +// Stores: []InventoryUploadStore{ +// {Code: "test-store-v5", Available: 45, PurchasePrice: 1500}, +// {Code: "test-store-v4", Available: 32, PurchasePrice: 1530}, +// {Code: "test-store", Available: 46, PurchasePrice: 1510}, +// }, +// }, +// }, +// ) // -// if err.RuntimeErr != nil { -// fmt.Printf("%v", err.RuntimeErr) -// } +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } // -// if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) -// } +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ApiErr()) +// } // -// fmt.Printf("%v\n", data.NotFoundOffers) +// fmt.Printf("%v\n", data.NotFoundOffers) func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string) (StoreUploadResponse, int, errs.Failure) { var resp StoreUploadResponse @@ -2914,30 +2914,30 @@ func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string // // Example: // -// var client = v5.New("https://demo.url", "09jIJ") +// var client = v5.New("https://demo.url", "09jIJ") // -// data, status, err := client.PricesUpload([]v5.OfferPriceUpload{ -// { +// data, status, err := client.PricesUpload([]v5.OfferPriceUpload{ +// { // ID 1 // Site "store-1" // Prices []PriceUpload{{Code: "price-1"}} -// }, -// { +// }, +// { // ID 2 // Site "store-1" // Prices []PriceUpload{{Code: "price-2"}} -// }, -// }) +// }, +// }) // -// if err.RuntimeErr != nil { -// fmt.Printf("%v", err.RuntimeErr) -// } +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } // -// if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) -// } +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ApiErr()) +// } // -// fmt.Printf("%v\n", data.NotFoundOffers) +// fmt.Printf("%v\n", data.NotFoundOffers) func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, int, errs.Failure) { var resp StoreUploadResponse @@ -2980,7 +2980,7 @@ func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, i // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.ProductGroup { @@ -3025,7 +3025,7 @@ func (c *Client) ProductsGroup(parameters ProductsGroupsRequest) (ProductsGroups // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.Products { @@ -3069,7 +3069,7 @@ func (c *Client) Products(parameters ProductsRequest) (ProductsResponse, int, er // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.Properties { @@ -3113,7 +3113,7 @@ func (c *Client) ProductsProperties(parameters ProductsPropertiesRequest) (Produ // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.Tasks { @@ -3156,7 +3156,7 @@ func (c *Client) Tasks(parameters TasksRequest) (TasksResponse, int, errs.Failur // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // if data.Success == true { @@ -3201,7 +3201,7 @@ func (c *Client) TaskCreate(task Task, site ...string) (CreateResponse, int, err // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // if data.Success == true { @@ -3223,6 +3223,7 @@ func (c *Client) Task(id int) (TaskResponse, int, errs.Failure) { return resp, status, err } + // Task editing // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-tasks-id-edit @@ -3241,7 +3242,7 @@ func (c *Client) Task(id int) (TaskResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) TaskEdit(task Task, site ...string) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -3284,7 +3285,7 @@ func (c *Client) TaskEdit(task Task, site ...string) (SuccessfulResponse, int, e // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.Groups { @@ -3324,7 +3325,7 @@ func (c *Client) UserGroups(parameters UserGroupsRequest) (UserGroupsResponse, i // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.Users { @@ -3364,7 +3365,7 @@ func (c *Client) Users(parameters UsersRequest) (UsersResponse, int, errs.Failur // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // if data.Success == true { @@ -3402,7 +3403,7 @@ func (c *Client) User(id int) (UserResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) UserStatus(id int, status string) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -3465,7 +3466,7 @@ func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.Costs { @@ -3514,7 +3515,7 @@ func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // If data.Success == true { @@ -3556,7 +3557,7 @@ func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, in // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // If data.Success == true { @@ -3613,7 +3614,7 @@ func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, errs.Failure) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // If data.Success == true { @@ -3653,7 +3654,7 @@ func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, errs. // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // If data.Success == true { @@ -3688,7 +3689,7 @@ func (c *Client) Cost(id int) (CostResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } func (c *Client) CostDelete(id int) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -3730,7 +3731,7 @@ func (c *Client) CostDelete(id int) (SuccessfulResponse, int, errs.Failure) { // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // If data.Success == true { @@ -3775,7 +3776,7 @@ func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateRespon // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // for _, value := range data.CustomFields { @@ -3907,7 +3908,7 @@ func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (Cu // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // If data.Success == true { @@ -4001,7 +4002,7 @@ func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (Custom // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // If data.Success == true { @@ -4042,7 +4043,7 @@ func (c *Client) CustomFieldsCreate(customFields CustomFields) (CustomResponse, // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // If data.Success == true { @@ -4081,7 +4082,7 @@ func (c *Client) CustomField(entity, code string) (CustomFieldResponse, int, err // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.ApiErr()) // } // // If data.Success == true { diff --git a/v5/client_test.go b/v5/client_test.go index 72e087c..67341f9 100644 --- a/v5/client_test.go +++ b/v5/client_test.go @@ -4868,7 +4868,7 @@ func TestClient_CustomDictionariesCreate_Fail(t *testing.T) { t.Errorf("%v", err.Error()) } - if status < http.StatusBadRequest{ + if status < http.StatusBadRequest { t.Errorf("%v", err.ApiError()) }