From 8e64270edbef0ea9bd34480493920c504378ed64 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Fri, 28 Sep 2018 01:37:56 +0300 Subject: [PATCH 1/2] add debug mode, add .env support for local testing --- .gitignore | 1 + v5/client.go | 60 +++++--- v5/client_test.go | 354 ++++++++++++++++++++++++---------------------- v5/types.go | 6 +- 4 files changed, 227 insertions(+), 194 deletions(-) diff --git a/.gitignore b/.gitignore index d70a5fb..c3ebba8 100644 --- a/.gitignore +++ b/.gitignore @@ -25,5 +25,6 @@ _testmain.go # IDE's files .idea *.iml +.env # Project ignores diff --git a/v5/client.go b/v5/client.go index 2b9c0c5..e946b11 100644 --- a/v5/client.go +++ b/v5/client.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "io/ioutil" + "log" "net/http" "net/url" "strconv" @@ -17,9 +18,9 @@ import ( // New initalize client func New(url string, key string) *Client { return &Client{ - url, - key, - &http.Client{Timeout: 20 * time.Second}, + URL: url, + Key: key, + httpClient: &http.Client{Timeout: 20 * time.Second}, } } @@ -45,6 +46,10 @@ func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte req.Header.Set("X-API-KEY", c.Key) + if c.Debug { + log.Printf("API Request: %s %s", fmt.Sprintf("%s%s%s", c.URL, prefix, urlWithParameters), c.Key) + } + resp, err := c.httpClient.Do(req) if err != nil { cerr.RuntimeErr = err @@ -61,6 +66,10 @@ func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte cerr.RuntimeErr = err } + if c.Debug { + log.Printf("API Response: %s", res) + } + return res, resp.StatusCode, cerr } @@ -79,6 +88,10 @@ func (c *Client) PostRequest(url string, postParams url.Values) ([]byte, int, er req.Header.Set("Content-Type", "application/x-www-form-urlencoded") req.Header.Set("X-API-KEY", c.Key) + if c.Debug { + log.Printf("API Request: %s %s %s", url, c.Key, postParams.Encode()) + } + resp, err := c.httpClient.Do(req) if err != nil { cerr.RuntimeErr = err @@ -96,6 +109,10 @@ func (c *Client) PostRequest(url string, postParams url.Values) ([]byte, int, er return res, 0, cerr } + if c.Debug { + log.Printf("API Response: %s", res) + } + return res, resp.StatusCode, cerr } @@ -222,7 +239,7 @@ func (c *Client) APICredentials() (CredentialResponse, int, errs.Failure) { return resp, status, err } -// Getting the list of customers matched the specified filter +// Customers returns list of customers matched the specified filter // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers // @@ -267,7 +284,7 @@ func (c *Client) Customers(parameters CustomersRequest) (CustomersResponse, int, return resp, status, err } -// Combining of customers +// CustomersCombine combine given customers // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-combine // @@ -309,7 +326,7 @@ func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) return resp, status, err } -// Customer creation +// CustomerCreate creates customer // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-create // @@ -365,7 +382,7 @@ func (c *Client) CustomerCreate(customer Customer, site ...string) (CustomerChan return resp, status, err } -// The mass recording of customers external ID +// CustomersFixExternalIds customers external ID // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-fix-external-ids // @@ -408,7 +425,7 @@ func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (Successfu return resp, status, err } -// Getting the customer change history +// CustomersHistory returns customer's history // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers-history // @@ -452,7 +469,7 @@ func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (Customers return resp, status, err } -// Getting the notes +// CustomerNotes returns cutomer related notes // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers-notes // @@ -497,7 +514,7 @@ func (c *Client) CustomerNotes(parameters NotesRequest) (NotesResponse, int, err return resp, status, err } -// Note creation +// CustomerNoteCreate note creation // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-notes-create // @@ -549,7 +566,7 @@ func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, return resp, status, err } -// Note removing +// CustomerNoteDelete remove cusomer related note // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-notes-id-delete // @@ -558,7 +575,6 @@ func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, // var client = v5.New("https://demo.url", "09jIJ") // // data, status, err := client.CustomerNoteDelete(12) - // if err.RuntimeErr != nil { // fmt.Printf("%v", err.RuntimeErr) // } @@ -587,7 +603,7 @@ func (c *Client) CustomerNoteDelete(id int) (SuccessfulResponse, int, errs.Failu return resp, status, err } -// Packet customers uploading +// CustomersUpload customers batch upload // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-upload // @@ -648,7 +664,7 @@ func (c *Client) CustomersUpload(customers []Customer, site ...string) (Customer return resp, status, err } -// Getting information on customer +// Customer returns information about customer // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers-externalId // @@ -690,7 +706,7 @@ func (c *Client) Customer(id, by, site string) (CustomerResponse, int, errs.Fail return resp, status, err } -// Customer editing +// CustomerEdit edit exact customer // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-externalId-edit // @@ -752,7 +768,7 @@ func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (Cus return resp, status, err } -// Updating of delivery statuses +// DeliveryTracking updates tracking data // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-delivery-generic-subcode-tracking // @@ -805,7 +821,7 @@ func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode st return resp, status, err } -// Getting the list of shipments to delivery services +// DeliveryShipments returns list of shipments // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-delivery-shipments // @@ -850,7 +866,7 @@ func (c *Client) DeliveryShipments(parameters DeliveryShipmentsRequest) (Deliver return resp, status, err } -// Shipment creation +// DeliveryShipmentCreate creates shipment // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-delivery-shipments-create // @@ -1355,7 +1371,7 @@ func (c *Client) OrderPaymentCreate(payment Payment, site ...string) (CreateResp return resp, status, err } -// Payment removing +// OrderPaymentDelete payment removing // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-payments-id-delete // @@ -3928,7 +3944,7 @@ func (c *Client) CustomDictionary(code string) (CustomDictionaryResponse, int, e return resp, status, err } -// Directory fields editing +// CustomDictionaryEdit edit custom dictionary // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-custom-fields-dictionaries-code-edit // @@ -3981,7 +3997,7 @@ func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (Custom return resp, status, err } -// Custom fields creation +// CustomFieldsCreate creates custom field // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-custom-fields-entity-create // @@ -4028,7 +4044,7 @@ func (c *Client) CustomFieldsCreate(customFields CustomFields) (CustomResponse, return resp, status, err } -// Getting information on custom fields +// CustomField returns information about custom fields // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-custom-fields-entity-code // diff --git a/v5/client_test.go b/v5/client_test.go index 67341f9..768b4ba 100644 --- a/v5/client_test.go +++ b/v5/client_test.go @@ -3,6 +3,7 @@ package v5 import ( "encoding/json" "fmt" + "log" "math/rand" "net/http" "net/url" @@ -12,14 +13,30 @@ import ( "time" "github.com/h2non/gock" + "github.com/joho/godotenv" ) +func TestMain(m *testing.M) { + if os.Getenv("DEVELOPER_NODE") == "1" { + err := godotenv.Load("../.env") + if err != nil { + log.Fatal("Error loading .env file") + } + + os.Exit(m.Run()) + } +} + +func init() { + r = rand.New(rand.NewSource(time.Now().UnixNano())) +} + 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" + crmURL = os.Getenv("RETAILCRM_URL") + badURL = "https://qwertypoiu.retailcrm.ru" errFail = "FailTest: error empty" statusFail = "FailTest: status < 400" @@ -28,10 +45,6 @@ var ( iCodeFail = 123123 ) -func init() { - r = rand.New(rand.NewSource(time.Now().UnixNano())) -} - func RandomString(strlen int) string { const chars = "abcdefghijklmnopqrstuvwxyz0123456789" result := make([]byte, strlen) @@ -44,11 +57,11 @@ func RandomString(strlen int) string { } func client() *Client { - return New(crmUrl, os.Getenv("RETAILCRM_KEY")) + return New(crmURL, os.Getenv("RETAILCRM_KEY")) } func badurlclient() *Client { - return New(badUrl, os.Getenv("RETAILCRM_KEY")) + return New(badURL, os.Getenv("RETAILCRM_KEY")) } func badkeyclient() *Client { @@ -75,6 +88,7 @@ func TestPostRequest(t *testing.T) { func TestClient_ApiVersionsVersions(t *testing.T) { c := client() + c.Debug = true data, status, err := c.APIVersions() if err.RuntimeErr != nil { @@ -95,7 +109,7 @@ func TestClient_ApiVersionsVersionsBadUrl(t *testing.T) { defer gock.Off() - gock.New(badUrl). + gock.New(badURL). Get("/api/api-versions"). Reply(200). BodyString(`{"success": false, "errorMsg" : "Account does not exist"}`) @@ -117,7 +131,7 @@ func TestClient_ApiVersionsVersionsBadUrl(t *testing.T) { func TestClient_ApiCredentialsCredentialsBadKey(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/api/credentials"). Reply(403). BodyString(`{"success": false, "errorMsg": "Wrong \"apiKey\" value"}`) @@ -141,7 +155,7 @@ func TestClient_ApiCredentialsCredentialsBadKey(t *testing.T) { func TestClient_ApiCredentialsCredentials(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/api/credentials"). Reply(200). BodyString(`{"success": true}`) @@ -165,7 +179,7 @@ func TestClient_ApiCredentialsCredentials(t *testing.T) { func TestClient_CustomersCustomers(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/api/v5/customers"). MatchParam("filter[city]", "Москва"). MatchParam("page", "3"). @@ -197,7 +211,7 @@ func TestClient_CustomersCustomers(t *testing.T) { func TestClient_CustomersCustomers_Fail(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/api/v5/customers"). MatchParam("filter[ids][]", codeFail). Reply(400). @@ -248,7 +262,7 @@ func TestClient_CustomerChange(t *testing.T) { "customer": {string(str)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/api/v5/customers/create"). MatchType("url"). BodyString(p.Encode()). @@ -278,7 +292,7 @@ func TestClient_CustomerChange(t *testing.T) { "customer": {string(str)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/customers/%v/edit", cr.ID)). MatchType("url"). BodyString(p.Encode()). @@ -298,7 +312,7 @@ func TestClient_CustomerChange(t *testing.T) { t.Errorf("%v", err.ApiError()) } - gock.New(crmUrl). + gock.New(crmURL). Get(fmt.Sprintf("/api/v5/customers/%v", f.ExternalID)). MatchParam("by", "externalId"). Reply(200). @@ -333,7 +347,7 @@ func TestClient_CustomerChange_Fail(t *testing.T) { "customer": {string(str)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/api/v5/customers/create"). MatchType("url"). BodyString(p.Encode()). @@ -363,7 +377,7 @@ func TestClient_CustomerChange_Fail(t *testing.T) { "customer": {string(str)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/customers/%v/edit", cr.ID)). MatchType("url"). BodyString(p.Encode()). @@ -383,7 +397,7 @@ func TestClient_CustomerChange_Fail(t *testing.T) { t.Error(successFail) } - gock.New(crmUrl). + gock.New(crmURL). Get(fmt.Sprintf("/api/v5/customers/%v", codeFail)). MatchParam("by", "externalId"). Reply(404). @@ -424,7 +438,7 @@ func TestClient_CustomersUpload(t *testing.T) { "customers": {string(str)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/api/v5/customers/upload"). MatchType("url"). BodyString(p.Encode()). @@ -457,7 +471,7 @@ func TestClient_CustomersUpload_Fail(t *testing.T) { "customers": {string(str)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/api/v5/customers/upload"). MatchType("url"). BodyString(p.Encode()). @@ -494,7 +508,7 @@ func TestClient_CustomersCombine(t *testing.T) { "resultCustomer": {string(combineJSONOut[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/customers/combine"). MatchType("url"). BodyString(p.Encode()). @@ -531,7 +545,7 @@ func TestClient_CustomersCombine_Fail(t *testing.T) { "resultCustomer": {string(combineJSONOut[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/customers/combine"). MatchType("url"). BodyString(p.Encode()). @@ -568,7 +582,7 @@ func TestClient_CustomersFixExternalIds(t *testing.T) { "customers": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/customers/fix-external-ids"). MatchType("url"). BodyString(p.Encode()). @@ -602,7 +616,7 @@ func TestClient_CustomersFixExternalIds_Fail(t *testing.T) { "customers": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/customers/fix-external-ids"). MatchType("url"). BodyString(p.Encode()). @@ -632,7 +646,7 @@ func TestClient_CustomersHistory(t *testing.T) { } defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/customers/history"). MatchParam("filter[sinceId]", "20"). Reply(200). @@ -666,7 +680,7 @@ func TestClient_CustomersHistory_Fail(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/customers/history"). MatchParam("filter[startDate]", "2020-13-12"). Reply(400). @@ -691,7 +705,7 @@ func TestClient_NotesNotes(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/customers/notes"). MatchParam("page", "1"). Reply(200). @@ -720,7 +734,7 @@ func TestClient_NotesNotes_Fail(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/customers/notes"). MatchParam("filter[createdAtFrom]", "2020-13-12"). Reply(400). @@ -761,7 +775,7 @@ func TestClient_NotesCreateDelete(t *testing.T) { "note": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/customers/notes/create"). MatchType("url"). BodyString(p.Encode()). @@ -785,7 +799,7 @@ func TestClient_NotesCreateDelete(t *testing.T) { "id": {string(1)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/api/v5/customers/notes/%d/delete", 1)). MatchType("url"). BodyString(p.Encode()). @@ -823,7 +837,7 @@ func TestClient_NotesCreateDelete_Fail(t *testing.T) { "note": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/customers/notes/create"). MatchType("url"). BodyString(p.Encode()). @@ -847,7 +861,7 @@ func TestClient_NotesCreateDelete_Fail(t *testing.T) { "id": {string(iCodeFail)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/customers/notes/%d/delete", iCodeFail)). MatchType("url"). BodyString(p.Encode()). @@ -873,7 +887,7 @@ func TestClient_OrdersOrders(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/orders"). MatchParam("filter[city]", "Москва"). MatchParam("page", "1"). @@ -900,7 +914,7 @@ func TestClient_OrdersOrders_Fail(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/orders"). MatchParam("filter[attachments]", "7"). Reply(400). @@ -941,7 +955,7 @@ func TestClient_OrderChange(t *testing.T) { "order": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/orders/create"). MatchType("url"). BodyString(p.Encode()). @@ -971,7 +985,7 @@ func TestClient_OrderChange(t *testing.T) { "order": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/orders/%d/edit", f.ID)). MatchType("url"). BodyString(p.Encode()). @@ -991,7 +1005,7 @@ func TestClient_OrderChange(t *testing.T) { t.Errorf("%v", err.ApiError()) } - gock.New(crmUrl). + gock.New(crmURL). Get(fmt.Sprintf("/orders/%s", f.ExternalID)). MatchParam("by", "externalId"). Reply(200). @@ -1034,7 +1048,7 @@ func TestClient_OrderChange_Fail(t *testing.T) { "order": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/orders/%d/edit", f.ID)). MatchType("url"). BodyString(p.Encode()). @@ -1076,7 +1090,7 @@ func TestClient_OrdersUpload(t *testing.T) { "orders": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/orders/upload"). MatchType("url"). BodyString(p.Encode()). @@ -1118,7 +1132,7 @@ func TestClient_OrdersUpload_Fail(t *testing.T) { "orders": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/orders/upload"). MatchType("url"). BodyString(p.Encode()). @@ -1152,7 +1166,7 @@ func TestClient_OrdersCombine(t *testing.T) { "resultOrder": {string(jr2)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/orders/combine"). MatchType("url"). BodyString(p.Encode()). @@ -1186,7 +1200,7 @@ func TestClient_OrdersCombine_Fail(t *testing.T) { "resultOrder": {string(jr)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/orders/combine"). MatchType("url"). BodyString(p.Encode()). @@ -1222,7 +1236,7 @@ func TestClient_OrdersFixExternalIds(t *testing.T) { "orders": {string(jr)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/orders/fix-external-ids"). MatchType("url"). BodyString(p.Encode()). @@ -1255,7 +1269,7 @@ func TestClient_OrdersFixExternalIds_Fail(t *testing.T) { "orders": {string(jr)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/orders/fix-external-ids"). MatchType("url"). BodyString(p.Encode()). @@ -1281,7 +1295,7 @@ func TestClient_OrdersHistory(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/orders/history"). MatchParam("filter[sinceId]", "20"). Reply(200). @@ -1311,7 +1325,7 @@ func TestClient_OrdersHistory_Fail(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/orders/history"). MatchParam("filter[startDate]", "2020-13-12"). Reply(400). @@ -1349,7 +1363,7 @@ func TestClient_PaymentCreateEditDelete(t *testing.T) { "payment": {string(jr)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/orders/payments/create"). MatchType("url"). BodyString(p.Encode()). @@ -1379,7 +1393,7 @@ func TestClient_PaymentCreateEditDelete(t *testing.T) { "payment": {string(jr)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/orders/payments/%d/edit", paymentCreateResponse.ID)). MatchType("url"). BodyString(p.Encode()). @@ -1403,7 +1417,7 @@ func TestClient_PaymentCreateEditDelete(t *testing.T) { "id": {string(paymentCreateResponse.ID)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/orders/payments/%d/delete", paymentCreateResponse.ID)). MatchType("url"). BodyString(p.Encode()). @@ -1440,7 +1454,7 @@ func TestClient_PaymentCreateEditDelete_Fail(t *testing.T) { "payment": {string(jr)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/orders/payments/create"). MatchType("url"). BodyString(p.Encode()). @@ -1470,7 +1484,7 @@ func TestClient_PaymentCreateEditDelete_Fail(t *testing.T) { "payment": {string(jr)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/orders/payments/%d/edit", iCodeFail)). MatchType("url"). BodyString(p.Encode()). @@ -1494,7 +1508,7 @@ func TestClient_PaymentCreateEditDelete_Fail(t *testing.T) { "id": {string(iCodeFail)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/orders/payments/%d/delete", iCodeFail)). MatchType("url"). BodyString(p.Encode()). @@ -1526,7 +1540,7 @@ func TestClient_TasksTasks(t *testing.T) { } defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/api/v5/tasks"). MatchParam("filter[creators][]", "123"). MatchParam("page", "1"). @@ -1557,7 +1571,7 @@ func TestClient_TasksTasks_Fail(t *testing.T) { } defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/api/v5/tasks"). MatchParam("filter[creators][]", "123123"). Reply(400). @@ -1591,7 +1605,7 @@ func TestClient_TaskChange(t *testing.T) { "task": {string(jr)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/tasks/create"). MatchType("url"). BodyString(p.Encode()). @@ -1614,7 +1628,7 @@ func TestClient_TaskChange(t *testing.T) { f.ID = cr.ID f.Commentary = RandomString(20) - gock.New(crmUrl). + gock.New(crmURL). Get(fmt.Sprintf("/tasks/%d", f.ID)). Reply(200). BodyString(`{"success": true}`) @@ -1637,7 +1651,7 @@ func TestClient_TaskChange(t *testing.T) { "task": {string(jr)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/tasks/%d/edit", f.ID)). MatchType("url"). BodyString(p.Encode()). @@ -1674,7 +1688,7 @@ func TestClient_TaskChange_Fail(t *testing.T) { "task": {string(jr)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/tasks/%d/edit", f.ID)). MatchType("url"). BodyString(p.Encode()). @@ -1700,7 +1714,7 @@ func TestClient_UsersUsers(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/users"). MatchParam("filter[active]", "1"). MatchParam("page", "1"). @@ -1727,7 +1741,7 @@ func TestClient_UsersUsers_Fail(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/users"). MatchParam("filter[active]", "3"). MatchParam("page", "1"). @@ -1753,7 +1767,7 @@ func TestClient_UsersUser(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get(fmt.Sprintf("/users/%d", user)). Reply(200). BodyString(`{"success": true}`) @@ -1778,7 +1792,7 @@ func TestClient_UsersUser_Fail(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get(fmt.Sprintf("/users/%d", iCodeFail)). Reply(404). BodyString(`{"success": false, "errorMsg": "Not found"}`) @@ -1802,7 +1816,7 @@ func TestClient_UsersGroups(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/user-groups"). MatchParam("page", "1"). Reply(200). @@ -1831,7 +1845,7 @@ func TestClient_UsersUpdate(t *testing.T) { "status": {string("busy")}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/users/%d/status", user)). MatchType("url"). BodyString(p.Encode()). @@ -1862,7 +1876,7 @@ func TestClient_UsersUpdate_Fail(t *testing.T) { "status": {string("busy")}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/users/%d/status", iCodeFail)). MatchType("url"). BodyString(p.Encode()). @@ -1888,7 +1902,7 @@ func TestClient_StaticticsUpdate(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/statistic/update"). Reply(200). BodyString(`{"success": true}`) @@ -1912,7 +1926,7 @@ func TestClient_Countries(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/reference/couriers"). Reply(200). BodyString(`{"success": true}`) @@ -1936,7 +1950,7 @@ func TestClient_CostGroups(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/reference/cost-groups"). Reply(200). BodyString(`{"success": true}`) @@ -1960,7 +1974,7 @@ func TestClient_CostItems(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/reference/cost-items"). Reply(200). BodyString(`{"success": true}`) @@ -1984,7 +1998,7 @@ func TestClient_Couriers(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/reference/couriers"). Reply(200). BodyString(`{"success": true}`) @@ -2008,7 +2022,7 @@ func TestClient_DeliveryService(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/reference/delivery-services"). Reply(200). BodyString(`{"success": true}`) @@ -2032,7 +2046,7 @@ func TestClient_DeliveryTypes(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/reference/delivery-types"). Reply(200). BodyString(`{"success": true}`) @@ -2056,7 +2070,7 @@ func TestClient_LegalEntities(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/reference/legal-entities"). Reply(200). BodyString(`{"success": true}`) @@ -2080,7 +2094,7 @@ func TestClient_OrderMethods(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/reference/order-methods"). Reply(200). BodyString(`{"success": true}`) @@ -2104,7 +2118,7 @@ func TestClient_OrderTypes(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/reference/order-types"). Reply(200). BodyString(`{"success": true}`) @@ -2128,7 +2142,7 @@ func TestClient_PaymentStatuses(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/reference/payment-statuses"). Reply(200). BodyString(`{"success": true}`) @@ -2152,7 +2166,7 @@ func TestClient_PaymentTypes(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/reference/payment-types"). Reply(200). BodyString(`{"success": true}`) @@ -2176,7 +2190,7 @@ func TestClient_PriceTypes(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/reference/price-types"). Reply(200). BodyString(`{"success": true}`) @@ -2200,7 +2214,7 @@ func TestClient_ProductStatuses(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/reference/product-statuses"). Reply(200). BodyString(`{"success": true}`) @@ -2224,7 +2238,7 @@ func TestClient_Statuses(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/reference/statuses"). Reply(200). BodyString(`{"success": true}`) @@ -2248,7 +2262,7 @@ func TestClient_StatusGroups(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/reference/status-groups"). Reply(200). BodyString(`{"success": true}`) @@ -2272,7 +2286,7 @@ func TestClient_Sites(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/reference/sites"). Reply(200). BodyString(`{"success": true}`) @@ -2296,7 +2310,7 @@ func TestClient_Stores(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/reference/stores"). Reply(200). BodyString(`{"success": true}`) @@ -2335,7 +2349,7 @@ func TestClient_CostGroupItemEdit(t *testing.T) { "costGroup": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/api/v5/reference/cost-groups/%s/edit", costGroup.Code)). MatchType("url"). BodyString(p.Encode()). @@ -2370,7 +2384,7 @@ func TestClient_CostGroupItemEdit(t *testing.T) { "costItem": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/api/v5/reference/cost-items/%s/edit", costItem.Code)). MatchType("url"). BodyString(p.Encode()). @@ -2410,7 +2424,7 @@ func TestClient_CostGroupItemEdit_Fail(t *testing.T) { "costGroup": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/cost-groups/%s/edit", costGroup.Code)). MatchType("url"). BodyString(p.Encode()). @@ -2445,7 +2459,7 @@ func TestClient_CostGroupItemEdit_Fail(t *testing.T) { "costItem": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/cost-items/%s/edit", costItem.Code)). MatchType("url"). BodyString(p.Encode()). @@ -2484,7 +2498,7 @@ func TestClient_Courier(t *testing.T) { "courier": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/api/v5/reference/couriers/create"). MatchType("url"). BodyString(p.Encode()). @@ -2513,7 +2527,7 @@ func TestClient_Courier(t *testing.T) { "courier": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/couriers/%d/edit", cur.ID)). MatchType("url"). BodyString(p.Encode()). @@ -2546,7 +2560,7 @@ func TestClient_Courier_Fail(t *testing.T) { "courier": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/api/v5/reference/couriers/create"). MatchType("url"). BodyString(p.Encode()). @@ -2573,7 +2587,7 @@ func TestClient_Courier_Fail(t *testing.T) { "courier": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/couriers/%d/edit", cur.ID)). MatchType("url"). BodyString(p.Encode()). @@ -2611,7 +2625,7 @@ func TestClient_DeliveryServiceEdit(t *testing.T) { "deliveryService": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/delivery-services/%s/edit", deliveryService.Code)). MatchType("url"). BodyString(p.Encode()). @@ -2648,7 +2662,7 @@ func TestClient_DeliveryServiceEdit_Fail(t *testing.T) { "deliveryService": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/delivery-services/%s/edit", deliveryService.Code)). MatchType("url"). BodyString(p.Encode()). @@ -2691,7 +2705,7 @@ func TestClient_DeliveryTypeEdit(t *testing.T) { "deliveryType": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/delivery-types/%s/edit", deliveryType.Code)). MatchType("url"). BodyString(p.Encode()). @@ -2732,7 +2746,7 @@ func TestClient_DeliveryTypeEdit_Fail(t *testing.T) { "deliveryType": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/delivery-types/%s/edit", deliveryType.Code)). MatchType("url"). BodyString(p.Encode()). @@ -2770,7 +2784,7 @@ func TestClient_OrderMethodEdit(t *testing.T) { "orderMethod": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/order-methods/%s/edit", orderMethod.Code)). MatchType("url"). BodyString(p.Encode()). @@ -2808,7 +2822,7 @@ func TestClient_OrderMethodEdit_Fail(t *testing.T) { "orderMethod": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/order-methods/%s/edit", orderMethod.Code)). MatchType("url"). BodyString(p.Encode()). @@ -2847,7 +2861,7 @@ func TestClient_OrderTypeEdit(t *testing.T) { "orderType": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/order-types/%s/edit", orderType.Code)). MatchType("url"). BodyString(p.Encode()). @@ -2884,7 +2898,7 @@ func TestClient_OrderTypeEdit_Fail(t *testing.T) { "orderType": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/order-types/%s/edit", orderType.Code)). MatchType("url"). BodyString(p.Encode()). @@ -2925,7 +2939,7 @@ func TestClient_PaymentStatusEdit(t *testing.T) { "paymentStatus": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/payment-statuses/%s/edit", paymentStatus.Code)). MatchType("url"). BodyString(p.Encode()). @@ -2965,7 +2979,7 @@ func TestClient_PaymentStatusEdit_Fail(t *testing.T) { "paymentStatus": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/payment-statuses/%s/edit", paymentStatus.Code)). MatchType("url"). BodyString(p.Encode()). @@ -3003,7 +3017,7 @@ func TestClient_PaymentTypeEdit(t *testing.T) { "paymentType": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/payment-types/%s/edit", paymentType.Code)). MatchType("url"). BodyString(p.Encode()). @@ -3041,7 +3055,7 @@ func TestClient_PaymentTypeEdit_Fail(t *testing.T) { "paymentType": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/payment-types/%s/edit", paymentType.Code)). MatchType("url"). BodyString(p.Encode()). @@ -3078,7 +3092,7 @@ func TestClient_PriceTypeEdit(t *testing.T) { "priceType": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/price-types/%s/edit", priceType.Code)). MatchType("url"). BodyString(p.Encode()). @@ -3114,7 +3128,7 @@ func TestClient_PriceTypeEdit_Fail(t *testing.T) { "priceType": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/price-types/%s/edit", priceType.Code)). MatchType("url"). BodyString(p.Encode()). @@ -3152,7 +3166,7 @@ func TestClient_ProductStatusEdit(t *testing.T) { "productStatus": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/product-statuses/%s/edit", productStatus.Code)). MatchType("url"). BodyString(p.Encode()). @@ -3189,7 +3203,7 @@ func TestClient_ProductStatusEdit_Fail(t *testing.T) { "productStatus": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/product-statuses/%s/edit", productStatus.Code)). MatchType("url"). BodyString(p.Encode()). @@ -3227,7 +3241,7 @@ func TestClient_StatusEdit(t *testing.T) { "status": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/statuses/%s/edit", status.Code)). MatchType("url"). BodyString(p.Encode()). @@ -3266,7 +3280,7 @@ func TestClient_StatusEdit_Fail(t *testing.T) { "status": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/statuses/%s/edit", status.Code)). MatchType("url"). BodyString(p.Encode()). @@ -3304,7 +3318,7 @@ func TestClient_SiteEdit(t *testing.T) { "site": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/sites/%s/edit", site.Code)). MatchType("url"). BodyString(p.Encode()). @@ -3338,7 +3352,7 @@ func TestClient_SiteEdit_Fail(t *testing.T) { "site": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/sites/%s/edit", site.Code)). MatchType("url"). BodyString(p.Encode()). @@ -3374,7 +3388,7 @@ func TestClient_StoreEdit(t *testing.T) { "store": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/stores/%s/edit", store.Code)). MatchType("url"). BodyString(p.Encode()). @@ -3413,7 +3427,7 @@ func TestClient_StoreEdit_Fail(t *testing.T) { "store": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/reference/stores/%s/edit", store.Code)). MatchType("url"). BodyString(p.Encode()). @@ -3450,7 +3464,7 @@ func TestClient_PackChange(t *testing.T) { "pack": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/orders/packs/create"). MatchType("url"). BodyString(pr.Encode()). @@ -3470,7 +3484,7 @@ func TestClient_PackChange(t *testing.T) { t.Errorf("%v", err.ApiError()) } - gock.New(crmUrl). + gock.New(crmURL). Get(fmt.Sprintf("/orders/packs/%d", p.ID)). Reply(200). BodyString(`{"success": true}`) @@ -3494,7 +3508,7 @@ func TestClient_PackChange(t *testing.T) { "pack": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/orders/packs/%d/edit", p.ID)). MatchType("url"). BodyString(pr.Encode()). @@ -3514,7 +3528,7 @@ func TestClient_PackChange(t *testing.T) { t.Errorf("%v", err.ApiError()) } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/orders/packs/%d/delete", p.ID)). MatchType("url"). Reply(200). @@ -3551,7 +3565,7 @@ func TestClient_PackChange_Fail(t *testing.T) { "pack": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/orders/packs/create"). MatchType("url"). BodyString(pr.Encode()). @@ -3571,7 +3585,7 @@ func TestClient_PackChange_Fail(t *testing.T) { t.Error(successFail) } - gock.New(crmUrl). + gock.New(crmURL). Get(fmt.Sprintf("/orders/packs/%d", iCodeFail)). Reply(400). BodyString(`{"success": false, "errorMsg": "Errors in the entity format"}`) @@ -3595,7 +3609,7 @@ func TestClient_PackChange_Fail(t *testing.T) { "pack": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/orders/packs/%d/edit", iCodeFail)). MatchType("url"). BodyString(pr.Encode()). @@ -3615,7 +3629,7 @@ func TestClient_PackChange_Fail(t *testing.T) { t.Error(successFail) } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/orders/packs/%d/delete", iCodeFail)). MatchType("url"). Reply(400). @@ -3640,7 +3654,7 @@ func TestClient_PacksHistory(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/orders/packs/history"). MatchParam("filter[sinceId]", "5"). Reply(200). @@ -3670,7 +3684,7 @@ func TestClient_PacksHistory_Fail(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/orders/packs/history"). MatchParam("filter[startDate]", "2020-13-12"). Reply(400). @@ -3695,7 +3709,7 @@ func TestClient_Packs(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/orders/packs"). MatchParam("page", "1"). Reply(200). @@ -3721,7 +3735,7 @@ func TestClient_Packs_Fail(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/orders/packs"). MatchParam("filter[shipmentDateFrom]", "2020-13-12"). Reply(400). @@ -3746,7 +3760,7 @@ func TestClient_Inventories(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/store/inventories"). MatchParam("filter[details]", "1"). MatchParam("page", "1"). @@ -3773,7 +3787,7 @@ func TestClient_Inventories_Fail(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/store/inventories"). MatchParam("filter[sites][]", codeFail). Reply(400). @@ -3798,7 +3812,7 @@ func TestClient_Segments(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/segments"). Reply(200). BodyString(`{"success": true, "id": 1}`) @@ -3823,7 +3837,7 @@ func TestClient_Segments_Fail(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/segments"). MatchParam("filter[active]", "3"). Reply(400). @@ -3868,7 +3882,7 @@ func TestClient_IntegrationModule(t *testing.T) { "integrationModule": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/integration-modules/%s/edit", integrationModule.Code)). MatchType("url"). BodyString(pr.Encode()). @@ -3888,7 +3902,7 @@ func TestClient_IntegrationModule(t *testing.T) { t.Errorf("%v", err.ApiError()) } - gock.New(crmUrl). + gock.New(crmURL). Get(fmt.Sprintf("/integration-modules/%s", code)). Reply(200). BodyString(`{"success": true}`) @@ -3931,7 +3945,7 @@ func TestClient_IntegrationModule_Fail(t *testing.T) { "integrationModule": {string(jr[:])}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/integration-modules/%s/edit", integrationModule.Code)). MatchType("url"). BodyString(pr.Encode()). @@ -3951,7 +3965,7 @@ func TestClient_IntegrationModule_Fail(t *testing.T) { t.Error(successFail) } - gock.New(crmUrl). + gock.New(crmURL). Get(fmt.Sprintf("/integration-modules/%s", code)). Reply(400). BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) @@ -3975,7 +3989,7 @@ func TestClient_ProductsGroup(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/store/product-groups"). MatchParam("filter[active]", "1"). Reply(200). @@ -4005,7 +4019,7 @@ func TestClient_ProductsGroup_Fail(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/store/product-groups"). MatchParam("filter[active]", "3"). Reply(400). @@ -4034,7 +4048,7 @@ func TestClient_Products(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/store/products"). MatchParam("filter[active]", "1"). MatchParam("filter[minPrice]", "1"). @@ -4066,7 +4080,7 @@ func TestClient_Products_Fail(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/store/products"). MatchParam("filter[active]", "3"). Reply(400). @@ -4096,7 +4110,7 @@ func TestClient_ProductsProperties(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/store/products"). MatchParam("filter[sites][]", sites[0]). Reply(200). @@ -4125,7 +4139,7 @@ func TestClient_DeliveryShipments(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/delivery/shipments"). MatchParam("filter[dateFrom]", "2017-10-10"). Reply(200). @@ -4154,7 +4168,7 @@ func TestClient_DeliveryShipments_Fail(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/delivery/shipments"). MatchParam("filter[stores][]", codeFail). Reply(400). @@ -4196,7 +4210,7 @@ func TestClient_Cost(t *testing.T) { "cost": {string(str)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/costs/create"). MatchType("url"). BodyString(p.Encode()). @@ -4219,7 +4233,7 @@ func TestClient_Cost(t *testing.T) { id := data.ID - gock.New(crmUrl). + gock.New(crmURL). Get("/costs"). MatchParam("filter[ids][]", strconv.Itoa(id)). MatchParam("limit", "20"). @@ -4247,7 +4261,7 @@ func TestClient_Cost(t *testing.T) { t.Errorf("%v", err.ApiError()) } - gock.New(crmUrl). + gock.New(crmURL). Get(fmt.Sprintf("/costs/%d", id)). Reply(200). BodyString(`{"success": true}`) @@ -4276,7 +4290,7 @@ func TestClient_Cost(t *testing.T) { "cost": {string(str)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/costs/%d/edit", id)). MatchType("url"). BodyString(p.Encode()). @@ -4303,7 +4317,7 @@ func TestClient_Cost(t *testing.T) { "costs": {string(j)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/costs/%d/delete", id)). MatchType("url"). BodyString(p.Encode()). @@ -4343,7 +4357,7 @@ func TestClient_Cost_Fail(t *testing.T) { "cost": {string(str)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/costs/create"). MatchType("url"). BodyString(p.Encode()). @@ -4365,7 +4379,7 @@ func TestClient_Cost_Fail(t *testing.T) { id := data.ID - gock.New(crmUrl). + gock.New(crmURL). Get("/costs"). MatchParam("filter[sites][]", codeFail). Reply(400). @@ -4386,7 +4400,7 @@ func TestClient_Cost_Fail(t *testing.T) { t.Error(successFail) } - gock.New(crmUrl). + gock.New(crmURL). Get(fmt.Sprintf("/costs/%d", id)). Reply(404). BodyString(`{"success": false, "errorMsg": "Not found"}`) @@ -4415,7 +4429,7 @@ func TestClient_Cost_Fail(t *testing.T) { "cost": {string(str)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/costs/%d/edit", id)). MatchType("url"). BodyString(p.Encode()). @@ -4440,7 +4454,7 @@ func TestClient_Cost_Fail(t *testing.T) { p = url.Values{ "costs": {string(j)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/costs/%d/delete", id)). MatchType("url"). BodyString(p.Encode()). @@ -4492,7 +4506,7 @@ func TestClient_CostsUpload(t *testing.T) { "costs": {string(j)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/costs/upload"). MatchType("url"). BodyString(p.Encode()). @@ -4522,7 +4536,7 @@ func TestClient_CostsUpload(t *testing.T) { "ids": {string(j)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/costs/delete"). MatchType("url"). BodyString(p.Encode()). @@ -4567,7 +4581,7 @@ func TestClient_CostsUpload_Fail(t *testing.T) { "costs": {string(j)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/costs/upload"). MatchType("url"). BodyString(p.Encode()). @@ -4595,7 +4609,7 @@ func TestClient_CostsUpload_Fail(t *testing.T) { "ids": {string(j)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/costs/delete"). MatchType("url"). BodyString(p.Encode()). @@ -4621,7 +4635,7 @@ func TestClient_CustomFields(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/custom-fields"). Reply(200). BodyString(`{"success": true}`) @@ -4646,7 +4660,7 @@ func TestClient_CustomFields_Fail(t *testing.T) { defer gock.Off() - gock.New(crmUrl). + gock.New(crmURL). Get("/custom-fields"). MatchParam("filter[type]", codeFail). Reply(400). @@ -4690,7 +4704,7 @@ func TestClient_CustomDictionariesCreate(t *testing.T) { "customDictionary": {string(j)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/custom-fields/dictionaries/create"). MatchType("url"). BodyString(p.Encode()). @@ -4711,7 +4725,7 @@ func TestClient_CustomDictionariesCreate(t *testing.T) { t.Errorf("%v", err.ApiError()) } - gock.New(crmUrl). + gock.New(crmURL). Get("/custom-fields/dictionaries"). MatchParam("filter[name]", "test"). MatchParam("limit", "10"). @@ -4740,7 +4754,7 @@ func TestClient_CustomDictionariesCreate(t *testing.T) { t.Errorf("%v", err.ApiError()) } - gock.New(crmUrl). + gock.New(crmURL). Get(fmt.Sprintf("/custom-fields/dictionaries/%s", code)). Reply(200). BodyString(`{"success": true}`) @@ -4769,7 +4783,7 @@ func TestClient_CustomDictionariesCreate(t *testing.T) { "customDictionary": {string(j)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/custom-fields/dictionaries/%s/edit", customDictionary.Code)). MatchType("url"). BodyString(p.Encode()). @@ -4813,7 +4827,7 @@ func TestClient_CustomDictionariesCreate_Fail(t *testing.T) { "customDictionary": {string(j)}, } - gock.New(crmUrl). + gock.New(crmURL). Post("/custom-fields/dictionaries/create"). MatchType("url"). BodyString(p.Encode()). @@ -4829,7 +4843,7 @@ func TestClient_CustomDictionariesCreate_Fail(t *testing.T) { t.Error(successFail) } - gock.New(crmUrl). + gock.New(crmURL). Get(fmt.Sprintf("/custom-fields/dictionaries/%s", codeFail)). Reply(404). BodyString(`{"success": false, "errorMsg": "Not found"}`) @@ -4856,7 +4870,7 @@ func TestClient_CustomDictionariesCreate_Fail(t *testing.T) { "customDictionary": {string(j)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/custom-fields/dictionaries/%s/edit", customDictionary.Code)). MatchType("url"). BodyString(p.Encode()). @@ -4897,7 +4911,7 @@ func TestClient_CustomFieldsCreate(t *testing.T) { "customField": {string(j)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/custom-fields/%s/create", customFields.Entity)). MatchType("url"). BodyString(p.Encode()). @@ -4919,7 +4933,7 @@ func TestClient_CustomFieldsCreate(t *testing.T) { t.Errorf("%v", err.ApiError()) } - gock.New(crmUrl). + gock.New(crmURL). Get(fmt.Sprintf("/custom-fields/%s/%s", "order", codeCustomField)). Reply(200). BodyString(`{"success": true}`) @@ -4946,7 +4960,7 @@ func TestClient_CustomFieldsCreate(t *testing.T) { "customField": {string(j)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/custom-fields/%s/%s/edit", customFields.Entity, customFields.Code)). MatchType("url"). BodyString(p.Encode()). @@ -4988,7 +5002,7 @@ func TestClient_CustomFieldsCreate_Fail(t *testing.T) { "customField": {string(j)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/custom-fields/%s/create", customFields.Entity)). MatchType("url"). BodyString(p.Encode()). @@ -5008,7 +5022,7 @@ func TestClient_CustomFieldsCreate_Fail(t *testing.T) { t.Error(successFail) } - gock.New(crmUrl). + gock.New(crmURL). Get(fmt.Sprintf("/custom-fields/%s/%s", "order", codeCustomField)). Reply(404). BodyString(`{"success": false, "errorMsg": "Not found"}`) @@ -5034,7 +5048,7 @@ func TestClient_CustomFieldsCreate_Fail(t *testing.T) { "customField": {string(j)}, } - gock.New(crmUrl). + gock.New(crmURL). Post(fmt.Sprintf("/custom-fields/%s/%s/edit", customFields.Entity, customFields.Code)). MatchType("url"). BodyString(p.Encode()). diff --git a/v5/types.go b/v5/types.go index e42ef11..4029dff 100644 --- a/v5/types.go +++ b/v5/types.go @@ -6,6 +6,7 @@ import "net/http" type Client struct { URL string Key string + Debug bool httpClient *http.Client } @@ -874,6 +875,7 @@ type MgTransport struct { WebhookUrl string `json:"webhookUrl,omitempty"` } +//MgBot type type MgBot struct{} /** @@ -930,14 +932,14 @@ type CustomFields struct { CustomeDictionaries related types */ -// customDictionary type +// CustomDictionary type type CustomDictionary struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` Elements []Element `json:"elements,omitempty,brackets"` } -// Dictionary Element type +// Element type type Element struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` From d5770c7514a93392b4a3f5eed0f34a7f926588b7 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Fri, 28 Sep 2018 13:46:09 +0300 Subject: [PATCH 2/2] minor refactoring --- v5/client.go | 216 +++++++++++++++++++++++----------------------- v5/client_test.go | 10 +-- v5/request.go | 2 +- v5/response.go | 4 +- v5/types.go | 4 +- 5 files changed, 120 insertions(+), 116 deletions(-) diff --git a/v5/client.go b/v5/client.go index e946b11..95f7850 100644 --- a/v5/client.go +++ b/v5/client.go @@ -27,7 +27,7 @@ func New(url string, key string) *Client { // GetRequest implements GET Request func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte, int, errs.Failure) { var res []byte - var cerr errs.Failure + var failure errs.Failure var prefix = "/api/v5" if len(versioned) > 0 { @@ -40,8 +40,8 @@ func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte req, err := http.NewRequest("GET", fmt.Sprintf("%s%s%s", c.URL, prefix, urlWithParameters), nil) if err != nil { - cerr.RuntimeErr = err - return res, 0, cerr + failure.RuntimeErr = err + return res, 0, failure } req.Header.Set("X-API-KEY", c.Key) @@ -52,37 +52,37 @@ func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte resp, err := c.httpClient.Do(req) if err != nil { - cerr.RuntimeErr = err - return res, 0, cerr + failure.RuntimeErr = err + return res, 0, failure } if resp.StatusCode >= http.StatusInternalServerError { - cerr.ApiErr = fmt.Sprintf("HTTP request error. Status code: %d.\n", resp.StatusCode) - return res, resp.StatusCode, cerr + failure.ApiErr = fmt.Sprintf("HTTP request error. Status code: %d.\n", resp.StatusCode) + return res, resp.StatusCode, failure } res, err = buildRawResponse(resp) if err != nil { - cerr.RuntimeErr = err + failure.RuntimeErr = err } if c.Debug { log.Printf("API Response: %s", res) } - return res, resp.StatusCode, cerr + return res, resp.StatusCode, failure } // PostRequest implements POST Request func (c *Client) PostRequest(url string, postParams url.Values) ([]byte, int, errs.Failure) { var res []byte - var cerr errs.Failure + var failure errs.Failure var prefix = "/api/v5" req, err := http.NewRequest("POST", fmt.Sprintf("%s%s%s", c.URL, prefix, url), strings.NewReader(postParams.Encode())) if err != nil { - cerr.RuntimeErr = err - return res, 0, cerr + failure.RuntimeErr = err + return res, 0, failure } req.Header.Set("Content-Type", "application/x-www-form-urlencoded") @@ -94,26 +94,26 @@ func (c *Client) PostRequest(url string, postParams url.Values) ([]byte, int, er resp, err := c.httpClient.Do(req) if err != nil { - cerr.RuntimeErr = err - return res, 0, cerr + failure.RuntimeErr = err + return res, 0, failure } if resp.StatusCode >= http.StatusInternalServerError { - cerr.ApiErr = fmt.Sprintf("HTTP request error. Status code: %d.\n", resp.StatusCode) - return res, resp.StatusCode, cerr + failure.ApiErr = fmt.Sprintf("HTTP request error. Status code: %d.\n", resp.StatusCode) + return res, resp.StatusCode, failure } res, err = buildRawResponse(resp) if err != nil { - cerr.RuntimeErr = err - return res, 0, cerr + failure.RuntimeErr = err + return res, 0, failure } if c.Debug { log.Printf("API Response: %s", res) } - return res, resp.StatusCode, cerr + return res, resp.StatusCode, failure } func buildRawResponse(resp *http.Response) ([]byte, error) { @@ -130,12 +130,12 @@ func buildRawResponse(resp *http.Response) ([]byte, error) { func buildErr(data []byte) errs.Failure { var err = errs.Failure{} - eresp, errr := errs.ErrorResponse(data) - err.RuntimeErr = errr - err.ApiErr = eresp.ErrorMsg + resp, e := errs.ErrorResponse(data) + err.RuntimeErr = e + err.ApiErr = resp.ErrorMsg - if eresp.Errors != nil { - err.ApiErrs = eresp.Errors + if resp.Errors != nil { + err.ApiErrs = resp.Errors } return err @@ -469,7 +469,7 @@ func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (Customers return resp, status, err } -// CustomerNotes returns cutomer related notes +// CustomerNotes returns customer related notes // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers-notes // @@ -566,7 +566,7 @@ func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, return resp, status, err } -// CustomerNoteDelete remove cusomer related note +// CustomerNoteDelete remove customer related note // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-notes-id-delete // @@ -922,7 +922,7 @@ func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType return resp, status, err } -// Getting information on shipment +// DeliveryShipment get information about shipment // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-delivery-shipments-id // @@ -960,7 +960,7 @@ func (c *Client) DeliveryShipment(id int) (DeliveryShipmentResponse, int, errs.F return resp, status, err } -// Shipment editing +// DeliveryShipmentEdit shipment editing // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-delivery-shipments-id-edit // @@ -1007,7 +1007,7 @@ func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) return resp, status, err } -// Getting the integration module +// IntegrationModule returns integration module // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-integration-modules-code // @@ -1045,7 +1045,7 @@ func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int, return resp, status, err } -// Integration module creation/editing +// IntegrationModuleEdit integration module create/edit // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-integration-modules-code // @@ -1098,7 +1098,7 @@ func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (Int return resp, status, err } -// Getting the list of orders matched the specified filter +// Orders returns list of orders matched the specified filters // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders // @@ -1138,7 +1138,7 @@ func (c *Client) Orders(parameters OrdersRequest) (OrdersResponse, int, errs.Fai return resp, status, err } -// Combining of orders +// OrdersCombine combines given orders // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-combine // @@ -1181,7 +1181,7 @@ func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (Oper return resp, status, err } -// Order creation +// OrderCreate creates an order // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-create // @@ -1232,7 +1232,7 @@ func (c *Client) OrderCreate(order Order, site ...string) (CreateResponse, int, return resp, status, err } -// The mass recording of orders external ID +// OrdersFixExternalIds set order external ID // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-fix-external-ids // @@ -1279,7 +1279,7 @@ func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulRespo return resp, status, err } -// Getting the order change history +// OrdersHistory returns orders history // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-history // @@ -1319,7 +1319,7 @@ func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (CustomersHistor return resp, status, err } -// Payment creation +// OrderPaymentCreate creates payment // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-payments-create // @@ -1409,7 +1409,7 @@ func (c *Client) OrderPaymentDelete(id int) (SuccessfulResponse, int, errs.Failu return resp, status, err } -// Payment editing +// OrderPaymentEdit edit payment // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-payments-id-edit // @@ -1463,7 +1463,7 @@ func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (S return resp, status, err } -// Packet orders uploading +// OrdersUpload batch orders uploading // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-upload // @@ -1524,7 +1524,7 @@ func (c *Client) OrdersUpload(orders []Order, site ...string) (OrdersUploadRespo return resp, status, err } -// Getting information on order +// Order returns information about order // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-externalId // @@ -1566,7 +1566,7 @@ func (c *Client) Order(id, by, site string) (OrderResponse, int, errs.Failure) { return resp, status, err } -// Order editing +// OrderEdit edit an order // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-externalId-edit // @@ -1621,7 +1621,7 @@ func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateRespon return resp, status, err } -// Getting the list of packs matched the specified filter +// Packs returns list of packs matched the specified filters // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-packs // @@ -1661,7 +1661,7 @@ func (c *Client) Packs(parameters PacksRequest) (PacksResponse, int, errs.Failur return resp, status, err } -// Pack creation +// PackCreate creates a pack // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-packs-create // @@ -1708,7 +1708,7 @@ func (c *Client) PackCreate(pack Pack) (CreateResponse, int, errs.Failure) { return resp, status, err } -// Getting the history of order packing +// PacksHistory returns a history of order packing // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-packs-history // @@ -1748,6 +1748,7 @@ func (c *Client) PacksHistory(parameters PacksHistoryRequest) (PacksHistoryRespo return resp, status, err } +// Pack returns a pack info // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-packs-id // @@ -1785,7 +1786,7 @@ func (c *Client) Pack(id int) (PackResponse, int, errs.Failure) { return resp, status, err } -// Pack removing +// PackDelete removes a pack // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-packs-id-delete // @@ -1819,7 +1820,7 @@ func (c *Client) PackDelete(id int) (SuccessfulResponse, int, errs.Failure) { return resp, status, err } -// Pack editing +// PackEdit edit a pack // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-packs-id-edit // @@ -1859,7 +1860,7 @@ func (c *Client) PackEdit(pack Pack) (CreateResponse, int, errs.Failure) { return resp, status, err } -// Getting the list of available country codes +// Countries returns 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) { @@ -1879,7 +1880,7 @@ func (c *Client) Countries() (CountriesResponse, int, errs.Failure) { return resp, status, err } -// Getting of the costs groups list +// CostGroups returns 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) { @@ -1899,7 +1900,7 @@ func (c *Client) CostGroups() (CostGroupsResponse, int, errs.Failure) { return resp, status, err } -// Editing costs groups +// CostGroupEdit edit costs groups // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-cost-groups-code-edit // @@ -1942,7 +1943,7 @@ func (c *Client) CostGroupEdit(costGroup CostGroup) (SuccessfulResponse, int, er return resp, status, err } -// Getting of the costs items list +// CostItems returns 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) { @@ -1962,7 +1963,7 @@ func (c *Client) CostItems() (CostItemsResponse, int, errs.Failure) { return resp, status, err } -// Editing costs items +// CostItemEdit edit costs items // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-cost-items-code-edit // @@ -2005,7 +2006,7 @@ func (c *Client) CostItemEdit(costItem CostItem) (SuccessfulResponse, int, errs. return resp, status, err } -// Getting the list of couriers +// Couriers returns 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) { @@ -2025,7 +2026,7 @@ func (c *Client) Couriers() (CouriersResponse, int, errs.Failure) { return resp, status, err } -// Courier creation +// CourierCreate creates a courier // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-couriers // @@ -2074,7 +2075,7 @@ func (c *Client) CourierCreate(courier Courier) (CreateResponse, int, errs.Failu return resp, status, err } -// Courier editing +// CourierEdit edit a courier // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-couriers-id-edit // @@ -2117,7 +2118,7 @@ func (c *Client) CourierEdit(courier Courier) (SuccessfulResponse, int, errs.Fai return resp, status, err } -// Getting the list of delivery services +// DeliveryServices returns 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) { @@ -2137,7 +2138,7 @@ func (c *Client) DeliveryServices() (DeliveryServiceResponse, int, errs.Failure) return resp, status, err } -// Delivery service creation/editing +// DeliveryServiceEdit delivery service create/edit // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-delivery-services-code-edit // @@ -2180,7 +2181,7 @@ func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (Successfu return resp, status, err } -// Getting the list of delivery types +// DeliveryTypes returns 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) { @@ -2200,7 +2201,7 @@ func (c *Client) DeliveryTypes() (DeliveryTypesResponse, int, errs.Failure) { return resp, status, err } -// Delivery type creation/editing +// DeliveryTypeEdit delivery type create/edit // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-delivery-types-code-edit // @@ -2245,7 +2246,7 @@ func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (SuccessfulResponse return resp, status, err } -// Getting the list of legal entities +// LegalEntities returns 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) { @@ -2265,7 +2266,7 @@ func (c *Client) LegalEntities() (LegalEntitiesResponse, int, errs.Failure) { return resp, status, err } -// Editing of information on legal entity +// LegalEntityEdit change information about legal entity // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-legal-entities-code-edit // @@ -2308,7 +2309,7 @@ func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (SuccessfulResponse, i return resp, status, err } -// Getting the list of order methods +// OrderMethods returns 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) { @@ -2328,7 +2329,7 @@ func (c *Client) OrderMethods() (OrderMethodsResponse, int, errs.Failure) { return resp, status, err } -// Order method creation/editing +// OrderMethodEdit order method create/edit // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-order-methods-code-edit // @@ -2372,7 +2373,7 @@ func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (SuccessfulResponse, i return resp, status, err } -// Getting the list of order types +// OrderTypes return 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) { @@ -2392,6 +2393,7 @@ func (c *Client) OrderTypes() (OrderTypesResponse, int, errs.Failure) { return resp, status, err } +// OrderTypeEdit create/edit order type // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-order-methods-code-edit // @@ -2435,7 +2437,7 @@ func (c *Client) OrderTypeEdit(orderType OrderType) (SuccessfulResponse, int, er return resp, status, err } -// Getting the list of payment statuses +// PaymentStatuses returns 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) { @@ -2455,7 +2457,7 @@ func (c *Client) PaymentStatuses() (PaymentStatusesResponse, int, errs.Failure) return resp, status, err } -// Payment status creation/editing +// PaymentStatusEdit 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) { @@ -2481,7 +2483,7 @@ func (c *Client) PaymentStatusEdit(paymentStatus PaymentStatus) (SuccessfulRespo return resp, status, err } -// Getting the list of payment types +// PaymentTypes returns 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) { @@ -2501,7 +2503,7 @@ func (c *Client) PaymentTypes() (PaymentTypesResponse, int, errs.Failure) { return resp, status, err } -// Payment type creation/editing +// PaymentTypeEdit payment type create/edit // // 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) { @@ -2527,7 +2529,7 @@ func (c *Client) PaymentTypeEdit(paymentType PaymentType) (SuccessfulResponse, i return resp, status, err } -// Getting the list of price types +// PriceTypes returns 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) { @@ -2547,7 +2549,7 @@ func (c *Client) PriceTypes() (PriceTypesResponse, int, errs.Failure) { return resp, status, err } -// Price type creation/editing +// PriceTypeEdit price type create/edit // // 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) { @@ -2573,7 +2575,7 @@ func (c *Client) PriceTypeEdit(priceType PriceType) (SuccessfulResponse, int, er return resp, status, err } -// Getting the list of item statuses in order +// ProductStatuses returns 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) { @@ -2593,7 +2595,7 @@ func (c *Client) ProductStatuses() (ProductStatusesResponse, int, errs.Failure) return resp, status, err } -// Item status creation/editing +// ProductStatusEdit order item status create/edit // // 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) { @@ -2619,7 +2621,7 @@ func (c *Client) ProductStatusEdit(productStatus ProductStatus) (SuccessfulRespo return resp, status, err } -// Getting the stores list +// Sites returns the sites 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) { @@ -2639,7 +2641,7 @@ func (c *Client) Sites() (SitesResponse, int, errs.Failure) { return resp, status, err } -// Store creation/editing +// SiteEdit site create/edit // // 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) { @@ -2665,7 +2667,7 @@ func (c *Client) SiteEdit(site Site) (SuccessfulResponse, int, errs.Failure) { return resp, status, err } -// Getting the list of order status groups +// StatusGroups returns 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) { @@ -2685,7 +2687,7 @@ func (c *Client) StatusGroups() (StatusGroupsResponse, int, errs.Failure) { return resp, status, err } -// Getting the list of order statuses +// Statuses returns 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) { @@ -2705,7 +2707,7 @@ func (c *Client) Statuses() (StatusesResponse, int, errs.Failure) { return resp, status, err } -// Order status creation/editing +// StatusEdit order status create/edit // // 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) { @@ -2731,7 +2733,7 @@ func (c *Client) StatusEdit(st Status) (SuccessfulResponse, int, errs.Failure) { return resp, status, err } -// Getting the list of warehouses +// Stores returns 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) { @@ -2751,7 +2753,7 @@ func (c *Client) Stores() (StoresResponse, int, errs.Failure) { return resp, status, err } -// Editing of information on warehouse +// StoreEdit warehouse create/edit // // 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) { @@ -2777,7 +2779,7 @@ func (c *Client) StoreEdit(store Store) (SuccessfulResponse, int, errs.Failure) return resp, status, err } -// Get segments +// Segments returns segments // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-segments // @@ -2821,7 +2823,7 @@ func (c *Client) Segments(parameters SegmentsRequest) (SegmentsResponse, int, er return resp, status, err } -// Getting the leftover stocks and purchasing prices +// Inventories returns leftover stocks and purchasing prices // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-store-inventories // @@ -2861,7 +2863,7 @@ func (c *Client) Inventories(parameters InventoriesRequest) (InventoriesResponse return resp, status, err } -// Updating the leftover stocks and purchasing prices +// InventoriesUpload updates the leftover stocks and purchasing prices // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-store-inventories-upload // @@ -2869,10 +2871,10 @@ func (c *Client) Inventories(parameters InventoriesRequest) (InventoriesResponse // // var client = v5.New("https://demo.url", "09jIJ") // -// data, status, err := clientc.InventoriesUpload( +// data, status, err := client.InventoriesUpload( // []v5.InventoryUpload{ // { -// XMLID: "pTKIKAeghYzX21HTdzFCe1", +// XMLID: "pT22K9YzX21HTdzFCe1", // Stores: []InventoryUploadStore{ // {Code: "test-store-v5", Available: 10, PurchasePrice: 1500}, // {Code: "test-store-v4", Available: 20, PurchasePrice: 1530}, @@ -2880,7 +2882,7 @@ func (c *Client) Inventories(parameters InventoriesRequest) (InventoriesResponse // }, // }, // { -// XMLID: "JQIvcrCtiSpOV3AAfMiQB3", +// XMLID: "JQICtiSpOV3AAfMiQB3", // Stores: []InventoryUploadStore{ // {Code: "test-store-v5", Available: 45, PurchasePrice: 1500}, // {Code: "test-store-v4", Available: 32, PurchasePrice: 1530}, @@ -2924,7 +2926,7 @@ func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string return resp, status, err } -// Offers prices updating +// PricesUpload updates prices // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-store-prices-upload // @@ -2977,7 +2979,7 @@ func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, i return resp, status, err } -// Getting the list of product groups +// ProductsGroup returns list of product groups // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-store-product-groups // @@ -3021,7 +3023,7 @@ func (c *Client) ProductsGroup(parameters ProductsGroupsRequest) (ProductsGroups return resp, status, err } -// Getting the list of products and SKU +// Products returns list of products and SKU // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-store-products // @@ -3066,7 +3068,7 @@ func (c *Client) Products(parameters ProductsRequest) (ProductsResponse, int, er return resp, status, err } -// Getting the list of item properties, matching the specified filter +// ProductsProperties returns list of item properties, matching the specified filters // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-store-products-properties // @@ -3110,7 +3112,7 @@ func (c *Client) ProductsProperties(parameters ProductsPropertiesRequest) (Produ return resp, status, err } -// Getting the task list +// Tasks returns task list // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-tasks // @@ -3154,7 +3156,7 @@ func (c *Client) Tasks(parameters TasksRequest) (TasksResponse, int, errs.Failur return resp, status, err } -// Task creation +// TaskCreate create a task // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-tasks-create // @@ -3202,7 +3204,7 @@ func (c *Client) TaskCreate(task Task, site ...string) (CreateResponse, int, err return resp, status, err } -// Getting information on task +// Task returns task // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-tasks-id // @@ -3240,7 +3242,7 @@ func (c *Client) Task(id int) (TaskResponse, int, errs.Failure) { return resp, status, err } -// Task editing +// TaskEdit edit a task // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-tasks-id-edit // @@ -3286,7 +3288,7 @@ func (c *Client) TaskEdit(task Task, site ...string) (SuccessfulResponse, int, e return resp, status, err } -// Getting the list of user groups +// UserGroups returns list of user groups // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-user-groups // @@ -3326,7 +3328,7 @@ func (c *Client) UserGroups(parameters UserGroupsRequest) (UserGroupsResponse, i return resp, status, err } -// Getting the list of users matched the specified filter +// Users returns list of users matched the specified filters // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-users // @@ -3366,7 +3368,7 @@ func (c *Client) Users(parameters UsersRequest) (UsersResponse, int, errs.Failur return resp, status, err } -// Getting information on user +// User returns information about user // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-users-id // @@ -3404,7 +3406,7 @@ func (c *Client) User(id int) (UserResponse, int, errs.Failure) { return resp, status, err } -// Change user status +// UserStatus change user status // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-users // @@ -3442,7 +3444,7 @@ func (c *Client) UserStatus(id int, status string) (SuccessfulResponse, int, err return resp, st, err } -// Statistics updating +// StaticticsUpdate updates statistics // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-statistic-update func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, errs.Failure) { @@ -3462,7 +3464,7 @@ func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, errs.Failure) { return resp, status, err } -// Getting of the cost list, adequate for the given filter +// Costs returns costs list // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-costs // @@ -3504,7 +3506,7 @@ func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, errs.Failure) { return resp, status, err } -// Creation of the cost +// CostCreate create an cost // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-create // @@ -3558,7 +3560,7 @@ func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, in return resp, status, err } -// Cost removing +// CostsDelete removes a cost // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-delete // @@ -3598,7 +3600,7 @@ func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, errs.Failure) return resp, status, err } -// Batch loading of costs +// CostsUpload batch costs upload // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-upload // @@ -3655,7 +3657,7 @@ func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, errs. return resp, status, err } -// Getting of cost information +// Cost returns information about specified cost // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-costs-id // @@ -3690,7 +3692,7 @@ func (c *Client) Cost(id int) (CostResponse, int, errs.Failure) { return resp, status, err } -// Cost removing +// CostDelete removes cost // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-id-delete // @@ -3727,7 +3729,7 @@ func (c *Client) CostDelete(id int) (SuccessfulResponse, int, errs.Failure) { return resp, status, err } -// Cost editing +// CostEdit edit a cost // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-id-edit // @@ -3774,7 +3776,7 @@ func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateRespon return resp, status, err } -// Getting the list of custom fields +// CustomFields returns list of custom fields // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-custom-fields // @@ -3814,7 +3816,7 @@ func (c *Client) CustomFields(customFields CustomFieldsRequest) (CustomFieldsRes return resp, status, err } -// Getting the list of custom directory +// CustomDictionaries returns list of custom directory // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-custom-fields-dictionaries // @@ -3855,7 +3857,7 @@ func (c *Client) CustomDictionaries(customDictionaries CustomDictionariesRequest return resp, status, err } -// Directory fields creation +// CustomDictionariesCreate creates a custom dictionary // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-custom-fields-dictionaries-create // @@ -3909,7 +3911,7 @@ func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (Cu return resp, status, err } -// Getting information on directory +// CustomDictionary returns information about dictionary // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-custom-fields-entity-code // diff --git a/v5/client_test.go b/v5/client_test.go index 768b4ba..fbb4f37 100644 --- a/v5/client_test.go +++ b/v5/client_test.go @@ -38,7 +38,6 @@ var ( 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" @@ -57,7 +56,9 @@ func RandomString(strlen int) string { } func client() *Client { - return New(crmURL, os.Getenv("RETAILCRM_KEY")) + c := New(crmURL, os.Getenv("RETAILCRM_KEY")) + c.Debug = true + return c } func badurlclient() *Client { @@ -88,7 +89,6 @@ func TestPostRequest(t *testing.T) { func TestClient_ApiVersionsVersions(t *testing.T) { c := client() - c.Debug = true data, status, err := c.APIVersions() if err.RuntimeErr != nil { @@ -918,7 +918,7 @@ func TestClient_OrdersOrders_Fail(t *testing.T) { 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."}}`) + BodyString(`{"success": false, "errorMsg": "Errors in the input parameters", "errors": {"children[attachments]": "SThis value is not valid."}}`) data, status, err := c.Orders(OrdersRequest{Filter: OrdersFilter{Attachments: 7}}) if err.RuntimeErr != nil { @@ -1693,7 +1693,7 @@ func TestClient_TaskChange_Fail(t *testing.T) { MatchType("url"). BodyString(p.Encode()). Reply(400). - BodyString(`{"success": false, "errorMsg": "Task is not loade", "errors": {"performerId": "This value should not be blank."}}`) + BodyString(`{"success": false, "errorMsg": "Task is not loaded", "errors": {"performerId": "This value should not be blank."}}`) data, status, err := c.TaskEdit(f) if err.RuntimeErr != nil { diff --git a/v5/request.go b/v5/request.go index 1f580f1..6f53f07 100644 --- a/v5/request.go +++ b/v5/request.go @@ -157,7 +157,7 @@ type CustomFieldsRequest struct { Page int `url:"page,omitempty"` } -// CustomeDictionariesRequest type +// CustomDictionariesRequest type type CustomDictionariesRequest struct { Filter CustomDictionariesFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` diff --git a/v5/response.go b/v5/response.go index 50cec63..e68c0cd 100644 --- a/v5/response.go +++ b/v5/response.go @@ -329,11 +329,13 @@ type IntegrationModuleEditResponse struct { Info ResponseInfo `json:"info,omitempty,brackets"` } +// ResponseInfo type type ResponseInfo struct { MgTransportInfo MgInfo `json:"mgTransport,omitempty,brackets"` MgBotInfo MgInfo `json:"mgBot,omitempty,brackets"` } +// MgInfo type type MgInfo struct { EndpointUrl string `json:"endpointUrl"` Token string `json:"token"` @@ -379,7 +381,7 @@ type CustomDictionariesResponse struct { CustomDictionaries *[]CustomDictionary `json:"customDictionaries,omitempty,brackets"` } -// CustomDictionariesResponse type +// CustomResponse type type CustomResponse struct { Success bool `json:"success"` Code string `json:"code,omitempty"` diff --git a/v5/types.go b/v5/types.go index 4029dff..3fc6cab 100644 --- a/v5/types.go +++ b/v5/types.go @@ -875,7 +875,7 @@ type MgTransport struct { WebhookUrl string `json:"webhookUrl,omitempty"` } -//MgBot type +// MgBot type type MgBot struct{} /** @@ -929,7 +929,7 @@ type CustomFields struct { } /** -CustomeDictionaries related types +CustomDictionaries related types */ // CustomDictionary type