diff --git a/errs/error.go b/errs/error.go deleted file mode 100644 index f6a6bfb..0000000 --- a/errs/error.go +++ /dev/null @@ -1,75 +0,0 @@ -package errs - -import ( - "encoding/json" - "fmt" - "strconv" -) - -// Error returns the string representation of the error and satisfies the error interface. -func (f *Failure) Error() string { - if f != nil && f.runtimeErr != nil { - return f.runtimeErr.Error() - } - - return "" -} - -// ApiError returns formatted string representation of the API error -func (f *Failure) ApiError() string { - if f != nil && f.apiErr != "" { - return fmt.Sprintf("%+v", f.apiErr) - } - - return "" -} - -// ApiErrors returns array of formatted strings that represents API errors -func (f *Failure) ApiErrors() map[string]string { - if len(f.apiErrs) > 0 { - return f.apiErrs - } - - return nil -} - -// SetRuntimeError set runtime error value -func (f *Failure) SetRuntimeError(e error) { - f.runtimeErr = e -} - -// SetApiError set api error value -func (f *Failure) SetApiError(e string) { - f.apiErr = e -} - -// SetApiErrors set api errors value -func (f *Failure) SetApiErrors(e map[string]string) { - f.apiErrs = e -} - -// ErrorsHandler returns map -func ErrorsHandler(errs interface{}) map[string]string { - m := make(map[string]string) - - switch errs.(type) { - case map[string]interface{}: - for idx, val := range errs.(map[string]interface{}) { - m[idx] = val.(string) - } - case []interface{}: - for idx, val := range errs.([]interface{}) { - m[strconv.Itoa(idx)] = val.(string) - } - } - - return m -} - -// ErrorResponse method -func ErrorResponse(data []byte) (FailureResponse, error) { - var resp FailureResponse - err := json.Unmarshal(data, &resp) - - return resp, err -} diff --git a/errs/error_test.go b/errs/error_test.go deleted file mode 100644 index 20d38d0..0000000 --- a/errs/error_test.go +++ /dev/null @@ -1,50 +0,0 @@ -package errs - -import ( - "reflect" - "testing" -) - -func TestFailure_ApiErrorsSlice(t *testing.T) { - var err = Failure{} - b := []byte(`{"success": false, "errorMsg": "Failed to activate module", "errors": ["Your account has insufficient funds to activate integration module"]}`) - expected := map[string]string{ - "0": "Your account has insufficient funds to activate integration module", - } - - resp, e := ErrorResponse(b) - err.SetRuntimeError(e) - err.SetApiError(resp.ErrorMsg) - - if resp.Errors != nil { - err.SetApiErrors(ErrorsHandler(resp.Errors)) - } - - eq := reflect.DeepEqual(expected, err.ApiErrors()) - - if eq != true { - t.Errorf("%+v", eq) - } -} - -func TestFailure_ApiErrorsMap(t *testing.T) { - var err = Failure{} - b := []byte(`{"success": false, "errorMsg": "Failed to activate module", "errors": {"id": "ID must be an integer"}}`) - expected := map[string]string{ - "id": "ID must be an integer", - } - - resp, e := ErrorResponse(b) - err.SetRuntimeError(e) - err.SetApiError(resp.ErrorMsg) - - if resp.Errors != nil { - err.SetApiErrors(ErrorsHandler(resp.Errors)) - } - - eq := reflect.DeepEqual(expected, err.ApiErrors()) - - if eq != true { - t.Errorf("%+v", eq) - } -} diff --git a/errs/interfaces.go b/errs/interfaces.go deleted file mode 100644 index 371eec4..0000000 --- a/errs/interfaces.go +++ /dev/null @@ -1,8 +0,0 @@ -package errs - -// Error implements generic error interface -type Error interface { - error - ApiError() string - ApiErrors() map[string]string -} diff --git a/errs/types.go b/errs/types.go deleted file mode 100644 index 5af2e43..0000000 --- a/errs/types.go +++ /dev/null @@ -1,14 +0,0 @@ -package errs - -// Failure struct implode runtime & api errors -type Failure struct { - runtimeErr error - apiErr string - apiErrs map[string]string -} - -// FailureResponse convert json error response into object -type FailureResponse struct { - ErrorMsg string `json:"errorMsg,omitempty"` - Errors interface{} `json:"errors,omitempty"` -} diff --git a/go.mod b/go.mod index 2c5d926..186f5f0 100644 --- a/go.mod +++ b/go.mod @@ -5,5 +5,6 @@ go 1.13 require ( github.com/google/go-querystring v1.1.0 github.com/joho/godotenv v1.3.0 + golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 gopkg.in/h2non/gock.v1 v1.0.16 ) diff --git a/v5/client.go b/v5/client.go index 6978762..122e200 100644 --- a/v5/client.go +++ b/v5/client.go @@ -15,10 +15,9 @@ import ( "time" "github.com/google/go-querystring/query" - "github.com/retailcrm/api-client-go/errs" ) -// New initialize client +// New initialize client. func New(url string, key string) *Client { return &Client{ URL: url, @@ -27,11 +26,11 @@ func New(url string, key string) *Client { } } -// GetRequest implements GET Request -func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte, int, *errs.Failure) { +// GetRequest implements GET Request. +func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte, int, error) { var res []byte var prefix = "/api/v5" - failure := &errs.Failure{} + apiError := &APIError{} if len(versioned) > 0 { s := versioned[0] @@ -43,8 +42,7 @@ 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 { - failure.SetRuntimeError(err) - return res, 0, failure + return res, 0, err } req.Header.Set("X-API-KEY", c.Key) @@ -55,37 +53,43 @@ func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte resp, err := c.httpClient.Do(req) if err != nil { - failure.SetRuntimeError(err) - return res, 0, failure + return res, 0, err } if resp.StatusCode >= http.StatusInternalServerError { - failure.SetApiError(fmt.Sprintf("HTTP request error. Status code: %d.\n", resp.StatusCode)) - return res, resp.StatusCode, failure + apiError.ErrorMsg = fmt.Sprintf("HTTP request error. Status code: %d.\n", resp.StatusCode) + return res, resp.StatusCode, apiError } res, err = buildRawResponse(resp) if err != nil { - failure.SetRuntimeError(err) + return res, 0, err + } + + if resp.StatusCode >= http.StatusBadRequest && resp.StatusCode < http.StatusInternalServerError { + return res, resp.StatusCode, NewAPIError(res) } if c.Debug { log.Printf("API Response: %s", res) } - return res, resp.StatusCode, failure + return res, resp.StatusCode, nil } -// PostRequest implements POST Request with generic body data -func (c *Client) PostRequest(uri string, postData interface{}, contType ...string) ([]byte, int, *errs.Failure) { +// PostRequest implements POST Request with generic body data. +func (c *Client) PostRequest( + uri string, + postData interface{}, + contType ...string, +) ([]byte, int, error) { var ( res []byte contentType string - reader io.Reader ) prefix := "/api/v5" - failure := &errs.Failure{} + apiError := &APIError{} if len(contType) > 0 { contentType = contType[0] @@ -93,22 +97,14 @@ func (c *Client) PostRequest(uri string, postData interface{}, contType ...strin contentType = "application/x-www-form-urlencoded" } - switch postData.(type) { - case url.Values: - reader = strings.NewReader(postData.(url.Values).Encode()) - default: - if i, ok := postData.(io.Reader); ok { - reader = i - } else { - failure.SetRuntimeError(errors.New("postData should be url.Values or implement io.Reader")) - return []byte{}, 0, failure - } + reader, err := getReaderForPostData(postData) + if err != nil { + return res, 0, err } req, err := http.NewRequest("POST", fmt.Sprintf("%s%s%s", c.URL, prefix, uri), reader) if err != nil { - failure.SetRuntimeError(err) - return res, 0, failure + return res, 0, err } req.Header.Set("Content-Type", contentType) @@ -120,26 +116,46 @@ func (c *Client) PostRequest(uri string, postData interface{}, contType ...strin resp, err := c.httpClient.Do(req) if err != nil { - failure.SetRuntimeError(err) - return res, 0, failure + return res, 0, err } if resp.StatusCode >= http.StatusInternalServerError { - failure.SetApiError(fmt.Sprintf("HTTP request error. Status code: %d.\n", resp.StatusCode)) - return res, resp.StatusCode, failure + apiError.ErrorMsg = fmt.Sprintf("HTTP request error. Status code: %d.\n", resp.StatusCode) + return res, resp.StatusCode, apiError } res, err = buildRawResponse(resp) if err != nil { - failure.SetRuntimeError(err) - return res, 0, failure + return res, 0, err + } + + if resp.StatusCode >= http.StatusBadRequest && resp.StatusCode < http.StatusInternalServerError { + return res, resp.StatusCode, NewAPIError(res) } if c.Debug { log.Printf("API Response: %s", res) } - return res, resp.StatusCode, failure + return res, resp.StatusCode, nil +} + +func getReaderForPostData(postData interface{}) (io.Reader, error) { + var reader io.Reader + + switch d := postData.(type) { + case url.Values: + reader = strings.NewReader(d.Encode()) + default: + if i, ok := d.(io.Reader); ok { + reader = i + } else { + err := errors.New("postData should be url.Values or implement io.Reader") + return nil, err + } + } + + return reader, nil } func buildRawResponse(resp *http.Response) ([]byte, error) { @@ -153,17 +169,7 @@ func buildRawResponse(resp *http.Response) ([]byte, error) { return res, nil } -func buildErr(data []byte, err *errs.Failure) { - resp, e := errs.ErrorResponse(data) - err.SetRuntimeError(e) - err.SetApiError(resp.ErrorMsg) - - if resp.Errors != nil { - err.SetApiErrors(errs.ErrorsHandler(resp.Errors)) - } -} - -// checkBy select identifier type +// checkBy select identifier type. func checkBy(by string) string { var context = ByID @@ -174,7 +180,7 @@ func checkBy(by string) string { return context } -// fillSite add site code to parameters if present +// fillSite add site code to parameters if present. func fillSite(p *url.Values, site []string) { if len(site) > 0 { s := site[0] @@ -206,21 +212,16 @@ func fillSite(p *url.Values, site []string) { // for _, value := range data.versions { // fmt.Printf("%v\n", value) // } -func (c *Client) APIVersions() (VersionResponse, int, *errs.Failure) { +func (c *Client) APIVersions() (VersionResponse, int, error) { var resp VersionResponse data, status, err := c.GetRequest("/api-versions", false) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -245,21 +246,16 @@ func (c *Client) APIVersions() (VersionResponse, int, *errs.Failure) { // for _, value := range data.credentials { // fmt.Printf("%v\n", value) // } -func (c *Client) APICredentials() (CredentialResponse, int, *errs.Failure) { +func (c *Client) APICredentials() (CredentialResponse, int, error) { var resp CredentialResponse data, status, err := c.GetRequest("/credentials", false) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -289,23 +285,18 @@ func (c *Client) APICredentials() (CredentialResponse, int, *errs.Failure) { // for _, value := range data.Customers { // fmt.Printf("%v\n", value) // } -func (c *Client) Customers(parameters CustomersRequest) (CustomersResponse, int, *errs.Failure) { +func (c *Client) Customers(parameters CustomersRequest) (CustomersResponse, int, error) { var resp CustomersResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/customers?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -326,7 +317,7 @@ func (c *Client) Customers(parameters CustomersRequest) (CustomersResponse, int, // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) (SuccessfulResponse, int, error) { var resp SuccessfulResponse combineJSONIn, _ := json.Marshal(&customers) @@ -338,17 +329,12 @@ func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) } data, status, err := c.PostRequest("/customers/combine", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -383,7 +369,7 @@ func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) // if data.Success == true { // fmt.Printf("%v", err.Id) // } -func (c *Client) CustomerCreate(customer Customer, site ...string) (CustomerChangeResponse, int, *errs.Failure) { +func (c *Client) CustomerCreate(customer Customer, site ...string) (CustomerChangeResponse, int, error) { var resp CustomerChangeResponse customerJSON, _ := json.Marshal(&customer) @@ -395,17 +381,12 @@ func (c *Client) CustomerCreate(customer Customer, site ...string) (CustomerChan fillSite(&p, site) data, status, err := c.PostRequest("/customers/create", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -429,7 +410,7 @@ func (c *Client) CustomerCreate(customer Customer, site ...string) (CustomerChan // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (SuccessfulResponse, int, error) { var resp SuccessfulResponse customersJSON, _ := json.Marshal(&customers) @@ -439,17 +420,12 @@ func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (Successfu } data, status, err := c.PostRequest("/customers/fix-external-ids", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -478,23 +454,18 @@ func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (Successfu // for _, value := range data.History { // fmt.Printf("%v\n", value) // } -func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (CustomersHistoryResponse, int, *errs.Failure) { +func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (CustomersHistoryResponse, int, error) { var resp CustomersHistoryResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/customers/history?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -524,23 +495,18 @@ func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (Customers // for _, value := range data.Notes { // fmt.Printf("%v\n", value) // } -func (c *Client) CustomerNotes(parameters NotesRequest) (NotesResponse, int, *errs.Failure) { +func (c *Client) CustomerNotes(parameters NotesRequest) (NotesResponse, int, error) { var resp NotesResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/customers/notes?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -571,7 +537,7 @@ func (c *Client) CustomerNotes(parameters NotesRequest) (NotesResponse, int, *er // if data.Success == true { // fmt.Printf("%v\n", data.ID) // } -func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, int, *errs.Failure) { +func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, int, error) { var resp CreateResponse noteJSON, _ := json.Marshal(¬e) @@ -583,17 +549,12 @@ func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, fillSite(&p, site) data, status, err := c.PostRequest("/customers/notes/create", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -613,7 +574,7 @@ func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) CustomerNoteDelete(id int) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) CustomerNoteDelete(id int) (SuccessfulResponse, int, error) { var resp SuccessfulResponse p := url.Values{ @@ -621,17 +582,12 @@ func (c *Client) CustomerNoteDelete(id int) (SuccessfulResponse, int, *errs.Fail } data, status, err := c.PostRequest(fmt.Sprintf("/customers/notes/%d/delete", id), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -671,7 +627,7 @@ func (c *Client) CustomerNoteDelete(id int) (SuccessfulResponse, int, *errs.Fail // if data.Success == true { // fmt.Printf("%v\n", data.UploadedCustomers) // } -func (c *Client) CustomersUpload(customers []Customer, site ...string) (CustomersUploadResponse, int, *errs.Failure) { +func (c *Client) CustomersUpload(customers []Customer, site ...string) (CustomersUploadResponse, int, error) { var resp CustomersUploadResponse uploadJSON, _ := json.Marshal(&customers) @@ -683,17 +639,12 @@ func (c *Client) CustomersUpload(customers []Customer, site ...string) (Customer fillSite(&p, site) data, status, err := c.PostRequest("/customers/upload", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -718,7 +669,7 @@ func (c *Client) CustomersUpload(customers []Customer, site ...string) (Customer // if data.Success == true { // fmt.Printf("%v\n", data.Customer) // } -func (c *Client) Customer(id, by, site string) (CustomerResponse, int, *errs.Failure) { +func (c *Client) Customer(id, by, site string) (CustomerResponse, int, error) { var resp CustomerResponse var context = checkBy(by) @@ -726,17 +677,12 @@ func (c *Client) Customer(id, by, site string) (CustomerResponse, int, *errs.Fai params, _ := query.Values(fw) data, status, err := c.GetRequest(fmt.Sprintf("/customers/%s?%s", id, params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -770,7 +716,7 @@ func (c *Client) Customer(id, by, site string) (CustomerResponse, int, *errs.Fai // if data.Success == true { // fmt.Printf("%v\n", data.Customer) // } -func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (CustomerChangeResponse, int, *errs.Failure) { +func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (CustomerChangeResponse, int, error) { var resp CustomerChangeResponse var uid = strconv.Itoa(customer.ID) var context = checkBy(by) @@ -789,17 +735,12 @@ func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (Cus fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/customers/%s/edit", uid), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -829,23 +770,18 @@ func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (Cus // for _, value := range data.CustomersCorporate { // fmt.Printf("%v\n", value) // } -func (c *Client) CorporateCustomers(parameters CorporateCustomersRequest) (CorporateCustomersResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomers(parameters CorporateCustomersRequest) (CorporateCustomersResponse, int, error) { var resp CorporateCustomersResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/customers-corporate?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -872,7 +808,9 @@ func (c *Client) CorporateCustomers(parameters CorporateCustomersRequest) (Corpo // if data.Success == true { // fmt.Printf("%v", err.Id) // } -func (c *Client) CorporateCustomerCreate(customer CorporateCustomer, site ...string) (CorporateCustomerChangeResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomerCreate(customer CorporateCustomer, site ...string) ( + CorporateCustomerChangeResponse, int, error, +) { var resp CorporateCustomerChangeResponse customerJSON, _ := json.Marshal(&customer) @@ -884,17 +822,12 @@ func (c *Client) CorporateCustomerCreate(customer CorporateCustomer, site ...str fillSite(&p, site) data, status, err := c.PostRequest("/customers-corporate/create", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -918,7 +851,7 @@ func (c *Client) CorporateCustomerCreate(customer CorporateCustomer, site ...str // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) CorporateCustomersFixExternalIds(customers []IdentifiersPair) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomersFixExternalIds(customers []IdentifiersPair) (SuccessfulResponse, int, error) { var resp SuccessfulResponse customersJSON, _ := json.Marshal(&customers) @@ -928,17 +861,12 @@ func (c *Client) CorporateCustomersFixExternalIds(customers []IdentifiersPair) ( } data, status, err := c.PostRequest("/customers-corporate/fix-external-ids", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -967,23 +895,20 @@ func (c *Client) CorporateCustomersFixExternalIds(customers []IdentifiersPair) ( // for _, value := range data.History { // fmt.Printf("%v\n", value) // } -func (c *Client) CorporateCustomersHistory(parameters CorporateCustomersHistoryRequest) (CorporateCustomersHistoryResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomersHistory(parameters CorporateCustomersHistoryRequest) ( + CorporateCustomersHistoryResponse, int, error, +) { var resp CorporateCustomersHistoryResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/customers-corporate/history?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1013,23 +938,20 @@ func (c *Client) CorporateCustomersHistory(parameters CorporateCustomersHistoryR // for _, value := range data.Notes { // fmt.Printf("%v\n", value) // } -func (c *Client) CorporateCustomersNotes(parameters CorporateCustomersNotesRequest) (CorporateCustomersNotesResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomersNotes(parameters CorporateCustomersNotesRequest) ( + CorporateCustomersNotesResponse, int, error, +) { var resp CorporateCustomersNotesResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/customers-corporate/notes?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1059,7 +981,7 @@ func (c *Client) CorporateCustomersNotes(parameters CorporateCustomersNotesReque // if data.Success == true { // fmt.Printf("%v", err.Id) // } -func (c *Client) CorporateCustomerNoteCreate(note CorporateCustomerNote, site ...string) (CreateResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomerNoteCreate(note CorporateCustomerNote, site ...string) (CreateResponse, int, error) { var resp CreateResponse noteJSON, _ := json.Marshal(¬e) @@ -1071,17 +993,12 @@ func (c *Client) CorporateCustomerNoteCreate(note CorporateCustomerNote, site .. fillSite(&p, site) data, status, err := c.PostRequest("/customers-corporate/notes/create", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1102,7 +1019,7 @@ func (c *Client) CorporateCustomerNoteCreate(note CorporateCustomerNote, site .. // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) CorporateCustomerNoteDelete(id int) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomerNoteDelete(id int) (SuccessfulResponse, int, error) { var resp SuccessfulResponse p := url.Values{ @@ -1110,17 +1027,12 @@ func (c *Client) CorporateCustomerNoteDelete(id int) (SuccessfulResponse, int, * } data, status, err := c.PostRequest(fmt.Sprintf("/customers-corporate/notes/%d/delete", id), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1154,7 +1066,9 @@ func (c *Client) CorporateCustomerNoteDelete(id int) (SuccessfulResponse, int, * // if data.Success == true { // fmt.Printf("%v\n", data.UploadedCustomers) // } -func (c *Client) CorporateCustomersUpload(customers []CorporateCustomer, site ...string) (CorporateCustomersUploadResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomersUpload( + customers []CorporateCustomer, site ...string, +) (CorporateCustomersUploadResponse, int, error) { var resp CorporateCustomersUploadResponse uploadJSON, _ := json.Marshal(&customers) @@ -1166,17 +1080,12 @@ func (c *Client) CorporateCustomersUpload(customers []CorporateCustomer, site .. fillSite(&p, site) data, status, err := c.PostRequest("/customers-corporate/upload", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1201,7 +1110,7 @@ func (c *Client) CorporateCustomersUpload(customers []CorporateCustomer, site .. // if data.Success == true { // fmt.Printf("%v\n", data.CorporateCustomer) // } -func (c *Client) CorporateCustomer(id, by, site string) (CorporateCustomerResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomer(id, by, site string) (CorporateCustomerResponse, int, error) { var resp CorporateCustomerResponse var context = checkBy(by) @@ -1209,17 +1118,12 @@ func (c *Client) CorporateCustomer(id, by, site string) (CorporateCustomerRespon params, _ := query.Values(fw) data, status, err := c.GetRequest(fmt.Sprintf("/customers-corporate/%s?%s", id, params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1252,24 +1156,21 @@ func (c *Client) CorporateCustomer(id, by, site string) (CorporateCustomerRespon // if data.Success == true { // fmt.Printf("%v\n", data.Addresses) // } -func (c *Client) CorporateCustomerAddresses(id string, parameters CorporateCustomerAddressesRequest) (CorporateCustomersAddressesResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomerAddresses( + id string, parameters CorporateCustomerAddressesRequest, +) (CorporateCustomersAddressesResponse, int, error) { var resp CorporateCustomersAddressesResponse parameters.By = checkBy(parameters.By) params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/customers-corporate/%s/addresses?%s", id, params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1297,7 +1198,9 @@ func (c *Client) CorporateCustomerAddresses(id string, parameters CorporateCusto // if data.Success == true { // fmt.Printf("%v", data.ID) // } -func (c *Client) CorporateCustomerAddressesCreate(id string, by string, address CorporateCustomerAddress, site ...string) (CreateResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomerAddressesCreate( + id string, by string, address CorporateCustomerAddress, site ...string, +) (CreateResponse, int, error) { var resp CreateResponse addressJSON, _ := json.Marshal(&address) @@ -1310,17 +1213,12 @@ func (c *Client) CorporateCustomerAddressesCreate(id string, by string, address fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/customers-corporate/%s/addresses/create", id), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1353,7 +1251,9 @@ func (c *Client) CorporateCustomerAddressesCreate(id string, by string, address // if data.Success == true { // fmt.Printf("%v\n", data.Customer) // } -func (c *Client) CorporateCustomerAddressesEdit(customerID, customerBy, entityBy string, address CorporateCustomerAddress, site ...string) (CreateResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomerAddressesEdit( + customerID, customerBy, entityBy string, address CorporateCustomerAddress, site ...string, +) (CreateResponse, int, error) { var ( resp CreateResponse uid string @@ -1380,17 +1280,12 @@ func (c *Client) CorporateCustomerAddressesEdit(customerID, customerBy, entityBy fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/customers-corporate/%s/addresses/%s/edit", customerID, uid), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1423,24 +1318,21 @@ func (c *Client) CorporateCustomerAddressesEdit(customerID, customerBy, entityBy // if data.Success == true { // fmt.Printf("%v\n", data.Companies) // } -func (c *Client) CorporateCustomerCompanies(id string, parameters IdentifiersPairRequest) (CorporateCustomerCompaniesResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomerCompanies( + id string, parameters IdentifiersPairRequest, +) (CorporateCustomerCompaniesResponse, int, error) { var resp CorporateCustomerCompaniesResponse parameters.By = checkBy(parameters.By) params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/customers-corporate/%s/companies?%s", id, params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1467,7 +1359,9 @@ func (c *Client) CorporateCustomerCompanies(id string, parameters IdentifiersPai // if data.Success == true { // fmt.Printf("%v", data.ID) // } -func (c *Client) CorporateCustomerCompaniesCreate(id string, by string, company Company, site ...string) (CreateResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomerCompaniesCreate( + id string, by string, company Company, site ...string, +) (CreateResponse, int, error) { var resp CreateResponse companyJSON, _ := json.Marshal(&company) @@ -1480,17 +1374,12 @@ func (c *Client) CorporateCustomerCompaniesCreate(id string, by string, company fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/customers-corporate/%s/companies/create", id), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1523,7 +1412,9 @@ func (c *Client) CorporateCustomerCompaniesCreate(id string, by string, company // if data.Success == true { // fmt.Printf("%v\n", data.ID) // } -func (c *Client) CorporateCustomerCompaniesEdit(customerID, customerBy, entityBy string, company Company, site ...string) (CreateResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomerCompaniesEdit( + customerID, customerBy, entityBy string, company Company, site ...string, +) (CreateResponse, int, error) { var ( resp CreateResponse uid string @@ -1550,17 +1441,12 @@ func (c *Client) CorporateCustomerCompaniesEdit(customerID, customerBy, entityBy fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/customers-corporate/%s/companies/%s/edit", customerID, uid), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1593,24 +1479,21 @@ func (c *Client) CorporateCustomerCompaniesEdit(customerID, customerBy, entityBy // if data.Success == true { // fmt.Printf("%v\n", data.Contacts) // } -func (c *Client) CorporateCustomerContacts(id string, parameters IdentifiersPairRequest) (CorporateCustomerContactsResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomerContacts( + id string, parameters IdentifiersPairRequest, +) (CorporateCustomerContactsResponse, int, error) { var resp CorporateCustomerContactsResponse parameters.By = checkBy(parameters.By) params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/customers-corporate/%s/contacts?%s", id, params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1642,7 +1525,9 @@ func (c *Client) CorporateCustomerContacts(id string, parameters IdentifiersPair // if data.Success == true { // fmt.Printf("%v", data.ID) // } -func (c *Client) CorporateCustomerContactsCreate(id string, by string, contact CorporateCustomerContact, site ...string) (CreateResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomerContactsCreate( + id string, by string, contact CorporateCustomerContact, site ...string, +) (CreateResponse, int, error) { var resp CreateResponse companyJSON, _ := json.Marshal(&contact) @@ -1655,17 +1540,12 @@ func (c *Client) CorporateCustomerContactsCreate(id string, by string, contact C fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/customers-corporate/%s/contacts/create", id), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1695,7 +1575,9 @@ func (c *Client) CorporateCustomerContactsCreate(id string, by string, contact C // if data.Success == true { // fmt.Printf("%v\n", data.ID) // } -func (c *Client) CorporateCustomerContactsEdit(customerID, customerBy, entityBy string, contact CorporateCustomerContact, site ...string) (CreateResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomerContactsEdit( + customerID, customerBy, entityBy string, contact CorporateCustomerContact, site ...string, +) (CreateResponse, int, error) { var ( resp CreateResponse uid string @@ -1722,17 +1604,12 @@ func (c *Client) CorporateCustomerContactsEdit(customerID, customerBy, entityBy fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/customers-corporate/%s/contacts/%s/edit", customerID, uid), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1766,7 +1643,9 @@ func (c *Client) CorporateCustomerContactsEdit(customerID, customerBy, entityBy // if data.Success == true { // fmt.Printf("%v\n", data.Customer) // } -func (c *Client) CorporateCustomerEdit(customer CorporateCustomer, by string, site ...string) (CustomerChangeResponse, int, *errs.Failure) { +func (c *Client) CorporateCustomerEdit(customer CorporateCustomer, by string, site ...string) ( + CustomerChangeResponse, int, error, +) { var resp CustomerChangeResponse var uid = strconv.Itoa(customer.ID) var context = checkBy(by) @@ -1785,17 +1664,12 @@ func (c *Client) CorporateCustomerEdit(customer CorporateCustomer, by string, si fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/customers-corporate/%s/edit", uid), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1830,7 +1704,9 @@ func (c *Client) CorporateCustomerEdit(customer CorporateCustomer, by string, si // fmt.Printf("%v", err.ApiError()) // } // -func (c *Client) DeliveryTracking(parameters []DeliveryTrackingRequest, subcode string) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) DeliveryTracking(parameters []DeliveryTrackingRequest, subcode string) ( + SuccessfulResponse, int, error, +) { var resp SuccessfulResponse updateJSON, _ := json.Marshal(¶meters) @@ -1840,17 +1716,12 @@ func (c *Client) DeliveryTracking(parameters []DeliveryTrackingRequest, subcode } data, status, err := c.PostRequest(fmt.Sprintf("/delivery/generic/%s/tracking", subcode), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1880,23 +1751,18 @@ func (c *Client) DeliveryTracking(parameters []DeliveryTrackingRequest, subcode // for _, value := range data.DeliveryShipments { // fmt.Printf("%v\n", value) // } -func (c *Client) DeliveryShipments(parameters DeliveryShipmentsRequest) (DeliveryShipmentsResponse, int, *errs.Failure) { +func (c *Client) DeliveryShipments(parameters DeliveryShipmentsRequest) (DeliveryShipmentsResponse, int, error) { var resp DeliveryShipmentsResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/delivery/shipments?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1931,7 +1797,9 @@ func (c *Client) DeliveryShipments(parameters DeliveryShipmentsRequest) (Deliver // if data.Success == true { // fmt.Printf("%v\n", data.ID) // } -func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType string, site ...string) (DeliveryShipmentUpdateResponse, int, *errs.Failure) { +func (c *Client) DeliveryShipmentCreate( + shipment DeliveryShipment, deliveryType string, site ...string, +) (DeliveryShipmentUpdateResponse, int, error) { var resp DeliveryShipmentUpdateResponse updateJSON, _ := json.Marshal(&shipment) @@ -1943,17 +1811,12 @@ func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType fillSite(&p, site) data, status, err := c.PostRequest("/delivery/shipments/create", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -1978,21 +1841,16 @@ func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType // if data.Success == true { // fmt.Printf("%v\n", data.DeliveryShipment) // } -func (c *Client) DeliveryShipment(id int) (DeliveryShipmentResponse, int, *errs.Failure) { +func (c *Client) DeliveryShipment(id int) (DeliveryShipmentResponse, int, error) { var resp DeliveryShipmentResponse data, status, err := c.GetRequest(fmt.Sprintf("/delivery/shipments/%d", id)) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2019,7 +1877,9 @@ func (c *Client) DeliveryShipment(id int) (DeliveryShipmentResponse, int, *errs. // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) (DeliveryShipmentUpdateResponse, int, *errs.Failure) { +func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) ( + DeliveryShipmentUpdateResponse, int, error, +) { var resp DeliveryShipmentUpdateResponse updateJSON, _ := json.Marshal(&shipment) @@ -2030,17 +1890,12 @@ func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/delivery/shipments/%s/edit", strconv.Itoa(shipment.ID)), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2065,21 +1920,16 @@ func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) // if data.Success == true { // fmt.Printf("%v\n", data.IntegrationModule) // } -func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int, *errs.Failure) { +func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int, error) { var resp IntegrationModuleResponse data, status, err := c.GetRequest(fmt.Sprintf("/integration-modules/%s", code)) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2116,24 +1966,21 @@ func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int, // if data.Success == true { // fmt.Printf("%v\n", data.Info) // } -func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (IntegrationModuleEditResponse, int, *errs.Failure) { +func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) ( + IntegrationModuleEditResponse, int, error, +) { var resp IntegrationModuleEditResponse updateJSON, _ := json.Marshal(&integrationModule) p := url.Values{"integrationModule": {string(updateJSON[:])}} data, status, err := c.PostRequest(fmt.Sprintf("/integration-modules/%s/edit", integrationModule.Code), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2158,23 +2005,18 @@ func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (Int // for _, value := range data.Orders { // fmt.Printf("%v\n", value) // } -func (c *Client) Orders(parameters OrdersRequest) (OrdersResponse, int, *errs.Failure) { +func (c *Client) Orders(parameters OrdersRequest) (OrdersResponse, int, error) { var resp OrdersResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/orders?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2195,7 +2037,7 @@ func (c *Client) Orders(parameters OrdersRequest) (OrdersResponse, int, *errs.Fa // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (OperationResponse, int, *errs.Failure) { +func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (OperationResponse, int, error) { var resp OperationResponse combineJSONIn, _ := json.Marshal(&order) @@ -2208,17 +2050,12 @@ func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (Oper } data, status, err := c.PostRequest("/orders/combine", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2249,7 +2086,7 @@ func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (Oper // if data.Success == true { // fmt.Printf("%v\n", data.ID) // } -func (c *Client) OrderCreate(order Order, site ...string) (OrderCreateResponse, int, *errs.Failure) { +func (c *Client) OrderCreate(order Order, site ...string) (OrderCreateResponse, int, error) { var resp OrderCreateResponse orderJSON, _ := json.Marshal(&order) @@ -2260,17 +2097,12 @@ func (c *Client) OrderCreate(order Order, site ...string) (OrderCreateResponse, fillSite(&p, site) data, status, err := c.PostRequest("/orders/create", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2298,7 +2130,7 @@ func (c *Client) OrderCreate(order Order, site ...string) (OrderCreateResponse, // if data.Success == true { // fmt.Printf("%v\n", data.ID) // } -func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulResponse, int, error) { var resp SuccessfulResponse ordersJSON, _ := json.Marshal(&orders) @@ -2308,17 +2140,12 @@ func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulRespo } data, status, err := c.PostRequest("/orders/fix-external-ids", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2343,23 +2170,18 @@ func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulRespo // for _, value := range data.History { // fmt.Printf("%v\n", value) // } -func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (OrdersHistoryResponse, int, *errs.Failure) { +func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (OrdersHistoryResponse, int, error) { var resp OrdersHistoryResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/orders/history?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2390,7 +2212,7 @@ func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (OrdersHistoryRe // if data.Success == true { // fmt.Printf("%v\n", data.ID) // } -func (c *Client) OrderPaymentCreate(payment Payment, site ...string) (CreateResponse, int, *errs.Failure) { +func (c *Client) OrderPaymentCreate(payment Payment, site ...string) (CreateResponse, int, error) { var resp CreateResponse paymentJSON, _ := json.Marshal(&payment) @@ -2402,17 +2224,12 @@ func (c *Client) OrderPaymentCreate(payment Payment, site ...string) (CreateResp fillSite(&p, site) data, status, err := c.PostRequest("/orders/payments/create", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2433,7 +2250,7 @@ func (c *Client) OrderPaymentCreate(payment Payment, site ...string) (CreateResp // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) OrderPaymentDelete(id int) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) OrderPaymentDelete(id int) (SuccessfulResponse, int, error) { var resp SuccessfulResponse p := url.Values{ @@ -2441,17 +2258,12 @@ func (c *Client) OrderPaymentDelete(id int) (SuccessfulResponse, int, *errs.Fail } data, status, err := c.PostRequest(fmt.Sprintf("/orders/payments/%d/delete", id), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2478,7 +2290,7 @@ func (c *Client) OrderPaymentDelete(id int) (SuccessfulResponse, int, *errs.Fail // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (SuccessfulResponse, int, error) { var resp SuccessfulResponse var uid = strconv.Itoa(payment.ID) var context = checkBy(by) @@ -2497,17 +2309,12 @@ func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (S fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/orders/payments/%s/edit", uid), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2531,23 +2338,18 @@ func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (S // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) OrdersStatuses(request OrdersStatusesRequest) (OrdersStatusesResponse, int, *errs.Failure) { +func (c *Client) OrdersStatuses(request OrdersStatusesRequest) (OrdersStatusesResponse, int, error) { var resp OrdersStatusesResponse params, _ := query.Values(request) data, status, err := c.GetRequest(fmt.Sprintf("/orders/statuses?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2587,7 +2389,7 @@ func (c *Client) OrdersStatuses(request OrdersStatusesRequest) (OrdersStatusesRe // if data.Success == true { // fmt.Printf("%v\n", data.UploadedOrders) // } -func (c *Client) OrdersUpload(orders []Order, site ...string) (OrdersUploadResponse, int, *errs.Failure) { +func (c *Client) OrdersUpload(orders []Order, site ...string) (OrdersUploadResponse, int, error) { var resp OrdersUploadResponse uploadJSON, _ := json.Marshal(&orders) @@ -2599,17 +2401,12 @@ func (c *Client) OrdersUpload(orders []Order, site ...string) (OrdersUploadRespo fillSite(&p, site) data, status, err := c.PostRequest("/orders/upload", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2634,7 +2431,7 @@ func (c *Client) OrdersUpload(orders []Order, site ...string) (OrdersUploadRespo // if data.Success == true { // fmt.Printf("%v\n", data.Order) // } -func (c *Client) Order(id, by, site string) (OrderResponse, int, *errs.Failure) { +func (c *Client) Order(id, by, site string) (OrderResponse, int, error) { var resp OrderResponse var context = checkBy(by) @@ -2642,17 +2439,12 @@ func (c *Client) Order(id, by, site string) (OrderResponse, int, *errs.Failure) params, _ := query.Values(fw) data, status, err := c.GetRequest(fmt.Sprintf("/orders/%s?%s", id, params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2679,7 +2471,7 @@ func (c *Client) Order(id, by, site string) (OrderResponse, int, *errs.Failure) // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateResponse, int, *errs.Failure) { +func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateResponse, int, error) { var resp CreateResponse var uid = strconv.Itoa(order.ID) var context = checkBy(by) @@ -2698,17 +2490,12 @@ func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateRespon fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/orders/%s/edit", uid), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2733,23 +2520,18 @@ func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateRespon // for _, value := range data.Packs { // fmt.Printf("%v\n", value) // } -func (c *Client) Packs(parameters PacksRequest) (PacksResponse, int, *errs.Failure) { +func (c *Client) Packs(parameters PacksRequest) (PacksResponse, int, error) { var resp PacksResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/orders/packs?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2778,7 +2560,7 @@ func (c *Client) Packs(parameters PacksRequest) (PacksResponse, int, *errs.Failu // if data.Success == true { // fmt.Printf("%v\n", data.ID) // } -func (c *Client) PackCreate(pack Pack) (CreateResponse, int, *errs.Failure) { +func (c *Client) PackCreate(pack Pack) (CreateResponse, int, error) { var resp CreateResponse packJSON, _ := json.Marshal(&pack) @@ -2787,17 +2569,12 @@ func (c *Client) PackCreate(pack Pack) (CreateResponse, int, *errs.Failure) { } data, status, err := c.PostRequest("/orders/packs/create", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2822,23 +2599,18 @@ func (c *Client) PackCreate(pack Pack) (CreateResponse, int, *errs.Failure) { // for _, value := range data.History { // fmt.Printf("%v\n", value) // } -func (c *Client) PacksHistory(parameters PacksHistoryRequest) (PacksHistoryResponse, int, *errs.Failure) { +func (c *Client) PacksHistory(parameters PacksHistoryRequest) (PacksHistoryResponse, int, error) { var resp PacksHistoryResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/orders/packs/history?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2863,21 +2635,16 @@ func (c *Client) PacksHistory(parameters PacksHistoryRequest) (PacksHistoryRespo // if data.Success == true { // fmt.Printf("%v\n", data.Pack) // } -func (c *Client) Pack(id int) (PackResponse, int, *errs.Failure) { +func (c *Client) Pack(id int) (PackResponse, int, error) { var resp PackResponse data, status, err := c.GetRequest(fmt.Sprintf("/orders/packs/%d", id)) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2898,21 +2665,16 @@ func (c *Client) Pack(id int) (PackResponse, int, *errs.Failure) { // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) PackDelete(id int) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) PackDelete(id int) (SuccessfulResponse, int, error) { var resp SuccessfulResponse data, status, err := c.PostRequest(fmt.Sprintf("/orders/packs/%d/delete", id), url.Values{}) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -2933,7 +2695,7 @@ func (c *Client) PackDelete(id int) (SuccessfulResponse, int, *errs.Failure) { // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) PackEdit(pack Pack) (CreateResponse, int, *errs.Failure) { +func (c *Client) PackEdit(pack Pack) (CreateResponse, int, error) { var resp CreateResponse packJSON, _ := json.Marshal(&pack) @@ -2943,59 +2705,44 @@ func (c *Client) PackEdit(pack Pack) (CreateResponse, int, *errs.Failure) { } data, status, err := c.PostRequest(fmt.Sprintf("/orders/packs/%d/edit", pack.ID), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) Countries() (CountriesResponse, int, error) { var resp CountriesResponse data, status, err := c.GetRequest("/reference/countries") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) CostGroups() (CostGroupsResponse, int, error) { var resp CostGroupsResponse data, status, err := c.GetRequest("/reference/cost-groups") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -3019,7 +2766,7 @@ func (c *Client) CostGroups() (CostGroupsResponse, int, *errs.Failure) { // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) CostGroupEdit(costGroup CostGroup) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) CostGroupEdit(costGroup CostGroup) (SuccessfulResponse, int, error) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&costGroup) @@ -3029,38 +2776,28 @@ func (c *Client) CostGroupEdit(costGroup CostGroup) (SuccessfulResponse, int, *e } data, status, err := c.PostRequest(fmt.Sprintf("/reference/cost-groups/%s/edit", costGroup.Code), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) CostItems() (CostItemsResponse, int, error) { var resp CostItemsResponse data, status, err := c.GetRequest("/reference/cost-items") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -3084,7 +2821,7 @@ func (c *Client) CostItems() (CostItemsResponse, int, *errs.Failure) { // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) CostItemEdit(costItem CostItem) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) CostItemEdit(costItem CostItem) (SuccessfulResponse, int, error) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&costItem) @@ -3094,38 +2831,28 @@ func (c *Client) CostItemEdit(costItem CostItem) (SuccessfulResponse, int, *errs } data, status, err := c.PostRequest(fmt.Sprintf("/reference/cost-items/%s/edit", costItem.Code), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) Couriers() (CouriersResponse, int, error) { var resp CouriersResponse data, status, err := c.GetRequest("/reference/couriers") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -3155,7 +2882,7 @@ func (c *Client) Couriers() (CouriersResponse, int, *errs.Failure) { // if data.Success == true { // fmt.Printf("%v", data.ID) // } -func (c *Client) CourierCreate(courier Courier) (CreateResponse, int, *errs.Failure) { +func (c *Client) CourierCreate(courier Courier) (CreateResponse, int, error) { var resp CreateResponse objJSON, _ := json.Marshal(&courier) @@ -3165,17 +2892,12 @@ func (c *Client) CourierCreate(courier Courier) (CreateResponse, int, *errs.Fail } data, status, err := c.PostRequest("/reference/couriers/create", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -3199,7 +2921,7 @@ func (c *Client) CourierCreate(courier Courier) (CreateResponse, int, *errs.Fail // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) CourierEdit(courier Courier) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) CourierEdit(courier Courier) (SuccessfulResponse, int, error) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&courier) @@ -3209,38 +2931,28 @@ func (c *Client) CourierEdit(courier Courier) (SuccessfulResponse, int, *errs.Fa } data, status, err := c.PostRequest(fmt.Sprintf("/reference/couriers/%d/edit", courier.ID), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) DeliveryServices() (DeliveryServiceResponse, int, error) { var resp DeliveryServiceResponse data, status, err := c.GetRequest("/reference/delivery-services") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -3264,7 +2976,7 @@ func (c *Client) DeliveryServices() (DeliveryServiceResponse, int, *errs.Failure // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (SuccessfulResponse, int, error) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&deliveryService) @@ -3274,38 +2986,28 @@ func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (Successfu } data, status, err := c.PostRequest(fmt.Sprintf("/reference/delivery-services/%s/edit", deliveryService.Code), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) DeliveryTypes() (DeliveryTypesResponse, int, error) { var resp DeliveryTypesResponse data, status, err := c.GetRequest("/reference/delivery-types") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -3331,7 +3033,7 @@ func (c *Client) DeliveryTypes() (DeliveryTypesResponse, int, *errs.Failure) { // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (SuccessfulResponse, int, error) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&deliveryType) @@ -3341,38 +3043,28 @@ func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (SuccessfulResponse } data, status, err := c.PostRequest(fmt.Sprintf("/reference/delivery-types/%s/edit", deliveryType.Code), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) LegalEntities() (LegalEntitiesResponse, int, error) { var resp LegalEntitiesResponse data, status, err := c.GetRequest("/reference/legal-entities") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -3396,7 +3088,7 @@ func (c *Client) LegalEntities() (LegalEntitiesResponse, int, *errs.Failure) { // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (SuccessfulResponse, int, error) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&legalEntity) @@ -3406,38 +3098,28 @@ func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (SuccessfulResponse, i } data, status, err := c.PostRequest(fmt.Sprintf("/reference/legal-entities/%s/edit", legalEntity.Code), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) OrderMethods() (OrderMethodsResponse, int, error) { var resp OrderMethodsResponse data, status, err := c.GetRequest("/reference/order-methods") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -3462,7 +3144,7 @@ func (c *Client) OrderMethods() (OrderMethodsResponse, int, *errs.Failure) { // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (SuccessfulResponse, int, error) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&orderMethod) @@ -3472,38 +3154,28 @@ func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (SuccessfulResponse, i } data, status, err := c.PostRequest(fmt.Sprintf("/reference/order-methods/%s/edit", orderMethod.Code), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) OrderTypes() (OrderTypesResponse, int, error) { var resp OrderTypesResponse data, status, err := c.GetRequest("/reference/order-types") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -3528,7 +3200,7 @@ func (c *Client) OrderTypes() (OrderTypesResponse, int, *errs.Failure) { // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) OrderTypeEdit(orderType OrderType) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) OrderTypeEdit(orderType OrderType) (SuccessfulResponse, int, error) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&orderType) @@ -3538,45 +3210,35 @@ func (c *Client) OrderTypeEdit(orderType OrderType) (SuccessfulResponse, int, *e } data, status, err := c.PostRequest(fmt.Sprintf("/reference/order-types/%s/edit", orderType.Code), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) PaymentStatuses() (PaymentStatusesResponse, int, error) { var resp PaymentStatusesResponse data, status, err := c.GetRequest("/reference/payment-statuses") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) PaymentStatusEdit(paymentStatus PaymentStatus) (SuccessfulResponse, int, error) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&paymentStatus) @@ -3586,45 +3248,35 @@ func (c *Client) PaymentStatusEdit(paymentStatus PaymentStatus) (SuccessfulRespo } data, status, err := c.PostRequest(fmt.Sprintf("/reference/payment-statuses/%s/edit", paymentStatus.Code), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) PaymentTypes() (PaymentTypesResponse, int, error) { var resp PaymentTypesResponse data, status, err := c.GetRequest("/reference/payment-types") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) PaymentTypeEdit(paymentType PaymentType) (SuccessfulResponse, int, error) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&paymentType) @@ -3634,45 +3286,35 @@ func (c *Client) PaymentTypeEdit(paymentType PaymentType) (SuccessfulResponse, i } data, status, err := c.PostRequest(fmt.Sprintf("/reference/payment-types/%s/edit", paymentType.Code), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) PriceTypes() (PriceTypesResponse, int, error) { var resp PriceTypesResponse data, status, err := c.GetRequest("/reference/price-types") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) PriceTypeEdit(priceType PriceType) (SuccessfulResponse, int, error) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&priceType) @@ -3682,45 +3324,35 @@ func (c *Client) PriceTypeEdit(priceType PriceType) (SuccessfulResponse, int, *e } data, status, err := c.PostRequest(fmt.Sprintf("/reference/price-types/%s/edit", priceType.Code), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) ProductStatuses() (ProductStatusesResponse, int, error) { var resp ProductStatusesResponse data, status, err := c.GetRequest("/reference/product-statuses") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) ProductStatusEdit(productStatus ProductStatus) (SuccessfulResponse, int, error) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&productStatus) @@ -3730,45 +3362,35 @@ func (c *Client) ProductStatusEdit(productStatus ProductStatus) (SuccessfulRespo } data, status, err := c.PostRequest(fmt.Sprintf("/reference/product-statuses/%s/edit", productStatus.Code), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) Sites() (SitesResponse, int, error) { var resp SitesResponse data, status, err := c.GetRequest("/reference/sites") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) SiteEdit(site Site) (SuccessfulResponse, int, error) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&site) @@ -3778,66 +3400,51 @@ func (c *Client) SiteEdit(site Site) (SuccessfulResponse, int, *errs.Failure) { } data, status, err := c.PostRequest(fmt.Sprintf("/reference/sites/%s/edit", site.Code), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) StatusGroups() (StatusGroupsResponse, int, error) { var resp StatusGroupsResponse data, status, err := c.GetRequest("/reference/status-groups") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) Statuses() (StatusesResponse, int, error) { var resp StatusesResponse data, status, err := c.GetRequest("/reference/statuses") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +// 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, error) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&st) @@ -3847,45 +3454,35 @@ func (c *Client) StatusEdit(st Status) (SuccessfulResponse, int, *errs.Failure) } data, status, err := c.PostRequest(fmt.Sprintf("/reference/statuses/%s/edit", st.Code), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) Stores() (StoresResponse, int, error) { var resp StoresResponse data, status, err := c.GetRequest("/reference/stores") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // 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) { +func (c *Client) StoreEdit(store Store) (SuccessfulResponse, int, error) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&store) @@ -3895,45 +3492,35 @@ func (c *Client) StoreEdit(store Store) (SuccessfulResponse, int, *errs.Failure) } data, status, err := c.PostRequest(fmt.Sprintf("/reference/stores/%s/edit", store.Code), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // Units returns units list // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-units -func (c *Client) Units() (UnitsResponse, int, *errs.Failure) { +func (c *Client) Units() (UnitsResponse, int, error) { var resp UnitsResponse data, status, err := c.GetRequest("/reference/units") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } // UnitEdit unit create/edit // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-units-code-edit -func (c *Client) UnitEdit(unit Unit) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) UnitEdit(unit Unit) (SuccessfulResponse, int, error) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&unit) @@ -3943,17 +3530,12 @@ func (c *Client) UnitEdit(unit Unit) (SuccessfulResponse, int, *errs.Failure) { } data, status, err := c.PostRequest(fmt.Sprintf("/reference/units/%s/edit", unit.Code), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -3982,23 +3564,18 @@ func (c *Client) UnitEdit(unit Unit) (SuccessfulResponse, int, *errs.Failure) { // for _, value := range data.Segments { // fmt.Printf("%v\n", value) // } -func (c *Client) Segments(parameters SegmentsRequest) (SegmentsResponse, int, *errs.Failure) { +func (c *Client) Segments(parameters SegmentsRequest) (SegmentsResponse, int, error) { var resp SegmentsResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/segments?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4021,21 +3598,16 @@ func (c *Client) Segments(parameters SegmentsRequest) (SegmentsResponse, int, *e // } // // fmt.Printf("%#v\n", data) -func (c *Client) Settings() (SettingsResponse, int, *errs.Failure) { +func (c *Client) Settings() (SettingsResponse, int, error) { var resp SettingsResponse data, status, err := c.GetRequest("/settings") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4060,23 +3632,18 @@ func (c *Client) Settings() (SettingsResponse, int, *errs.Failure) { // for _, value := range data.Offers { // fmt.Printf("%v\n", value) // } -func (c *Client) Inventories(parameters InventoriesRequest) (InventoriesResponse, int, *errs.Failure) { +func (c *Client) Inventories(parameters InventoriesRequest) (InventoriesResponse, int, error) { var resp InventoriesResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/store/inventories?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4118,7 +3685,7 @@ func (c *Client) Inventories(parameters InventoriesRequest) (InventoriesResponse // } // // fmt.Printf("%v\n", data.NotFoundOffers) -func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string) (StoreUploadResponse, int, *errs.Failure) { +func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string) (StoreUploadResponse, int, error) { var resp StoreUploadResponse uploadJSON, _ := json.Marshal(&inventories) @@ -4130,17 +3697,12 @@ func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string fillSite(&p, site) data, status, err := c.PostRequest("/store/inventories/upload", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4174,7 +3736,7 @@ func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string // } // // fmt.Printf("%v\n", data.NotFoundOffers) -func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, int, *errs.Failure) { +func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, int, error) { var resp StoreUploadResponse uploadJSON, _ := json.Marshal(&prices) @@ -4184,17 +3746,12 @@ func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, i } data, status, err := c.PostRequest("/store/prices/upload", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4223,23 +3780,18 @@ func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, i // for _, value := range data.ProductGroup { // fmt.Printf("%v\n", value) // } -func (c *Client) ProductsGroup(parameters ProductsGroupsRequest) (ProductsGroupsResponse, int, *errs.Failure) { +func (c *Client) ProductsGroup(parameters ProductsGroupsRequest) (ProductsGroupsResponse, int, error) { var resp ProductsGroupsResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/store/product-groups?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4269,23 +3821,18 @@ func (c *Client) ProductsGroup(parameters ProductsGroupsRequest) (ProductsGroups // for _, value := range data.Products { // fmt.Printf("%v\n", value) // } -func (c *Client) Products(parameters ProductsRequest) (ProductsResponse, int, *errs.Failure) { +func (c *Client) Products(parameters ProductsRequest) (ProductsResponse, int, error) { var resp ProductsResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/store/products?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4314,23 +3861,18 @@ func (c *Client) Products(parameters ProductsRequest) (ProductsResponse, int, *e // for _, value := range data.Properties { // fmt.Printf("%v\n", value) // } -func (c *Client) ProductsProperties(parameters ProductsPropertiesRequest) (ProductsPropertiesResponse, int, *errs.Failure) { +func (c *Client) ProductsProperties(parameters ProductsPropertiesRequest) (ProductsPropertiesResponse, int, error) { var resp ProductsPropertiesResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/store/products/properties?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4359,23 +3901,18 @@ func (c *Client) ProductsProperties(parameters ProductsPropertiesRequest) (Produ // for _, value := range data.Tasks { // fmt.Printf("%v\n", value) // } -func (c *Client) Tasks(parameters TasksRequest) (TasksResponse, int, *errs.Failure) { +func (c *Client) Tasks(parameters TasksRequest) (TasksResponse, int, error) { var resp TasksResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/tasks?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4403,7 +3940,7 @@ func (c *Client) Tasks(parameters TasksRequest) (TasksResponse, int, *errs.Failu // if data.Success == true { // fmt.Printf("%v\n", data.ID) // } -func (c *Client) TaskCreate(task Task, site ...string) (CreateResponse, int, *errs.Failure) { +func (c *Client) TaskCreate(task Task, site ...string) (CreateResponse, int, error) { var resp CreateResponse taskJSON, _ := json.Marshal(&task) @@ -4414,17 +3951,12 @@ func (c *Client) TaskCreate(task Task, site ...string) (CreateResponse, int, *er fillSite(&p, site) data, status, err := c.PostRequest("/tasks/create", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4449,21 +3981,16 @@ func (c *Client) TaskCreate(task Task, site ...string) (CreateResponse, int, *er // if data.Success == true { // fmt.Printf("%v\n", data.Task) // } -func (c *Client) Task(id int) (TaskResponse, int, *errs.Failure) { +func (c *Client) Task(id int) (TaskResponse, int, error) { var resp TaskResponse data, status, err := c.GetRequest(fmt.Sprintf("/tasks/%d", id)) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4487,7 +4014,7 @@ func (c *Client) Task(id int) (TaskResponse, int, *errs.Failure) { // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) TaskEdit(task Task, site ...string) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) TaskEdit(task Task, site ...string) (SuccessfulResponse, int, error) { var resp SuccessfulResponse var uid = strconv.Itoa(task.ID) @@ -4500,15 +4027,15 @@ func (c *Client) TaskEdit(task Task, site ...string) (SuccessfulResponse, int, * fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/tasks/%s/edit", uid), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - buildErr(data, err) - return resp, status, err + a := NewAPIError(data) + return resp, status, a } return resp, status, nil @@ -4535,23 +4062,18 @@ func (c *Client) TaskEdit(task Task, site ...string) (SuccessfulResponse, int, * // for _, value := range data.Groups { // fmt.Printf("%v\n", value) // } -func (c *Client) UserGroups(parameters UserGroupsRequest) (UserGroupsResponse, int, *errs.Failure) { +func (c *Client) UserGroups(parameters UserGroupsRequest) (UserGroupsResponse, int, error) { var resp UserGroupsResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/user-groups?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4576,23 +4098,18 @@ func (c *Client) UserGroups(parameters UserGroupsRequest) (UserGroupsResponse, i // for _, value := range data.Users { // fmt.Printf("%v\n", value) // } -func (c *Client) Users(parameters UsersRequest) (UsersResponse, int, *errs.Failure) { +func (c *Client) Users(parameters UsersRequest) (UsersResponse, int, error) { var resp UsersResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/users?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4617,21 +4134,16 @@ func (c *Client) Users(parameters UsersRequest) (UsersResponse, int, *errs.Failu // if data.Success == true { // fmt.Printf("%v\n", data.User) // } -func (c *Client) User(id int) (UserResponse, int, *errs.Failure) { +func (c *Client) User(id int) (UserResponse, int, error) { var resp UserResponse data, status, err := c.GetRequest(fmt.Sprintf("/users/%d", id)) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4652,7 +4164,7 @@ func (c *Client) User(id int) (UserResponse, int, *errs.Failure) { // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) UserStatus(id int, status string) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) UserStatus(id int, status string) (SuccessfulResponse, int, error) { var resp SuccessfulResponse p := url.Values{ @@ -4660,15 +4172,14 @@ func (c *Client) UserStatus(id int, status string) (SuccessfulResponse, int, *er } data, st, err := c.PostRequest(fmt.Sprintf("/users/%d/status", id), p) - if err.Error() != "" { + if err != nil { return resp, st, err } json.Unmarshal(data, &resp) if resp.Success == false { - buildErr(data, err) - return resp, st, err + return resp, st, NewAPIError(data) } return resp, st, nil @@ -4677,21 +4188,16 @@ func (c *Client) UserStatus(id int, status string) (SuccessfulResponse, int, *er // 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) { +func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, error) { var resp SuccessfulResponse data, status, err := c.GetRequest("/statistic/update") - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4721,24 +4227,19 @@ func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, *errs.Failure) { // for _, value := range data.Costs { // fmt.Printf("%v\n", value.Summ) // } -func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, *errs.Failure) { +func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, error) { var resp CostsResponse params, _ := query.Values(costs) data, status, err := c.GetRequest(fmt.Sprintf("/costs?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4775,7 +4276,7 @@ func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, *errs.Failure) { // If data.Success == true { // fmt.Printf("%v", data.ID) // } -func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, int, *errs.Failure) { +func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, int, error) { var resp CreateResponse costJSON, _ := json.Marshal(&cost) @@ -4787,17 +4288,12 @@ func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, in fillSite(&p, site) data, status, err := c.PostRequest("/costs/create", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4822,7 +4318,7 @@ func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, in // If data.Success == true { // fmt.Printf("Not removed costs: %v", data.NotRemovedIds) // } -func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, *errs.Failure) { +func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, error) { var resp CostsDeleteResponse costJSON, _ := json.Marshal(&ids) @@ -4832,17 +4328,12 @@ func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, *errs.Failure } data, status, err := c.PostRequest("/costs/delete", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4884,7 +4375,7 @@ func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, *errs.Failure // If data.Success == true { // fmt.Printf("Uploaded costs: %v", data.UploadedCosts) // } -func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, *errs.Failure) { +func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, error) { var resp CostsUploadResponse costJSON, _ := json.Marshal(&cost) @@ -4894,17 +4385,12 @@ func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, *errs } data, status, err := c.PostRequest("/costs/upload", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4929,22 +4415,17 @@ func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, *errs // If data.Success == true { // fmt.Printf("%v", data.Cost) // } -func (c *Client) Cost(id int) (CostResponse, int, *errs.Failure) { +func (c *Client) Cost(id int) (CostResponse, int, error) { var resp CostResponse data, status, err := c.GetRequest(fmt.Sprintf("/costs/%d", id)) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -4965,7 +4446,7 @@ func (c *Client) Cost(id int) (CostResponse, int, *errs.Failure) { // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) CostDelete(id int) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) CostDelete(id int) (SuccessfulResponse, int, error) { var resp SuccessfulResponse costJSON, _ := json.Marshal(&id) @@ -4976,17 +4457,12 @@ func (c *Client) CostDelete(id int) (SuccessfulResponse, int, *errs.Failure) { data, status, err := c.PostRequest(fmt.Sprintf("/costs/%d/delete", id), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -5016,7 +4492,7 @@ func (c *Client) CostDelete(id int) (SuccessfulResponse, int, *errs.Failure) { // If data.Success == true { // fmt.Printf("%v", data.Id) // } -func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateResponse, int, *errs.Failure) { +func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateResponse, int, error) { var resp CreateResponse costJSON, _ := json.Marshal(&cost) @@ -5028,17 +4504,12 @@ 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.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -5063,7 +4534,7 @@ func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateRespon // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiError()) // } -func (c *Client) Files(files FilesRequest) (FilesResponse, int, *errs.Failure) { +func (c *Client) Files(files FilesRequest) (FilesResponse, int, error) { var resp FilesResponse params, _ := query.Values(files) @@ -5076,11 +4547,6 @@ func (c *Client) Files(files FilesRequest) (FilesResponse, int, *errs.Failure) { json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -5106,7 +4572,7 @@ func (c *Client) Files(files FilesRequest) (FilesResponse, int, *errs.Failure) { // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.Error()) // } -func (c *Client) FileUpload(reader io.Reader) (FileUploadResponse, int, *errs.Failure) { +func (c *Client) FileUpload(reader io.Reader) (FileUploadResponse, int, error) { var resp FileUploadResponse data, status, err := c.PostRequest("/files/upload", reader, "application/octet-stream") @@ -5117,11 +4583,6 @@ func (c *Client) FileUpload(reader io.Reader) (FileUploadResponse, int, *errs.Fa json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -5146,21 +4607,16 @@ func (c *Client) FileUpload(reader io.Reader) (FileUploadResponse, int, *errs.Fa // if data.Success == true { // fmt.Printf("%v\n", data.File) // } -func (c *Client) File(id int) (FileResponse, int, *errs.Failure) { +func (c *Client) File(id int) (FileResponse, int, error) { var resp FileResponse data, status, err := c.GetRequest(fmt.Sprintf("/files/%d", id)) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -5181,7 +4637,7 @@ func (c *Client) File(id int) (FileResponse, int, *errs.Failure) { // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.Error()) // } -func (c *Client) FileDelete(id int) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) FileDelete(id int) (SuccessfulResponse, int, error) { var resp SuccessfulResponse data, status, err := c.PostRequest(fmt.Sprintf("/files/%d/delete", id), strings.NewReader("")) @@ -5192,11 +4648,6 @@ func (c *Client) FileDelete(id int) (SuccessfulResponse, int, *errs.Failure) { json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -5217,7 +4668,7 @@ func (c *Client) FileDelete(id int) (SuccessfulResponse, int, *errs.Failure) { // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.Error()) // } -func (c *Client) FileDownload(id int) (io.ReadCloser, int, *errs.Failure) { +func (c *Client) FileDownload(id int) (io.ReadCloser, int, error) { data, status, err := c.GetRequest(fmt.Sprintf("/files/%d/download", id)) if status != http.StatusOK { return nil, status, err @@ -5244,13 +4695,15 @@ func (c *Client) FileDownload(id int) (io.ReadCloser, int, *errs.Failure) { // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.Error()) // } -func (c *Client) FileEdit(id int, file File) (FileResponse, int, *errs.Failure) { +func (c *Client) FileEdit(id int, file File) (FileResponse, int, error) { var resp FileResponse req, _ := json.Marshal(file) - data, status, err := c.PostRequest(fmt.Sprintf("/files/%d/edit", id), url.Values{ - "file": {string(req)}, - }) + data, status, err := c.PostRequest( + fmt.Sprintf("/files/%d/edit", id), url.Values{ + "file": {string(req)}, + }, + ) if err != nil && err.Error() != "" { return resp, status, err @@ -5258,11 +4711,6 @@ func (c *Client) FileEdit(id int, file File) (FileResponse, int, *errs.Failure) json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -5290,24 +4738,19 @@ func (c *Client) FileEdit(id int, file File) (FileResponse, int, *errs.Failure) // for _, value := range data.CustomFields { // fmt.Printf("%v\n", value) // } -func (c *Client) CustomFields(customFields CustomFieldsRequest) (CustomFieldsResponse, int, *errs.Failure) { +func (c *Client) CustomFields(customFields CustomFieldsRequest) (CustomFieldsResponse, int, error) { var resp CustomFieldsResponse params, _ := query.Values(customFields) data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -5336,24 +4779,21 @@ func (c *Client) CustomFields(customFields CustomFieldsRequest) (CustomFieldsRes // for _, value := range data.CustomDictionaries { // fmt.Printf("%v\n", value.Elements) // } -func (c *Client) CustomDictionaries(customDictionaries CustomDictionariesRequest) (CustomDictionariesResponse, int, *errs.Failure) { +func (c *Client) CustomDictionaries(customDictionaries CustomDictionariesRequest) ( + CustomDictionariesResponse, int, error, +) { var resp CustomDictionariesResponse params, _ := query.Values(customDictionaries) data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields/dictionaries?%s", params.Encode())) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -5391,7 +4831,7 @@ func (c *Client) CustomDictionaries(customDictionaries CustomDictionariesRequest // If data.Success == true { // fmt.Printf("%v", data.Code) // } -func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (CustomResponse, int, *errs.Failure) { +func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (CustomResponse, int, error) { var resp CustomResponse costJSON, _ := json.Marshal(&customDictionary) @@ -5402,17 +4842,12 @@ func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (Cu data, status, err := c.PostRequest("/custom-fields/dictionaries/create", p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -5437,22 +4872,17 @@ func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (Cu // If data.Success == true { // fmt.Printf("%v", data.CustomDictionary.Name) // } -func (c *Client) CustomDictionary(code string) (CustomDictionaryResponse, int, *errs.Failure) { +func (c *Client) CustomDictionary(code string) (CustomDictionaryResponse, int, error) { var resp CustomDictionaryResponse data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields/dictionaries/%s", code)) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -5490,7 +4920,7 @@ func (c *Client) CustomDictionary(code string) (CustomDictionaryResponse, int, * // If data.Success == true { // fmt.Printf("%v", data.Code) // } -func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (CustomResponse, int, *errs.Failure) { +func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (CustomResponse, int, error) { var resp CustomResponse costJSON, _ := json.Marshal(&customDictionary) @@ -5500,17 +4930,12 @@ func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (Custom } data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/dictionaries/%s/edit", customDictionary.Code), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -5541,7 +4966,7 @@ func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (Custom // If data.Success == true { // fmt.Printf("%v", data.Code) // } -func (c *Client) CustomFieldsCreate(customFields CustomFields) (CustomResponse, int, *errs.Failure) { +func (c *Client) CustomFieldsCreate(customFields CustomFields) (CustomResponse, int, error) { var resp CustomResponse costJSON, _ := json.Marshal(&customFields) @@ -5552,17 +4977,12 @@ func (c *Client) CustomFieldsCreate(customFields CustomFields) (CustomResponse, data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/%s/create", customFields.Entity), p) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -5587,22 +5007,17 @@ func (c *Client) CustomFieldsCreate(customFields CustomFields) (CustomResponse, // If data.Success == true { // fmt.Printf("%v", data.CustomField) // } -func (c *Client) CustomField(entity, code string) (CustomFieldResponse, int, *errs.Failure) { +func (c *Client) CustomField(entity, code string) (CustomFieldResponse, int, error) { var resp CustomFieldResponse data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields/%s/%s", entity, code)) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } @@ -5631,7 +5046,7 @@ func (c *Client) CustomField(entity, code string) (CustomFieldResponse, int, *er // If data.Success == true { // fmt.Printf("%v", data.Code) // } -func (c *Client) CustomFieldEdit(customFields CustomFields) (CustomResponse, int, *errs.Failure) { +func (c *Client) CustomFieldEdit(customFields CustomFields) (CustomResponse, int, error) { var resp CustomResponse costJSON, _ := json.Marshal(&customFields) @@ -5640,18 +5055,15 @@ func (c *Client) CustomFieldEdit(customFields CustomFields) (CustomResponse, int "customField": {string(costJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/%s/%s/edit", customFields.Entity, customFields.Code), p) + data, status, err := c.PostRequest( + fmt.Sprintf("/custom-fields/%s/%s/edit", customFields.Entity, customFields.Code), p, + ) - if err.Error() != "" { + if err != nil { return resp, status, err } json.Unmarshal(data, &resp) - if resp.Success == false { - buildErr(data, err) - return resp, status, err - } - return resp, status, nil } diff --git a/v5/client_test.go b/v5/client_test.go index 0e132a2..c8687d7 100644 --- a/v5/client_test.go +++ b/v5/client_test.go @@ -112,17 +112,13 @@ func TestClient_ApiVersionsVersions(t *testing.T) { Reply(200). BodyString(`{"success": true, "versions" : ["1.0", "4.0", "3.0", "4.0", "5.0"]}`) - data, status, err := c.APIVersions() - if err.Error() != "" { + data, _, err := c.APIVersions() + if err != nil { t.Errorf("%v", err.Error()) } - if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) - } - if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -133,20 +129,16 @@ func TestClient_ApiVersionsVersionsBadUrl(t *testing.T) { gock.New(badURL). Get("/api/api-versions"). - Reply(200). + Reply(400). BodyString(`{"success": false, "errorMsg" : "Account does not exist"}`) - data, status, err := c.APIVersions() - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + data, _, err := c.APIVersions() + if err == nil { + t.Error("Error must be return") } if data.Success != false { - t.Logf("%v", err.ApiError()) + t.Logf("%v", err) } } @@ -160,17 +152,13 @@ func TestClient_ApiCredentialsCredentialsBadKey(t *testing.T) { c := client() - data, status, err := c.APICredentials() - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Logf("%v", err.ApiError()) + data, _, err := c.APICredentials() + if err == nil { + t.Error("Error must be return") } if data.Success != false { - t.Logf("%v", err.ApiError()) + t.Logf("%v", err) } } @@ -184,17 +172,13 @@ func TestClient_ApiCredentialsCredentials(t *testing.T) { c := client() - data, status, err := c.APICredentials() - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + data, _, err := c.APICredentials() + if err != nil { + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -217,16 +201,16 @@ func TestClient_CustomersCustomers(t *testing.T) { Page: 3, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Logf("%v", err.ApiError()) + t.Logf("%v", err) } if data.Success != true { - t.Logf("%v", err.ApiError()) + t.Logf("%v", err) } } @@ -241,18 +225,14 @@ func TestClient_CustomersCustomers_Fail(t *testing.T) { c := client() - data, status, err := c.Customers(CustomersRequest{ + data, _, err := c.Customers(CustomersRequest{ Filter: CustomersFilter{ Ids: []string{codeFail}, }, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -296,16 +276,16 @@ func TestClient_CustomerChange(t *testing.T) { BodyString(`{"success": true, "id": 123}`) cr, sc, err := c.CustomerCreate(f) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if sc != http.StatusCreated { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if cr.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } f.ID = cr.ID @@ -326,16 +306,16 @@ func TestClient_CustomerChange(t *testing.T) { BodyString(`{"success": true}`) ed, se, err := c.CustomerEdit(f, ByID) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if se != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if ed.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } gock.New(crmURL). @@ -360,21 +340,17 @@ func TestClient_CustomerChange(t *testing.T) { } }`) - data, status, err := c.Customer(f.ExternalID, ByExternalID, "") - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + data, _, err := c.Customer(f.ExternalID, ByExternalID, "") + if err != nil { + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if !reflect.DeepEqual(data.Customer.Tags, f.Tags) { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -401,8 +377,8 @@ func TestClient_CustomerChange_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Parameter 'externalId' in 'customer' is missing"}`) cr, sc, err := c.CustomerCreate(f) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if sc < http.StatusBadRequest { @@ -431,8 +407,8 @@ func TestClient_CustomerChange_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Not found"}`) ed, se, err := c.CustomerEdit(f, ByID) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if se < http.StatusBadRequest { @@ -449,13 +425,9 @@ func TestClient_CustomerChange_Fail(t *testing.T) { Reply(404). BodyString(`{"success": false, "errorMsg": "Not found"}`) - data, status, err := c.Customer(codeFail, ByExternalID, "") - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.Customer(codeFail, ByExternalID, "") + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -492,16 +464,16 @@ func TestClient_CustomersUpload(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.CustomersUpload(customers) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -524,13 +496,9 @@ func TestClient_CustomersUpload_Fail(t *testing.T) { Reply(460). BodyString(`{"success": false, "errorMsg": "Customers are loaded with errors"}`) - data, status, err := c.CustomersUpload(customers) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.CustomersUpload(customers) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -562,16 +530,16 @@ func TestClient_CustomersCombine(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.CustomersCombine(customers, resultCustomer) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -598,13 +566,9 @@ func TestClient_CustomersCombine_Fail(t *testing.T) { Reply(400). BodyString(`{"success": false, "errorMsg": "Invalid input parameters"}`) - data, status, err := c.CustomersCombine([]Customer{{}, {}}, Customer{}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.CustomersCombine([]Customer{{}, {}}, Customer{}) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -636,16 +600,16 @@ func TestClient_CustomersFixExternalIds(t *testing.T) { BodyString(`{"success": true}`) fx, fe, err := c.CustomersFixExternalIds(customers) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if fe != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if fx.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -669,13 +633,9 @@ func TestClient_CustomersFixExternalIds_Fail(t *testing.T) { 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.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.CustomersFixExternalIds(customers) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -699,16 +659,16 @@ func TestClient_CustomersHistory(t *testing.T) { BodyString(`{"success": true, "history": [{"id": 1}]}`) data, status, err := c.CustomersHistory(f) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if len(data.History) == 0 { @@ -732,13 +692,9 @@ func TestClient_CustomersHistory_Fail(t *testing.T) { Reply(400). BodyString(`{"success": false, "errorMsg": "Errors in the input parameters", "errors": {"children[startDate]": "Значение недопустимо."}}`) - data, status, err := c.CustomersHistory(f) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.CustomersHistory(f) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -765,16 +721,16 @@ func TestClient_CorporateCustomersList(t *testing.T) { Page: 3, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Logf("%v", err.ApiError()) + t.Logf("%v", err) } if data.Success != true { - t.Logf("%v", err.ApiError()) + t.Logf("%v", err) } } @@ -861,16 +817,16 @@ func TestClient_CorporateCustomersCreate(t *testing.T) { data, status, err := c.CorporateCustomerCreate(customer, "site") - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusCreated { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -898,16 +854,16 @@ func TestClient_CorporateCustomersFixExternalIds(t *testing.T) { BodyString(`{"success": true}`) fx, fe, err := c.CorporateCustomersFixExternalIds(customers) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if fe != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if fx.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -931,13 +887,9 @@ func TestClient_CorporateCustomersFixExternalIds_Fail(t *testing.T) { Reply(400). BodyString(`{"success": false, "errorMsg": "Errors in the input parameters", "errors": {"id": "ID must be an integer"}}`) - data, status, err := c.CorporateCustomersFixExternalIds(customers) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.CorporateCustomersFixExternalIds(customers) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -961,16 +913,16 @@ func TestClient_CorporateCustomersHistory(t *testing.T) { BodyString(`{"success": true, "history": [{"id": 1}]}`) data, status, err := c.CorporateCustomersHistory(f) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if len(data.History) == 0 { @@ -994,13 +946,9 @@ func TestClient_CorporateCustomersHistory_Fail(t *testing.T) { Reply(400). BodyString(`{"success": false, "errorMsg": "Errors in the input parameters", "errors": {"children[startDate]": "Значение недопустимо."}}`) - data, status, err := c.CorporateCustomersHistory(f) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.CorporateCustomersHistory(f) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -1049,16 +997,16 @@ func TestClient_CorporateCustomersNotes(t *testing.T) { }, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Notes[0].Text != "

sample text

" { @@ -1083,16 +1031,16 @@ func TestClient_CorporateCustomerNoteCreate(t *testing.T) { }, }, "site") - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.ID != 1 { @@ -1112,16 +1060,16 @@ func TestClient_CorporateCustomerNoteDelete(t *testing.T) { data, status, err := c.CorporateCustomerNoteDelete(1) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -1152,16 +1100,16 @@ func TestClient_CorporateCustomersUpload(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.CorporateCustomersUpload(customers) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -1184,13 +1132,9 @@ func TestClient_CorporateCustomersUpload_Fail(t *testing.T) { Reply(460). BodyString(`{"success": false, "errorMsg": "Customers are loaded with errors"}`) - data, status, err := c.CorporateCustomersUpload(customers) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.CorporateCustomersUpload(customers) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -1242,16 +1186,16 @@ func TestClient_CorporateCustomer(t *testing.T) { `) data, status, err := c.CorporateCustomer("ext-id", ByExternalID, "site") - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -1301,16 +1245,16 @@ func TestClient_CorporateCustomerAddresses(t *testing.T) { Page: 1, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if len(data.Addresses) == 0 { @@ -1333,16 +1277,16 @@ func TestClient_CorporateCustomerAddressesCreate(t *testing.T) { Name: "New Address", }, "site") - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -1367,16 +1311,16 @@ func TestClient_CorporateCustomerAddressesEdit(t *testing.T) { "site", ) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -1462,16 +1406,16 @@ func TestClient_CorporateCustomerCompanies(t *testing.T) { Page: 1, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if len(data.Companies) == 0 { @@ -1493,16 +1437,16 @@ func TestClient_CorporateCustomerCompaniesCreate(t *testing.T) { Name: "New Company", }, "site") - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -1527,16 +1471,16 @@ func TestClient_CorporateCustomerCompaniesEdit(t *testing.T) { "site", ) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -1578,16 +1522,16 @@ func TestClient_CorporateCustomerContacts(t *testing.T) { Page: 1, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if len(data.Contacts) == 0 { @@ -1616,16 +1560,16 @@ func TestClient_CorporateCustomerContactsCreate(t *testing.T) { LastName: "Person", }, "site") - if createErr.Error() != "" { - t.Errorf("%v", createErr.Error()) + if createErr != nil { + t.Errorf("%v", createErr) } if createStatus >= http.StatusBadRequest { - t.Errorf("%v", createErr.ApiError()) + t.Errorf("%v", createErr) } if createResponse.Success != true { - t.Errorf("%v", createErr.ApiError()) + t.Errorf("%v", createErr) } if createResponse.ID != 2 { @@ -1641,16 +1585,16 @@ func TestClient_CorporateCustomerContactsCreate(t *testing.T) { Companies: []IdentifiersPair{}, }, "site") - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.ID != 3 { @@ -1675,16 +1619,16 @@ func TestClient_CorporateCustomerContactsEdit(t *testing.T) { }, }, "site") - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("(%d) %v", status, err.ApiError()) + t.Errorf("(%d) %v", status, err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.ID == 0 { @@ -1708,16 +1652,16 @@ func TestClient_CorporateCustomerEdit(t *testing.T) { Vip: true, }, ByExternalID, "site") - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("(%d) %v", status, err.ApiError()) + t.Errorf("(%d) %v", status, err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -1733,20 +1677,20 @@ func TestClient_NotesNotes(t *testing.T) { BodyString(`{"success": true, "notes": [{"id": 1}]}`) data, status, err := c.CustomerNotes(NotesRequest{Page: 1}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if len(data.Notes) == 0 { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -1761,15 +1705,11 @@ func TestClient_NotesNotes_Fail(t *testing.T) { 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{ + data, _, err := c.CustomerNotes(NotesRequest{ Filter: NotesFilter{CreatedAtFrom: "2020-13-12"}, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -1804,16 +1744,16 @@ func TestClient_NotesCreateDelete(t *testing.T) { BodyString(`{"success": true, "id": 1}`) noteCreateResponse, noteCreateStatus, err := c.CustomerNoteCreate(note) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if noteCreateStatus != http.StatusCreated { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if noteCreateResponse.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } p = url.Values{ @@ -1828,17 +1768,17 @@ func TestClient_NotesCreateDelete(t *testing.T) { BodyString(`{"success": true}`) noteDeleteResponse, noteDeleteStatus, err := c.CustomerNoteDelete(noteCreateResponse.ID) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if noteDeleteStatus != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if noteDeleteResponse.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -1865,13 +1805,9 @@ func TestClient_NotesCreateDelete_Fail(t *testing.T) { 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.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.CustomerNoteCreate(note) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -1890,8 +1826,8 @@ func TestClient_NotesCreateDelete_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Note not found map"}`) noteDeleteResponse, noteDeleteStatus, err := c.CustomerNoteDelete(iCodeFail) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if noteDeleteStatus < http.StatusBadRequest { @@ -1916,17 +1852,17 @@ func TestClient_OrdersOrders(t *testing.T) { BodyString(`{"success": true, "orders": [{"id": 1}]}`) data, status, err := c.Orders(OrdersRequest{Filter: OrdersFilter{City: "Москва"}, Page: 1}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -1941,13 +1877,9 @@ func TestClient_OrdersOrders_Fail(t *testing.T) { Reply(400). 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.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.Orders(OrdersRequest{Filter: OrdersFilter{Attachments: 7}}) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -2060,16 +1992,16 @@ func TestClient_OrderChange(t *testing.T) { }`) cr, sc, err := c.OrderCreate(f) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if sc != http.StatusCreated { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if cr.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if cr.Order.Number != "1A" { @@ -2094,16 +2026,16 @@ func TestClient_OrderChange(t *testing.T) { BodyString(`{"success": true}`) ed, se, err := c.OrderEdit(f, ByID) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if se != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if ed.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } gock.New(crmURL). @@ -2113,16 +2045,16 @@ func TestClient_OrderChange(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.Order(f.ExternalID, ByExternalID, "") - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -2156,13 +2088,9 @@ func TestClient_OrderChange_Fail(t *testing.T) { Reply(404). BodyString(`{"success": false, "errorMsg": "Not found map"}`) - data, status, err := c.OrderEdit(f, ByID) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.OrderEdit(f, ByID) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -2199,17 +2127,17 @@ func TestClient_OrdersUpload(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.OrdersUpload(orders) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -2240,13 +2168,9 @@ func TestClient_OrdersUpload_Fail(t *testing.T) { Reply(460). BodyString(`{"success": false, "errorMsg": "Orders are loaded with errors"}`) - data, status, err := c.OrdersUpload(orders) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.OrdersUpload(orders) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -2275,17 +2199,17 @@ func TestClient_OrdersCombine(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.OrdersCombine("ours", Order{ID: 1}, Order{ID: 2}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -2308,13 +2232,9 @@ func TestClient_OrdersCombine_Fail(t *testing.T) { Reply(400). BodyString(`{"success": false, "errorMsg": "Invalid input parameters"}`) - data, status, err := c.OrdersCombine("ours", Order{}, Order{}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.OrdersCombine("ours", Order{}, Order{}) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -2345,17 +2265,17 @@ func TestClient_OrdersFixExternalIds(t *testing.T) { BodyString(`{"success": true}`) fx, fe, err := c.OrdersFixExternalIds(orders) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if fe != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if fx.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -2377,13 +2297,9 @@ func TestClient_OrdersFixExternalIds_Fail(t *testing.T) { Reply(400). BodyString(`{"success": false, "errorMsg": "Invalid input parameters"}`) - data, status, err := c.OrdersFixExternalIds(orders) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.OrdersFixExternalIds(orders) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -2423,20 +2339,20 @@ func TestClient_OrdersStatuses(t *testing.T) { IDs: []int{1}, ExternalIDs: []string{"2"}, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if len(data.Orders) == 0 { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -2452,21 +2368,21 @@ func TestClient_OrdersHistory(t *testing.T) { BodyString(`{"success": true, "history": [{"id": 1}]}`) data, status, err := c.OrdersHistory(OrdersHistoryRequest{Filter: OrdersHistoryFilter{SinceID: 20}}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if len(data.History) == 0 { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -2481,13 +2397,9 @@ func TestClient_OrdersHistory_Fail(t *testing.T) { 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.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.OrdersHistory(OrdersHistoryRequest{Filter: OrdersHistoryFilter{StartDate: "2020-13-12"}}) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -2521,16 +2433,16 @@ func TestClient_PaymentCreateEditDelete(t *testing.T) { BodyString(`{"success": true, "id": 1}`) paymentCreateResponse, status, err := c.OrderPaymentCreate(f) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusCreated { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if paymentCreateResponse.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } k := Payment{ @@ -2551,16 +2463,16 @@ func TestClient_PaymentCreateEditDelete(t *testing.T) { BodyString(`{"success": true}`) paymentEditResponse, status, err := c.OrderPaymentEdit(k, ByID) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if paymentEditResponse.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } p = url.Values{ @@ -2575,16 +2487,16 @@ func TestClient_PaymentCreateEditDelete(t *testing.T) { BodyString(`{"success": true}`) paymentDeleteResponse, status, err := c.OrderPaymentDelete(paymentCreateResponse.ID) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if paymentDeleteResponse.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -2611,13 +2523,9 @@ func TestClient_PaymentCreateEditDelete_Fail(t *testing.T) { 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.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.OrderPaymentCreate(f) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -2642,8 +2550,8 @@ func TestClient_PaymentCreateEditDelete_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Payment not found"}`) paymentEditResponse, status, err := c.OrderPaymentEdit(k, ByID) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if status < http.StatusBadRequest { @@ -2666,12 +2574,8 @@ func TestClient_PaymentCreateEditDelete_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Payment not found"}`) paymentDeleteResponse, status, err := c.OrderPaymentDelete(iCodeFail) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + if err == nil { + t.Error("Error must be return") } if paymentDeleteResponse.Success != false { @@ -2698,16 +2602,16 @@ func TestClient_TasksTasks(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.Tasks(f) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -2727,13 +2631,9 @@ func TestClient_TasksTasks_Fail(t *testing.T) { Reply(400). BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) - data, status, err := c.Tasks(f) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.Tasks(f) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -2763,16 +2663,16 @@ func TestClient_TaskChange(t *testing.T) { BodyString(`{"success": true, "id": 1}`) cr, sc, err := c.TaskCreate(f) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if sc != http.StatusCreated { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if cr.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } f.ID = cr.ID @@ -2784,16 +2684,16 @@ func TestClient_TaskChange(t *testing.T) { BodyString(`{"success": true}`) gt, sg, err := c.Task(f.ID) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if sg != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if gt.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } jr, _ = json.Marshal(f) @@ -2809,17 +2709,17 @@ func TestClient_TaskChange(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.TaskEdit(f) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -2845,13 +2745,9 @@ func TestClient_TaskChange_Fail(t *testing.T) { Reply(400). BodyString(`{"success": false, "errorMsg": "Task is not loaded", "errors": {"performerId": "This value should not be blank."}}`) - data, status, err := c.TaskEdit(f) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.TaskEdit(f) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -2872,17 +2768,17 @@ func TestClient_UsersUsers(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.Users(UsersRequest{Filter: UsersFilter{Active: 1}, Page: 1}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -2898,13 +2794,9 @@ func TestClient_UsersUsers_Fail(t *testing.T) { 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.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.Users(UsersRequest{Filter: UsersFilter{Active: 3}, Page: 1}) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -2923,17 +2815,17 @@ func TestClient_UsersUser(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.User(user) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -2947,13 +2839,9 @@ func TestClient_UsersUser_Fail(t *testing.T) { Reply(404). BodyString(`{"success": false, "errorMsg": "Not found"}`) - data, status, err := c.User(iCodeFail) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.User(iCodeFail) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -2973,16 +2861,16 @@ func TestClient_UsersGroups(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.UserGroups(UserGroupsRequest{Page: 1}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3003,17 +2891,16 @@ func TestClient_UsersUpdate(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.UserStatus(user, "busy") - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3033,13 +2920,9 @@ func TestClient_UsersUpdate_Fail(t *testing.T) { Reply(404). BodyString(`{"success": false, "errorMsg": "Not found"}`) - data, status, err := c.UserStatus(iCodeFail, "busy") - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.UserStatus(iCodeFail, "busy") + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -3058,16 +2941,16 @@ func TestClient_StaticticsUpdate(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.StaticticsUpdate() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3082,16 +2965,16 @@ func TestClient_Countries(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.Couriers() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3106,16 +2989,16 @@ func TestClient_CostGroups(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.CostGroups() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3130,16 +3013,16 @@ func TestClient_CostItems(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.CostItems() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3154,16 +3037,16 @@ func TestClient_Couriers(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.Couriers() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3178,16 +3061,16 @@ func TestClient_DeliveryService(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.DeliveryServices() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3202,16 +3085,16 @@ func TestClient_DeliveryTypes(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.DeliveryTypes() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3226,16 +3109,16 @@ func TestClient_LegalEntities(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.LegalEntities() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3250,16 +3133,16 @@ func TestClient_OrderMethods(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.OrderMethods() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3285,16 +3168,16 @@ func TestClient_OrderPaymentEdit(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.OrderPaymentEdit(payment, "externalId") - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3309,16 +3192,16 @@ func TestClient_OrderTypes(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.OrderTypes() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3333,16 +3216,16 @@ func TestClient_PaymentStatuses(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.PaymentStatuses() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3357,16 +3240,16 @@ func TestClient_PaymentTypes(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.PaymentTypes() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3381,16 +3264,16 @@ func TestClient_PriceTypes(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.PriceTypes() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3405,16 +3288,16 @@ func TestClient_ProductStatuses(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.ProductStatuses() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3429,16 +3312,16 @@ func TestClient_Statuses(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.Statuses() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3453,16 +3336,16 @@ func TestClient_StatusGroups(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.StatusGroups() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3477,16 +3360,16 @@ func TestClient_Sites(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.Sites() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3501,16 +3384,16 @@ func TestClient_Stores(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.Stores() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3542,16 +3425,16 @@ func TestClient_CostGroupItemEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.CostGroupEdit(costGroup) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[st] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } costItem := CostItem{ @@ -3577,17 +3460,17 @@ func TestClient_CostGroupItemEdit(t *testing.T) { BodyString(`{"success": true}`) idata, st, err := c.CostItemEdit(costItem) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[st] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if idata.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3616,13 +3499,9 @@ func TestClient_CostGroupItemEdit_Fail(t *testing.T) { Reply(400). BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) - data, status, err := c.CostGroupEdit(costGroup) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.CostGroupEdit(costGroup) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -3652,8 +3531,8 @@ func TestClient_CostGroupItemEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) idata, st, err := c.CostItemEdit(costItem) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if st < http.StatusBadRequest { @@ -3691,16 +3570,16 @@ func TestClient_Courier(t *testing.T) { BodyString(`{"success": true, "id": 1}`) data, st, err := c.CourierCreate(cur) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[st] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } cur.ID = data.ID @@ -3720,17 +3599,17 @@ func TestClient_Courier(t *testing.T) { BodyString(`{"success": true}`) idata, st, err := c.CourierEdit(cur) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[st] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if idata.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3753,8 +3632,8 @@ func TestClient_Courier_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the entity format", "errors": {"firstName": "Specify the first name"}}`) data, st, err := c.CourierCreate(Courier{}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if st < http.StatusBadRequest { @@ -3780,8 +3659,8 @@ func TestClient_Courier_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "An attempt was made to edit a nonexistent record"}`) idata, st, err := c.CourierEdit(cur) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if st < http.StatusBadRequest { @@ -3818,17 +3697,17 @@ func TestClient_DeliveryServiceEdit(t *testing.T) { BodyString(`{"success": true, "id": 1}`) data, st, err := c.DeliveryServiceEdit(deliveryService) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[st] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3855,8 +3734,8 @@ func TestClient_DeliveryServiceEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.DeliveryServiceEdit(deliveryService) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if st < http.StatusBadRequest { @@ -3898,17 +3777,17 @@ func TestClient_DeliveryTypeEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.DeliveryTypeEdit(deliveryType) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[st] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -3939,8 +3818,8 @@ func TestClient_DeliveryTypeEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.DeliveryTypeEdit(deliveryType) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if st < http.StatusBadRequest { @@ -3977,17 +3856,17 @@ func TestClient_OrderMethodEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.OrderMethodEdit(orderMethod) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[st] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -4015,8 +3894,8 @@ func TestClient_OrderMethodEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.OrderMethodEdit(orderMethod) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if st < http.StatusBadRequest { @@ -4054,17 +3933,17 @@ func TestClient_OrderTypeEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.OrderTypeEdit(orderType) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[st] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -4091,8 +3970,8 @@ func TestClient_OrderTypeEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.OrderTypeEdit(orderType) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if st < http.StatusBadRequest { @@ -4132,17 +4011,17 @@ func TestClient_PaymentStatusEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.PaymentStatusEdit(paymentStatus) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[st] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -4172,8 +4051,8 @@ func TestClient_PaymentStatusEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.PaymentStatusEdit(paymentStatus) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if st < http.StatusBadRequest { @@ -4210,17 +4089,17 @@ func TestClient_PaymentTypeEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.PaymentTypeEdit(paymentType) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[st] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -4248,8 +4127,8 @@ func TestClient_PaymentTypeEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.PaymentTypeEdit(paymentType) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if st < http.StatusBadRequest { @@ -4285,16 +4164,16 @@ func TestClient_PriceTypeEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.PriceTypeEdit(priceType) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[st] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -4321,8 +4200,8 @@ func TestClient_PriceTypeEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.PriceTypeEdit(priceType) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if st < http.StatusBadRequest { @@ -4359,16 +4238,16 @@ func TestClient_ProductStatusEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.ProductStatusEdit(productStatus) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[st] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -4396,8 +4275,8 @@ func TestClient_ProductStatusEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.ProductStatusEdit(productStatus) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if st < http.StatusBadRequest { @@ -4434,17 +4313,17 @@ func TestClient_StatusEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.StatusEdit(status) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[st] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -4473,8 +4352,8 @@ func TestClient_StatusEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.StatusEdit(status) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if st < http.StatusBadRequest { @@ -4511,12 +4390,12 @@ func TestClient_SiteEdit(t *testing.T) { BodyString(`{"success": true}`) data, _, err := c.SiteEdit(site) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if data.Success == false { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -4545,8 +4424,8 @@ func TestClient_SiteEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Method Not Allowed"}`) data, _, err := c.SiteEdit(site) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -4581,16 +4460,16 @@ func TestClient_StoreEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.StoreEdit(store) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[st] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -4620,8 +4499,8 @@ func TestClient_StoreEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.StoreEdit(store) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if st < http.StatusBadRequest { @@ -4644,16 +4523,16 @@ func TestClient_Units(t *testing.T) { BodyString(`{"success": true, "units": []}`) data, st, err := c.Units() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if st != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -4684,16 +4563,16 @@ func TestClient_UnitsEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.UnitEdit(unit) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[st] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -4721,8 +4600,8 @@ func TestClient_UnitEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Method not found"}`) data, st, err := c.UnitEdit(unit) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if st < http.StatusBadRequest { @@ -4758,16 +4637,16 @@ func TestClient_PackChange(t *testing.T) { BodyString(`{"success": true, "id": 1}`) p, status, err := c.PackCreate(pack) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusCreated { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if p.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } gock.New(crmURL). @@ -4776,16 +4655,16 @@ func TestClient_PackChange(t *testing.T) { BodyString(`{"success": true}`) s, status, err := c.Pack(p.ID) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if s.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } jr, _ = json.Marshal(&Pack{ID: p.ID, Quantity: 2}) @@ -4802,16 +4681,16 @@ func TestClient_PackChange(t *testing.T) { BodyString(`{"success": true}`) e, status, err := c.PackEdit(Pack{ID: p.ID, Quantity: 2}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if e.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } gock.New(crmURL). @@ -4821,16 +4700,16 @@ func TestClient_PackChange(t *testing.T) { BodyString(`{"success": true}`) d, status, err := c.PackDelete(p.ID) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if d.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -4859,8 +4738,8 @@ func TestClient_PackChange_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the entity format"}`) p, status, err := c.PackCreate(pack) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Errorf("%v", err) } if status < http.StatusBadRequest { @@ -4877,12 +4756,8 @@ func TestClient_PackChange_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the entity format"}`) s, status, err := c.Pack(iCodeFail) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + if err == nil { + t.Error("Error must be return") } if s.Success != false { @@ -4903,12 +4778,8 @@ func TestClient_PackChange_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Pack with id 123123 not found"}`) e, status, err := c.PackEdit(Pack{ID: iCodeFail, Quantity: 2}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + if err == nil { + t.Error("Error must be return") } if e.Success != false { @@ -4922,12 +4793,8 @@ func TestClient_PackChange_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Pack not found"}`) d, status, err := c.PackDelete(iCodeFail) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + if err == nil { + t.Errorf("%v", err) } if d.Success != false { @@ -4947,21 +4814,21 @@ func TestClient_PacksHistory(t *testing.T) { BodyString(`{"success": true, "history": [{"id": 1}]}`) data, status, err := c.PacksHistory(PacksHistoryRequest{Filter: OrdersHistoryFilter{SinceID: 5}}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if len(data.History) == 0 { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -4976,13 +4843,9 @@ func TestClient_PacksHistory_Fail(t *testing.T) { 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.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.PacksHistory(PacksHistoryRequest{Filter: OrdersHistoryFilter{StartDate: "2020-13-12"}}) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -5002,17 +4865,17 @@ func TestClient_Packs(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.Packs(PacksRequest{Filter: PacksFilter{}, Page: 1}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -5027,13 +4890,9 @@ func TestClient_Packs_Fail(t *testing.T) { 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.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.Packs(PacksRequest{Filter: PacksFilter{ShipmentDateFrom: "2020-13-12"}}) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -5054,17 +4913,17 @@ func TestClient_Inventories(t *testing.T) { BodyString(`{"success": true, "id": 1}`) data, status, err := c.Inventories(InventoriesRequest{Filter: InventoriesFilter{Details: 1}, Page: 1}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -5079,13 +4938,9 @@ func TestClient_Inventories_Fail(t *testing.T) { Reply(400). BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) - data, status, err := c.Inventories(InventoriesRequest{Filter: InventoriesFilter{Sites: []string{codeFail}}}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.Inventories(InventoriesRequest{Filter: InventoriesFilter{Sites: []string{codeFail}}}) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -5104,17 +4959,17 @@ func TestClient_Segments(t *testing.T) { BodyString(`{"success": true, "id": 1}`) data, status, err := c.Segments(SegmentsRequest{}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -5146,16 +5001,16 @@ func TestClient_Settings(t *testing.T) { `) data, status, err := c.Settings() - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status >= http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Settings.DefaultCurrency.Value != "RUB" { @@ -5182,13 +5037,9 @@ func TestClient_Segments_Fail(t *testing.T) { Reply(400). BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) - data, status, err := c.Segments(SegmentsRequest{Filter: SegmentsFilter{Active: 3}}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.Segments(SegmentsRequest{Filter: SegmentsFilter{Active: 3}}) + if err == nil { + t.Error("Error must be return") } if data.Success != false { @@ -5229,16 +5080,16 @@ func TestClient_IntegrationModule(t *testing.T) { BodyString(`{"success": true}`) m, status, err := c.IntegrationModuleEdit(integrationModule) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusCreated { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if m.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } gock.New(crmURL). @@ -5247,16 +5098,16 @@ func TestClient_IntegrationModule(t *testing.T) { BodyString(`{"success": true}`) g, status, err := c.IntegrationModule(code) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if g.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -5292,8 +5143,8 @@ func TestClient_IntegrationModule_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) m, status, err := c.IntegrationModuleEdit(integrationModule) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if status < http.StatusBadRequest { @@ -5310,12 +5161,8 @@ func TestClient_IntegrationModule_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) g, status, err := c.IntegrationModule(code) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + if err == nil { + t.Error("Error must be return") } if g.Success != false { @@ -5339,17 +5186,17 @@ func TestClient_ProductsGroup(t *testing.T) { Active: 1, }, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if g.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -5369,8 +5216,8 @@ func TestClient_ProductsGroup_Fail(t *testing.T) { Active: 3, }, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if status < http.StatusBadRequest { @@ -5400,17 +5247,17 @@ func TestClient_Products(t *testing.T) { MinPrice: 1, }, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if g.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -5428,8 +5275,8 @@ func TestClient_Products_Fail(t *testing.T) { g, status, err := c.Products(ProductsRequest{ Filter: ProductsFilter{Active: 3}, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if status < http.StatusBadRequest { @@ -5460,16 +5307,16 @@ func TestClient_ProductsProperties(t *testing.T) { Sites: sites, }, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if g.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -5497,16 +5344,16 @@ func TestClient_DeliveryTracking(t *testing.T) { }}, }}, "subcode") - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if g.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -5526,16 +5373,16 @@ func TestClient_DeliveryShipments(t *testing.T) { DateFrom: "2017-10-10", }, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if g.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -5555,8 +5402,8 @@ func TestClient_DeliveryShipments_Fail(t *testing.T) { Stores: []string{codeFail}, }, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Error("Error must be return") } if status < http.StatusBadRequest { @@ -5595,16 +5442,16 @@ func TestClient_Cost(t *testing.T) { data, status, err := c.CostCreate(costRecord) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[status] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } id := data.ID @@ -5625,16 +5472,16 @@ func TestClient_Cost(t *testing.T) { Page: 1, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[status] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if costs.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } gock.New(crmURL). @@ -5644,16 +5491,16 @@ func TestClient_Cost(t *testing.T) { cost, status, err := c.Cost(id) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[status] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if cost.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } costRecord.DateFrom = "2018-04-09" @@ -5675,16 +5522,16 @@ func TestClient_Cost(t *testing.T) { costEdit, status, err := c.CostEdit(id, costRecord) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[status] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if costEdit.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } j, _ := json.Marshal(&id) @@ -5702,16 +5549,16 @@ func TestClient_Cost(t *testing.T) { costDelete, status, err := c.CostDelete(id) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[status] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if costDelete.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -5740,17 +5587,13 @@ func TestClient_Cost_Fail(t *testing.T) { Reply(400). BodyString(`{"success": false, "errorMsg": "Cost is not loaded"}`) - data, status, err := c.CostCreate(costRecord) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + data, _, err := c.CostCreate(costRecord) + if err == nil { + t.Error("Error must be return") } - if status < http.StatusBadRequest { - t.Error(statusFail) - } - - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Errorf("%v", err) } id := data.ID @@ -5764,8 +5607,8 @@ func TestClient_Cost_Fail(t *testing.T) { costs, status, err := c.Costs(CostsRequest{ Filter: CostsFilter{Sites: []string{codeFail}}, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Errorf("%v", err) } if status < http.StatusBadRequest { @@ -5782,12 +5625,8 @@ func TestClient_Cost_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Not found"}`) cost, status, err := c.Cost(id) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + if err == nil { + t.Errorf("%v", err) } if cost.Success != false { @@ -5813,12 +5652,8 @@ func TestClient_Cost_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Cost is not loaded"}`) costEdit, status, err := c.CostEdit(id, costRecord) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + if err == nil { + t.Errorf("%v", err) } if costEdit.Success != false { @@ -5838,12 +5673,8 @@ func TestClient_Cost_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Not found"}`) costDelete, status, err := c.CostDelete(id) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + if err == nil { + t.Errorf("%v", err) } if costDelete.Success != false { @@ -5891,17 +5722,17 @@ func TestClient_CostsUpload(t *testing.T) { data, status, err := c.CostsUpload(costsUpload) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[status] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } ids := data.UploadedCosts @@ -5920,17 +5751,17 @@ func TestClient_CostsUpload(t *testing.T) { BodyString(`{"success": true}`) costsDelete, status, err := c.CostsDelete(ids) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[status] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if costsDelete.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -5964,13 +5795,9 @@ func TestClient_CostsUpload_Fail(t *testing.T) { Reply(460). BodyString(`{"success": false, "errorMsg": "Costs are loaded with errors"}`) - data, status, err := c.CostsUpload(costsUpload) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.CostsUpload(costsUpload) + if err == nil { + t.Errorf("%v", err) } if data.Success != false { @@ -5993,8 +5820,8 @@ func TestClient_CostsUpload_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Expected array, but got NULL: null"}`) costsDelete, status, err := c.CostsDelete(ids) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Errorf("%v", err) } if status < http.StatusBadRequest { @@ -6029,7 +5856,7 @@ func TestClient_Files(t *testing.T) { }) if status != 200 { - t.Errorf("%v %v", err.Error(), err.ApiError()) + t.Errorf("%v %v", err.Error(), err) } } @@ -6045,16 +5872,16 @@ func TestClient_FileUpload(t *testing.T) { BodyString(`{"success": true, "file": {"id": 1}}`) data, status, err := c.FileUpload(file) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.File.ID != 1 { @@ -6074,8 +5901,8 @@ func TestClient_FileUploadFail(t *testing.T) { BodyString(`{"success":false,"errorMsg":"Your account doesn't have enough money to upload files."}`) _, status, err := c.FileUpload(file) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Errorf("%v", err) } if status != http.StatusBadRequest { @@ -6115,16 +5942,16 @@ func TestClient_File(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Not Found"}`) s, status, err := c.File(fileResponse.File.ID) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if s.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if s.File.ID != fileResponse.File.ID { @@ -6132,8 +5959,8 @@ func TestClient_File(t *testing.T) { } s, status, err = c.File(invalidFile) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Errorf("%v", err) } if status != http.StatusNotFound { @@ -6165,34 +5992,26 @@ func TestClient_FileDelete(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Not Found"}`) data, status, err := c.FileDelete(successful) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } - data, status, err = c.FileDelete(badRequest) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + data, _, err = c.FileDelete(badRequest) + if err == nil { + t.Errorf("%v", err) } - if status != http.StatusBadRequest { - t.Errorf("status should be `%d`, got `%d` instead", http.StatusBadRequest, status) - } - - data, status, err = c.FileDelete(notFound) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status != http.StatusNotFound { - t.Errorf("status should be `%d`, got `%d` instead", http.StatusNotFound, status) + data, _, err = c.FileDelete(notFound) + if err == nil { + t.Errorf("%v", err) } } @@ -6215,17 +6034,17 @@ func TestClient_FileDownload(t *testing.T) { BodyString("") data, status, err := c.FileDownload(successful) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } - fetchedByte, errr := ioutil.ReadAll(data) - if errr != nil { - t.Error(errr) + fetchedByte, err := ioutil.ReadAll(data) + if err != nil { + t.Error(err) } fetched := string(fetchedByte) @@ -6234,8 +6053,8 @@ func TestClient_FileDownload(t *testing.T) { } data, status, err = c.FileDownload(fail) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Errorf("%v", err) } if status != http.StatusBadRequest { @@ -6266,25 +6085,25 @@ func TestClient_FileEdit(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Not Found"}`) data, status, err := c.FileEdit(successful, *resp.File) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if status != http.StatusOK { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.File.Filename != resp.File.Filename { t.Errorf("filename should be `%s`, got `%s` instead", resp.File.Filename, data.File.Filename) } - data, status, err = c.FileEdit(fail, *resp.File) - if status != http.StatusNotFound { - t.Errorf("status should be `%d`, got `%d` instead", http.StatusNotFound, status) + data, _, err = c.FileEdit(fail, *resp.File) + if err == nil { + t.Errorf("%v", err) } } @@ -6300,16 +6119,16 @@ func TestClient_CustomFields(t *testing.T) { data, status, err := c.CustomFields(CustomFieldsRequest{}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[status] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -6324,13 +6143,9 @@ func TestClient_CustomFields_Fail(t *testing.T) { Reply(400). BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) - data, status, err := c.CustomFields(CustomFieldsRequest{Filter: CustomFieldsFilter{Type: codeFail}}) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.CustomFields(CustomFieldsRequest{Filter: CustomFieldsFilter{Type: codeFail}}) + if err == nil { + t.Errorf("%v", err) } if data.Success != false { @@ -6371,16 +6186,16 @@ func TestClient_CustomDictionariesCreate(t *testing.T) { data, status, err := c.CustomDictionariesCreate(customDictionary) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[status] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } gock.New(crmURL). @@ -6399,17 +6214,17 @@ func TestClient_CustomDictionariesCreate(t *testing.T) { Page: 1, }) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[status] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if cds.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } gock.New(crmURL). @@ -6419,12 +6234,12 @@ func TestClient_CustomDictionariesCreate(t *testing.T) { cd, status, err := c.CustomDictionary(code) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if cd.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } customDictionary.Name = "test223" @@ -6450,16 +6265,16 @@ func TestClient_CustomDictionariesCreate(t *testing.T) { cde, status, err := c.CustomDictionaryEdit(customDictionary) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[status] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if cde.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -6492,9 +6307,9 @@ func TestClient_CustomDictionariesCreate_Fail(t *testing.T) { Reply(400). BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) - data, status, err := c.CustomDictionariesCreate(customDictionary) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + data, _, err := c.CustomDictionariesCreate(customDictionary) + if err == nil { + t.Errorf("%v", err) } if data.Success != false { @@ -6507,8 +6322,8 @@ func TestClient_CustomDictionariesCreate_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Not found"}`) cd, status, err := c.CustomDictionary(codeFail) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Errorf("%v", err) } if cd.Success != false { @@ -6536,12 +6351,12 @@ func TestClient_CustomDictionariesCreate_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) cde, status, err := c.CustomDictionaryEdit(customDictionary) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Errorf("%v", err) } if status < http.StatusBadRequest { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if cde.Success != false { @@ -6578,17 +6393,17 @@ func TestClient_CustomFieldsCreate(t *testing.T) { data, status, err := c.CustomFieldsCreate(customFields) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[status] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if data.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } gock.New(crmURL). @@ -6598,16 +6413,16 @@ func TestClient_CustomFieldsCreate(t *testing.T) { customField, status, err := c.CustomField("order", codeCustomField) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[status] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if customField.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } customFields.DisplayArea = "delivery" @@ -6627,16 +6442,16 @@ func TestClient_CustomFieldsCreate(t *testing.T) { customFieldEdit, status, err := c.CustomFieldEdit(customFields) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err != nil { + t.Errorf("%v", err) } if !statuses[status] { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } if customFieldEdit.Success != true { - t.Errorf("%v", err.ApiError()) + t.Errorf("%v", err) } } @@ -6667,13 +6482,9 @@ func TestClient_CustomFieldsCreate_Fail(t *testing.T) { Reply(400). BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) - data, status, err := c.CustomFieldsCreate(customFields) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + data, _, err := c.CustomFieldsCreate(customFields) + if err == nil { + t.Errorf("%v", err) } if data.Success != false { @@ -6686,8 +6497,8 @@ func TestClient_CustomFieldsCreate_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Not found"}`) customField, status, err := c.CustomField("order", codeCustomField) - if err.Error() != "" { - t.Errorf("%v", err.Error()) + if err == nil { + t.Errorf("%v", err) } if status < http.StatusBadRequest { @@ -6714,12 +6525,8 @@ func TestClient_CustomFieldsCreate_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) customFieldEdit, status, err := c.CustomFieldEdit(customFields) - if err.Error() != "" { - t.Errorf("%v", err.Error()) - } - - if status < http.StatusBadRequest { - t.Error(statusFail) + if err == nil { + t.Errorf("%v", err) } if customFieldEdit.Success != false { diff --git a/v5/error.go b/v5/error.go new file mode 100644 index 0000000..cbdc9df --- /dev/null +++ b/v5/error.go @@ -0,0 +1,32 @@ +package v5 + +import "encoding/json" + +// APIErrorsList struct. +type APIErrorsList map[string]string + +// APIError struct. +type APIError struct { + SuccessfulResponse + ErrorMsg string `json:"errorMsg,omitempty"` + Errors APIErrorsList `json:"errors,omitempty"` +} + +func (e *APIError) Error() string { + return e.ErrorMsg +} + +func NewAPIError(dataResponse []byte) error { + a := &APIError{} + + if len(dataResponse) > 0 && dataResponse[0] == '<' { + a.ErrorMsg = "Account does not exist." + return a + } + + if err := json.Unmarshal(dataResponse, a); err != nil { + return err + } + + return a +} diff --git a/v5/error_test.go b/v5/error_test.go new file mode 100644 index 0000000..989b8e3 --- /dev/null +++ b/v5/error_test.go @@ -0,0 +1,54 @@ +package v5 + +import ( + "reflect" + "testing" + + "golang.org/x/xerrors" +) + +func TestFailure_ApiErrorsSlice(t *testing.T) { + b := []byte(`{"success": false, + "errorMsg": "Failed to activate module", + "errors": [ + "Your account has insufficient funds to activate integration module", + "Test error" + ]}`) + expected := APIErrorsList{ + "0": "Your account has insufficient funds to activate integration module", + "1": "Test error", + } + + var expEr *APIError + e := NewAPIError(b) + + if xerrors.As(e, &expEr) { + if eq := reflect.DeepEqual(expEr.Errors, expected); eq != true { + t.Errorf("%+v", eq) + } + } else { + t.Errorf("Error must be type of APIError: %v", e) + } +} + +func TestFailure_ApiErrorsMap(t *testing.T) { + b := []byte(`{"success": false, + "errorMsg": "Failed to activate module", + "errors": {"id": "ID must be an integer", "test": "Test error"}}`, + ) + expected := APIErrorsList{ + "id": "ID must be an integer", + "test": "Test error", + } + + var expEr *APIError + e := NewAPIError(b) + + if xerrors.As(e, &expEr) { + if eq := reflect.DeepEqual(expEr.Errors, expected); eq != true { + t.Errorf("%+v", eq) + } + } else { + t.Errorf("Error must be type of APIError: %v", e) + } +} diff --git a/v5/filters.go b/v5/filters.go index 6a653bd..1956ac8 100644 --- a/v5/filters.go +++ b/v5/filters.go @@ -1,6 +1,6 @@ package v5 -// CustomersFilter type +// CustomersFilter type. type CustomersFilter struct { Ids []string `url:"ids,omitempty,brackets"` ExternalIds []string `url:"externalIds,omitempty,brackets"` @@ -57,7 +57,7 @@ type CustomersFilter struct { CustomFields map[string]string `url:"customFields,omitempty,brackets"` } -// CorporateCustomersFilter type +// CorporateCustomersFilter type. type CorporateCustomersFilter struct { ContragentName string `url:"contragentName,omitempty"` ContragentInn string `url:"contragentInn,omitempty"` @@ -99,7 +99,7 @@ type CorporateCustomersFilter struct { CustomFields map[string]string `url:"customFields,omitempty,brackets"` } -// CorporateCustomersNotesFilter type +// CorporateCustomersNotesFilter type. type CorporateCustomersNotesFilter struct { Ids []string `url:"ids,omitempty,brackets"` CustomerIds []string `url:"ids,omitempty,brackets"` @@ -110,7 +110,7 @@ type CorporateCustomersNotesFilter struct { CreatedAtTo string `url:"createdAtTo,omitempty"` } -// CorporateCustomerAddressesFilter type +// CorporateCustomerAddressesFilter type. type CorporateCustomerAddressesFilter struct { Ids []string `url:"ids,omitempty,brackets"` Name string `url:"name,omitempty"` @@ -118,13 +118,13 @@ type CorporateCustomerAddressesFilter struct { Region string `url:"region,omitempty"` } -// IdentifiersPairFilter type +// IdentifiersPairFilter type. type IdentifiersPairFilter struct { Ids []string `url:"ids,omitempty,brackets"` ExternalIds []string `url:"externalIds,omitempty,brackets"` } -// CustomersHistoryFilter type +// CustomersHistoryFilter type. type CustomersHistoryFilter struct { CustomerID int `url:"customerId,omitempty"` SinceID int `url:"sinceId,omitempty"` @@ -133,7 +133,7 @@ type CustomersHistoryFilter struct { EndDate string `url:"endDate,omitempty"` } -// CorporateCustomersHistoryFilter type +// CorporateCustomersHistoryFilter type. type CorporateCustomersHistoryFilter struct { CustomerID int `url:"customerId,omitempty"` SinceID int `url:"sinceId,omitempty"` @@ -143,7 +143,7 @@ type CorporateCustomersHistoryFilter struct { EndDate string `url:"endDate,omitempty"` } -// OrdersFilter type +// OrdersFilter type. type OrdersFilter struct { Ids []int `url:"ids,omitempty,brackets"` ExternalIds []string `url:"externalIds,omitempty,brackets"` @@ -234,7 +234,7 @@ type OrdersFilter struct { CustomFields map[string]string `url:"customFields,omitempty,brackets"` } -// OrdersHistoryFilter type +// OrdersHistoryFilter type. type OrdersHistoryFilter struct { OrderID int `url:"orderId,omitempty"` SinceID int `url:"sinceId,omitempty"` @@ -243,7 +243,7 @@ type OrdersHistoryFilter struct { EndDate string `url:"endDate,omitempty"` } -// UsersFilter type +// UsersFilter type. type UsersFilter struct { Email string `url:"email,omitempty"` Status string `url:"status,omitempty"` @@ -256,7 +256,7 @@ type UsersFilter struct { Groups []string `url:"groups,omitempty,brackets"` } -// TasksFilter type +// TasksFilter type. type TasksFilter struct { OrderNumber string `url:"orderNumber,omitempty"` Status string `url:"status,omitempty"` @@ -268,7 +268,7 @@ type TasksFilter struct { Performers []int `url:"performers,omitempty,brackets"` } -// NotesFilter type +// NotesFilter type. type NotesFilter struct { Ids []int `url:"ids,omitempty,brackets"` CustomerIds []int `url:"customerIds,omitempty,brackets"` @@ -279,7 +279,7 @@ type NotesFilter struct { CreatedAtTo string `url:"createdAtTo,omitempty"` } -// SegmentsFilter type +// SegmentsFilter type. type SegmentsFilter struct { Ids []int `url:"ids,omitempty,brackets"` Active int `url:"active,omitempty"` @@ -291,7 +291,7 @@ type SegmentsFilter struct { DateTo string `url:"dateTo,omitempty"` } -// PacksFilter type +// PacksFilter type. type PacksFilter struct { Ids []int `url:"ids,omitempty,brackets"` Stores []string `url:"stores,omitempty"` @@ -306,7 +306,7 @@ type PacksFilter struct { DeliveryNoteNumber string `url:"deliveryNoteNumber,omitempty"` } -// InventoriesFilter type +// InventoriesFilter type. type InventoriesFilter struct { Ids []int `url:"ids,omitempty,brackets"` ProductExternalID string `url:"productExternalId,omitempty"` @@ -319,7 +319,7 @@ type InventoriesFilter struct { Sites []string `url:"sites,omitempty,brackets"` } -// ProductsGroupsFilter type +// ProductsGroupsFilter type. type ProductsGroupsFilter struct { Ids []int `url:"ids,omitempty,brackets"` Sites []string `url:"sites,omitempty,brackets"` @@ -327,7 +327,7 @@ type ProductsGroupsFilter struct { ParentGroupID string `url:"parentGroupId,omitempty"` } -// ProductsFilter type +// ProductsFilter type. type ProductsFilter struct { Ids []int `url:"ids,omitempty,brackets"` OfferIds []int `url:"offerIds,omitempty,brackets"` @@ -355,14 +355,14 @@ type ProductsFilter struct { Properties map[string]string `url:"properties,omitempty,brackets"` } -// ProductsPropertiesFilter type +// ProductsPropertiesFilter type. type ProductsPropertiesFilter struct { Code string `url:"code,omitempty"` Name string `url:"name,omitempty"` Sites []string `url:"sites,omitempty,brackets"` } -// ShipmentFilter type +// ShipmentFilter type. type ShipmentFilter struct { Ids []int `url:"ids,omitempty,brackets"` ExternalID string `url:"externalId,omitempty"` @@ -375,7 +375,7 @@ type ShipmentFilter struct { Statuses []string `url:"statuses,omitempty,brackets"` } -// CostsFilter type +// CostsFilter type. type CostsFilter struct { MinSumm string `url:"minSumm,omitempty"` MaxSumm string `url:"maxSumm,omitempty"` @@ -395,7 +395,7 @@ type CostsFilter struct { OrderExternalIds []string `url:"orderIds,omitempty,brackets"` } -// FilesFilter type +// FilesFilter type. type FilesFilter struct { Ids []int `url:"ids,omitempty,brackets"` OrderIds []int `url:"orderIds,omitempty,brackets"` @@ -412,7 +412,7 @@ type FilesFilter struct { Sites []string `url:"sites,omitempty,brackets"` } -// CustomFieldsFilter type +// CustomFieldsFilter type. type CustomFieldsFilter struct { Name string `url:"name,omitempty"` Code string `url:"code,omitempty"` @@ -422,7 +422,7 @@ type CustomFieldsFilter struct { DisplayArea string `url:"displayArea,omitempty"` } -// CustomDictionariesFilter type +// CustomDictionariesFilter type. type CustomDictionariesFilter struct { Name string `url:"name,omitempty"` Code string `url:"code,omitempty"` diff --git a/v5/marshaling.go b/v5/marshaling.go index 6cc65cf..15cfd50 100644 --- a/v5/marshaling.go +++ b/v5/marshaling.go @@ -1,7 +1,35 @@ package v5 -import "encoding/json" +import ( + "encoding/json" + "fmt" + "strconv" +) func (t Tag) MarshalJSON() ([]byte, error) { return json.Marshal(t.Name) } + +func (a *APIErrorsList) UnmarshalJSON(data []byte) error { + var i interface{} + var m map[string]string + if err := json.Unmarshal(data, &i); err != nil { + return err + } + + switch e := i.(type) { + case map[string]interface{}: + m = make(map[string]string, len(e)) + for idx, val := range e { + m[idx] = fmt.Sprint(val) + } + case []interface{}: + m = make(map[string]string, len(e)) + for idx, val := range e { + m[strconv.Itoa(idx)] = fmt.Sprint(val) + } + } + + *a = m + return nil +} diff --git a/v5/request.go b/v5/request.go index 87a5582..8899845 100644 --- a/v5/request.go +++ b/v5/request.go @@ -1,33 +1,33 @@ package v5 -// CustomerRequest type +// CustomerRequest type. type CustomerRequest struct { By string `url:"by,omitempty"` Site string `url:"site,omitempty"` } -// CustomersRequest type +// CustomersRequest type. type CustomersRequest struct { Filter CustomersFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// CorporateCustomersRequest type +// CorporateCustomersRequest type. type CorporateCustomersRequest struct { Filter CorporateCustomersFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// CorporateCustomersNotesRequest type +// CorporateCustomersNotesRequest type. type CorporateCustomersNotesRequest struct { Filter CorporateCustomersNotesFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// CorporateCustomerAddressesRequest type +// CorporateCustomerAddressesRequest type. type CorporateCustomerAddressesRequest struct { Filter CorporateCustomerAddressesFilter `url:"filter,omitempty"` By string `url:"by,omitempty"` @@ -36,7 +36,7 @@ type CorporateCustomerAddressesRequest struct { Page int `url:"page,omitempty"` } -// IdentifiersPairRequest type +// IdentifiersPairRequest type. type IdentifiersPairRequest struct { Filter IdentifiersPairFilter `url:"filter,omitempty"` By string `url:"by,omitempty"` @@ -45,135 +45,135 @@ type IdentifiersPairRequest struct { Page int `url:"page,omitempty"` } -// CustomersUploadRequest type +// CustomersUploadRequest type. type CustomersUploadRequest struct { Customers []Customer `url:"customers,omitempty,brackets"` Site string `url:"site,omitempty"` } -// CustomersHistoryRequest type +// CustomersHistoryRequest type. type CustomersHistoryRequest struct { Filter CustomersHistoryFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// CorporateCustomersHistoryRequest type +// CorporateCustomersHistoryRequest type. type CorporateCustomersHistoryRequest struct { Filter CorporateCustomersHistoryFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// OrderRequest type +// OrderRequest type. type OrderRequest struct { By string `url:"by,omitempty"` Site string `url:"site,omitempty"` } -// OrdersRequest type +// OrdersRequest type. type OrdersRequest struct { Filter OrdersFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// OrdersStatusesRequest type +// OrdersStatusesRequest type. type OrdersStatusesRequest struct { IDs []int `url:"ids,omitempty,brackets"` ExternalIDs []string `url:"externalIds,omitempty,brackets"` } -// OrdersUploadRequest type +// OrdersUploadRequest type. type OrdersUploadRequest struct { Orders []Order `url:"orders,omitempty,brackets"` Site string `url:"site,omitempty"` } -// OrdersHistoryRequest type +// OrdersHistoryRequest type. type OrdersHistoryRequest struct { Filter OrdersHistoryFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// PacksRequest type +// PacksRequest type. type PacksRequest struct { Filter PacksFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// PacksHistoryRequest type +// PacksHistoryRequest type. type PacksHistoryRequest struct { Filter OrdersHistoryFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// UsersRequest type +// UsersRequest type. type UsersRequest struct { Filter UsersFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// UserGroupsRequest type +// UserGroupsRequest type. type UserGroupsRequest struct { Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// TasksRequest type +// TasksRequest type. type TasksRequest struct { Filter TasksFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// NotesRequest type +// NotesRequest type. type NotesRequest struct { Filter NotesFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// SegmentsRequest type +// SegmentsRequest type. type SegmentsRequest struct { Filter SegmentsFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// InventoriesRequest type +// InventoriesRequest type. type InventoriesRequest struct { Filter InventoriesFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// ProductsGroupsRequest type +// ProductsGroupsRequest type. type ProductsGroupsRequest struct { Filter ProductsGroupsFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// ProductsRequest type +// ProductsRequest type. type ProductsRequest struct { Filter ProductsFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// ProductsPropertiesRequest type +// ProductsPropertiesRequest type. type ProductsPropertiesRequest struct { Filter ProductsPropertiesFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// DeliveryTrackingRequest type +// DeliveryTrackingRequest type. type DeliveryTrackingRequest struct { DeliveryID string `json:"deliveryId,omitempty"` TrackNumber string `json:"trackNumber,omitempty"` @@ -181,35 +181,35 @@ type DeliveryTrackingRequest struct { ExtraData map[string]string `json:"extraData,omitempty,brackets"` } -// DeliveryShipmentsRequest type +// DeliveryShipmentsRequest type. type DeliveryShipmentsRequest struct { Filter ShipmentFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// CostsRequest type +// CostsRequest type. type CostsRequest struct { Filter CostsFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// FilesRequest type +// FilesRequest type. type FilesRequest struct { Filter FilesFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// CustomFieldsRequest type +// CustomFieldsRequest type. type CustomFieldsRequest struct { Filter CustomFieldsFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } -// CustomDictionariesRequest 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 227fb35..3920682 100644 --- a/v5/response.go +++ b/v5/response.go @@ -1,495 +1,495 @@ package v5 -// SuccessfulResponse type +// SuccessfulResponse type. type SuccessfulResponse struct { Success bool `json:"success,omitempty"` } -// CreateResponse type +// CreateResponse type. type CreateResponse struct { Success bool `json:"success"` ID int `json:"id,omitempty"` } -// OrderCreateResponse type +// OrderCreateResponse type. type OrderCreateResponse struct { CreateResponse Order Order `json:"order,omitempty"` } -// OperationResponse type +// OperationResponse type. type OperationResponse struct { Success bool `json:"success"` - Errors map[string]string `json:"errors,omitempty,brackets"` + Errors map[string]string `json:"errors,omitempty"` } -// VersionResponse return available API versions +// VersionResponse return available API versions. type VersionResponse struct { Success bool `json:"success,omitempty"` - Versions []string `json:"versions,brackets,omitempty"` + Versions []string `json:"versions,omitempty"` } -// CredentialResponse return available API methods +// CredentialResponse return available API methods. type CredentialResponse struct { Success bool `json:"success,omitempty"` - Credentials []string `json:"credentials,brackets,omitempty"` + Credentials []string `json:"credentials,omitempty"` SiteAccess string `json:"siteAccess,omitempty"` - SitesAvailable []string `json:"sitesAvailable,brackets,omitempty"` + SitesAvailable []string `json:"sitesAvailable,omitempty"` } -// CustomerResponse type +// CustomerResponse type. type CustomerResponse struct { Success bool `json:"success"` - Customer *Customer `json:"customer,omitempty,brackets"` + Customer *Customer `json:"customer,omitempty"` } -// CorporateCustomerResponse type +// CorporateCustomerResponse type. type CorporateCustomerResponse struct { Success bool `json:"success"` - CorporateCustomer *CorporateCustomer `json:"customerCorporate,omitempty,brackets"` + CorporateCustomer *CorporateCustomer `json:"customerCorporate,omitempty"` } -// CustomersResponse type +// CustomersResponse type. type CustomersResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` - Customers []Customer `json:"customers,omitempty,brackets"` + Customers []Customer `json:"customers,omitempty"` } -// CorporateCustomersResponse type +// CorporateCustomersResponse type. type CorporateCustomersResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` - CustomersCorporate []CorporateCustomer `json:"customersCorporate,omitempty,brackets"` + CustomersCorporate []CorporateCustomer `json:"customersCorporate,omitempty"` } -// CorporateCustomersNotesResponse type +// CorporateCustomersNotesResponse type. type CorporateCustomersNotesResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` - Notes []Note `json:"notes,omitempty,brackets"` + Notes []Note `json:"notes,omitempty"` } -// CorporateCustomersAddressesResponse type +// CorporateCustomersAddressesResponse type. type CorporateCustomersAddressesResponse struct { Success bool `json:"success"` Addresses []CorporateCustomerAddress `json:"addresses"` } -// CorporateCustomerCompaniesResponse type +// CorporateCustomerCompaniesResponse type. type CorporateCustomerCompaniesResponse struct { Success bool `json:"success"` Companies []Company `json:"companies"` } -// CorporateCustomerContactsResponse type +// CorporateCustomerContactsResponse type. type CorporateCustomerContactsResponse struct { Success bool `json:"success"` Contacts []CorporateCustomerContact `json:"contacts"` } -// CustomerChangeResponse type +// CustomerChangeResponse type. type CustomerChangeResponse struct { Success bool `json:"success"` ID int `json:"id,omitempty"` State string `json:"state,omitempty"` } -// CorporateCustomerChangeResponse type +// CorporateCustomerChangeResponse type. type CorporateCustomerChangeResponse CustomerChangeResponse -// CustomersUploadResponse type +// CustomersUploadResponse type. type CustomersUploadResponse struct { Success bool `json:"success"` - UploadedCustomers []IdentifiersPair `json:"uploadedCustomers,omitempty,brackets"` + UploadedCustomers []IdentifiersPair `json:"uploadedCustomers,omitempty"` } -// CorporateCustomersUploadResponse type +// CorporateCustomersUploadResponse type. type CorporateCustomersUploadResponse CustomersUploadResponse -// CustomersHistoryResponse type +// CustomersHistoryResponse type. type CustomersHistoryResponse struct { Success bool `json:"success,omitempty"` GeneratedAt string `json:"generatedAt,omitempty"` - History []CustomerHistoryRecord `json:"history,omitempty,brackets"` + History []CustomerHistoryRecord `json:"history,omitempty"` Pagination *Pagination `json:"pagination,omitempty"` } -// CorporateCustomersHistoryResponse type +// CorporateCustomersHistoryResponse type. type CorporateCustomersHistoryResponse struct { Success bool `json:"success,omitempty"` GeneratedAt string `json:"generatedAt,omitempty"` - History []CorporateCustomerHistoryRecord `json:"history,omitempty,brackets"` + History []CorporateCustomerHistoryRecord `json:"history,omitempty"` Pagination *Pagination `json:"pagination,omitempty"` } -// OrderResponse type +// OrderResponse type. type OrderResponse struct { Success bool `json:"success"` - Order *Order `json:"order,omitempty,brackets"` + Order *Order `json:"order,omitempty"` } -// OrdersResponse type +// OrdersResponse type. type OrdersResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` - Orders []Order `json:"orders,omitempty,brackets"` + Orders []Order `json:"orders,omitempty"` } -// OrdersStatusesResponse type +// OrdersStatusesResponse type. type OrdersStatusesResponse struct { Success bool `json:"success"` Orders []OrdersStatus `json:"orders"` } -// OrdersUploadResponse type +// OrdersUploadResponse type. type OrdersUploadResponse struct { Success bool `json:"success"` - UploadedOrders []IdentifiersPair `json:"uploadedOrders,omitempty,brackets"` + UploadedOrders []IdentifiersPair `json:"uploadedOrders,omitempty"` } -// OrdersHistoryResponse type +// OrdersHistoryResponse type. type OrdersHistoryResponse struct { Success bool `json:"success,omitempty"` GeneratedAt string `json:"generatedAt,omitempty"` - History []OrdersHistoryRecord `json:"history,omitempty,brackets"` + History []OrdersHistoryRecord `json:"history,omitempty"` Pagination *Pagination `json:"pagination,omitempty"` } -// PackResponse type +// PackResponse type. type PackResponse struct { Success bool `json:"success"` - Pack *Pack `json:"pack,omitempty,brackets"` + Pack *Pack `json:"pack,omitempty"` } -// PacksResponse type +// PacksResponse type. type PacksResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` - Packs []Pack `json:"packs,omitempty,brackets"` + Packs []Pack `json:"packs,omitempty"` } -// PacksHistoryResponse type +// PacksHistoryResponse type. type PacksHistoryResponse struct { Success bool `json:"success,omitempty"` GeneratedAt string `json:"generatedAt,omitempty"` - History []PacksHistoryRecord `json:"history,omitempty,brackets"` + History []PacksHistoryRecord `json:"history,omitempty"` Pagination *Pagination `json:"pagination,omitempty"` } -// UserResponse type +// UserResponse type. type UserResponse struct { Success bool `json:"success"` - User *User `json:"user,omitempty,brackets"` + User *User `json:"user,omitempty"` } -// UsersResponse type +// UsersResponse type. type UsersResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` - Users []User `json:"users,omitempty,brackets"` + Users []User `json:"users,omitempty"` } -// UserGroupsResponse type +// UserGroupsResponse type. type UserGroupsResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` - Groups []UserGroup `json:"groups,omitempty,brackets"` + Groups []UserGroup `json:"groups,omitempty"` } -// TaskResponse type +// TaskResponse type. type TaskResponse struct { Success bool `json:"success"` - Task *Task `json:"task,omitempty,brackets"` + Task *Task `json:"task,omitempty"` } -// TasksResponse type +// TasksResponse type. type TasksResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` - Tasks []Task `json:"tasks,omitempty,brackets"` + Tasks []Task `json:"tasks,omitempty"` } -// NotesResponse type +// NotesResponse type. type NotesResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` - Notes []Note `json:"notes,omitempty,brackets"` + Notes []Note `json:"notes,omitempty"` } -// SegmentsResponse type +// SegmentsResponse type. type SegmentsResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` - Segments []Segment `json:"segments,omitempty,brackets"` + Segments []Segment `json:"segments,omitempty"` } -// SettingsResponse type +// SettingsResponse type. type SettingsResponse struct { - Success bool `json:"success"` - Settings Settings `json:"settings,omitempty,brackets"` + Success bool `json:"success"` + Settings Settings `json:"settings,omitempty"` } -// CountriesResponse type +// CountriesResponse type. type CountriesResponse struct { Success bool `json:"success"` - CountriesIso []string `json:"countriesIso,omitempty,brackets"` + CountriesIso []string `json:"countriesIso,omitempty"` } -// CostGroupsResponse type +// CostGroupsResponse type. type CostGroupsResponse struct { Success bool `json:"success"` - CostGroups []CostGroup `json:"costGroups,omitempty,brackets"` + CostGroups []CostGroup `json:"costGroups,omitempty"` } -// CostItemsResponse type +// CostItemsResponse type. type CostItemsResponse struct { Success bool `json:"success"` - CostItems []CostItem `json:"costItems,omitempty,brackets"` + CostItems []CostItem `json:"costItems,omitempty"` } -// CouriersResponse type +// CouriersResponse type. type CouriersResponse struct { Success bool `json:"success"` - Couriers []Courier `json:"couriers,omitempty,brackets"` + Couriers []Courier `json:"couriers,omitempty"` } -// DeliveryServiceResponse type +// DeliveryServiceResponse type. type DeliveryServiceResponse struct { Success bool `json:"success"` - DeliveryServices map[string]DeliveryService `json:"deliveryServices,omitempty,brackets"` + DeliveryServices map[string]DeliveryService `json:"deliveryServices,omitempty"` } -// DeliveryTypesResponse type +// DeliveryTypesResponse type. type DeliveryTypesResponse struct { Success bool `json:"success"` - DeliveryTypes map[string]DeliveryType `json:"deliveryTypes,omitempty,brackets"` + DeliveryTypes map[string]DeliveryType `json:"deliveryTypes,omitempty"` } -// LegalEntitiesResponse type +// LegalEntitiesResponse type. type LegalEntitiesResponse struct { Success bool `json:"success"` - LegalEntities []LegalEntity `json:"legalEntities,omitempty,brackets"` + LegalEntities []LegalEntity `json:"legalEntities,omitempty"` } -// OrderMethodsResponse type +// OrderMethodsResponse type. type OrderMethodsResponse struct { Success bool `json:"success"` - OrderMethods map[string]OrderMethod `json:"orderMethods,omitempty,brackets"` + OrderMethods map[string]OrderMethod `json:"orderMethods,omitempty"` } -// OrderTypesResponse type +// OrderTypesResponse type. type OrderTypesResponse struct { Success bool `json:"success"` - OrderTypes map[string]OrderType `json:"orderTypes,omitempty,brackets"` + OrderTypes map[string]OrderType `json:"orderTypes,omitempty"` } -// PaymentStatusesResponse type +// PaymentStatusesResponse type. type PaymentStatusesResponse struct { Success bool `json:"success"` - PaymentStatuses map[string]PaymentStatus `json:"paymentStatuses,omitempty,brackets"` + PaymentStatuses map[string]PaymentStatus `json:"paymentStatuses,omitempty"` } -// PaymentTypesResponse type +// PaymentTypesResponse type. type PaymentTypesResponse struct { Success bool `json:"success"` - PaymentTypes map[string]PaymentType `json:"paymentTypes,omitempty,brackets"` + PaymentTypes map[string]PaymentType `json:"paymentTypes,omitempty"` } -// PriceTypesResponse type +// PriceTypesResponse type. type PriceTypesResponse struct { Success bool `json:"success"` - PriceTypes []PriceType `json:"priceTypes,omitempty,brackets"` + PriceTypes []PriceType `json:"priceTypes,omitempty"` } -// ProductStatusesResponse type +// ProductStatusesResponse type. type ProductStatusesResponse struct { Success bool `json:"success"` - ProductStatuses map[string]ProductStatus `json:"productStatuses,omitempty,brackets"` + ProductStatuses map[string]ProductStatus `json:"productStatuses,omitempty"` } -// StatusesResponse type +// StatusesResponse type. type StatusesResponse struct { Success bool `json:"success"` - Statuses map[string]Status `json:"statuses,omitempty,brackets"` + Statuses map[string]Status `json:"statuses,omitempty"` } -// StatusGroupsResponse type +// StatusGroupsResponse type. type StatusGroupsResponse struct { Success bool `json:"success"` - StatusGroups map[string]StatusGroup `json:"statusGroups,omitempty,brackets"` + StatusGroups map[string]StatusGroup `json:"statusGroups,omitempty"` } -// SitesResponse type +// SitesResponse type. type SitesResponse struct { Success bool `json:"success"` - Sites map[string]Site `json:"sites,omitempty,brackets"` + Sites map[string]Site `json:"sites,omitempty"` } -// StoresResponse type +// StoresResponse type. type StoresResponse struct { Success bool `json:"success"` - Stores []Store `json:"stores,omitempty,brackets"` + Stores []Store `json:"stores,omitempty"` } -// InventoriesResponse type +// InventoriesResponse type. type InventoriesResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` Offers []Offer `json:"offers,omitempty"` } -// StoreUploadResponse type +// StoreUploadResponse type. type StoreUploadResponse struct { Success bool `json:"success"` ProcessedOffersCount int `json:"processedOffersCount,omitempty"` NotFoundOffers []Offer `json:"notFoundOffers,omitempty"` } -// ProductsGroupsResponse type +// ProductsGroupsResponse type. type ProductsGroupsResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` - ProductGroup []ProductGroup `json:"productGroup,omitempty,brackets"` + ProductGroup []ProductGroup `json:"productGroup,omitempty"` } -// ProductsResponse type +// ProductsResponse type. type ProductsResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` - Products []Product `json:"products,omitempty,brackets"` + Products []Product `json:"products,omitempty"` } -// ProductsPropertiesResponse type +// ProductsPropertiesResponse type. type ProductsPropertiesResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` - Properties []Property `json:"properties,omitempty,brackets"` + Properties []Property `json:"properties,omitempty"` } -// DeliveryShipmentsResponse type +// DeliveryShipmentsResponse type. type DeliveryShipmentsResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` - DeliveryShipments []DeliveryShipment `json:"deliveryShipments,omitempty,brackets"` + DeliveryShipments []DeliveryShipment `json:"deliveryShipments,omitempty"` } -// DeliveryShipmentResponse type +// DeliveryShipmentResponse type. type DeliveryShipmentResponse struct { Success bool `json:"success"` - DeliveryShipment *DeliveryShipment `json:"deliveryShipment,omitempty,brackets"` + DeliveryShipment *DeliveryShipment `json:"deliveryShipment,omitempty"` } -// DeliveryShipmentUpdateResponse type +// DeliveryShipmentUpdateResponse type. type DeliveryShipmentUpdateResponse struct { Success bool `json:"success"` ID int `json:"id,omitempty"` Status string `json:"status,omitempty"` } -// IntegrationModuleResponse type +// IntegrationModuleResponse type. type IntegrationModuleResponse struct { Success bool `json:"success"` IntegrationModule *IntegrationModule `json:"integrationModule,omitempty"` } -// IntegrationModuleEditResponse type +// IntegrationModuleEditResponse type. type IntegrationModuleEditResponse struct { Success bool `json:"success"` - Info ResponseInfo `json:"info,omitempty,brackets"` + Info ResponseInfo `json:"info,omitempty"` } -// ResponseInfo type +// ResponseInfo type. type ResponseInfo struct { - MgTransportInfo MgInfo `json:"mgTransport,omitempty,brackets"` - MgBotInfo MgInfo `json:"mgBot,omitempty,brackets"` + MgTransportInfo MgInfo `json:"mgTransport,omitempty"` + MgBotInfo MgInfo `json:"mgBot,omitempty"` } -// MgInfo type +// MgInfo type. type MgInfo struct { EndpointUrl string `json:"endpointUrl"` Token string `json:"token"` } -// CostsResponse type +// CostsResponse type. type CostsResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` - Costs []Cost `json:"costs,omitempty,brackets"` + Costs []Cost `json:"costs,omitempty"` } -// CostsUploadResponse type +// CostsUploadResponse type. type CostsUploadResponse struct { Success bool `json:"success"` - UploadedCosts []int `json:"uploadedCosts,omitempty,brackets"` + UploadedCosts []int `json:"uploadedCosts,omitempty"` } -// CostsDeleteResponse type +// CostsDeleteResponse type. type CostsDeleteResponse struct { Success bool `json:"success"` - Count int `json:"count,omitempty,brackets"` - NotRemovedIds []int `json:"notRemovedIds,omitempty,brackets"` + Count int `json:"count,omitempty"` + NotRemovedIds []int `json:"notRemovedIds,omitempty"` } -// CostResponse type +// CostResponse type. type CostResponse struct { Success bool `json:"success"` - Cost *Cost `json:"cost,omitempty,brackets"` + Cost *Cost `json:"cost,omitempty"` } -// FilesResponse type +// FilesResponse type. type FilesResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` Files []File `json:"files,omitempty"` } -// FileUpload response +// FileUpload response. type FileUploadResponse struct { Success bool `json:"success"` File *File `json:"file,omitempty"` } -// FileResponse type +// FileResponse type. type FileResponse struct { Success bool `json:"success"` File *File `json:"file,omitempty"` } -// CustomFieldsResponse type +// CustomFieldsResponse type. type CustomFieldsResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` - CustomFields []CustomFields `json:"customFields,omitempty,brackets"` + CustomFields []CustomFields `json:"customFields,omitempty"` } -// CustomDictionariesResponse type +// CustomDictionariesResponse type. type CustomDictionariesResponse struct { Success bool `json:"success"` Pagination *Pagination `json:"pagination,omitempty"` - CustomDictionaries *[]CustomDictionary `json:"customDictionaries,omitempty,brackets"` + CustomDictionaries *[]CustomDictionary `json:"customDictionaries,omitempty"` } -// CustomResponse type +// CustomResponse type. type CustomResponse struct { Success bool `json:"success"` Code string `json:"code,omitempty"` } -// CustomDictionaryResponse type +// CustomDictionaryResponse type. type CustomDictionaryResponse struct { Success bool `json:"success"` - CustomDictionary *CustomDictionary `json:"CustomDictionary,omitempty,brackets"` + CustomDictionary *CustomDictionary `json:"CustomDictionary,omitempty"` } -// CustomFieldResponse type +// CustomFieldResponse type. type CustomFieldResponse struct { Success bool `json:"success"` - CustomField CustomFields `json:"customField,omitempty,brackets"` + CustomField CustomFields `json:"customField,omitempty"` } -// UnitsResponse type +// UnitsResponse type. type UnitsResponse struct { Success bool `json:"success"` - Units *[]Unit `json:"units,omitempty,brackets"` + Units *[]Unit `json:"units,omitempty"` } diff --git a/v5/types.go b/v5/types.go index 744fdba..c6c4c1a 100644 --- a/v5/types.go +++ b/v5/types.go @@ -7,13 +7,13 @@ import ( "strings" ) -// ByID is "id" constant to use as `by` property in methods +// ByID is "id" constant to use as `by` property in methods. const ByID = "id" -// ByExternalId is "externalId" constant to use as `by` property in methods +// ByExternalId is "externalId" constant to use as `by` property in methods. const ByExternalID = "externalId" -// Client type +// Client type. type Client struct { URL string Key string @@ -21,7 +21,7 @@ type Client struct { httpClient *http.Client } -// Pagination type +// Pagination type. type Pagination struct { Limit int `json:"limit,omitempty"` TotalCount int `json:"totalCount,omitempty"` @@ -29,7 +29,7 @@ type Pagination struct { TotalPageCount int `json:"totalPageCount,omitempty"` } -// Address type +// Address type. type Address struct { Index string `json:"index,omitempty"` CountryIso string `json:"countryIso,omitempty"` @@ -51,7 +51,7 @@ type Address struct { Text string `json:"text,omitempty"` } -// GeoHierarchyRow type +// GeoHierarchyRow type. type GeoHierarchyRow struct { Country string `json:"country,omitempty"` Region string `json:"region,omitempty"` @@ -60,7 +60,7 @@ type GeoHierarchyRow struct { CityID int `json:"cityId,omitempty"` } -// Source type +// Source type. type Source struct { Source string `json:"source,omitempty"` Medium string `json:"medium,omitempty"` @@ -69,7 +69,7 @@ type Source struct { Content string `json:"content,omitempty"` } -// Contragent type +// Contragent type. type Contragent struct { ContragentType string `json:"contragentType,omitempty"` LegalName string `json:"legalName,omitempty"` @@ -88,26 +88,26 @@ type Contragent struct { BankAccount string `json:"bankAccount,omitempty"` } -// APIKey type +// APIKey type. type APIKey struct { Current bool `json:"current,omitempty"` } -// Property type +// Property type. type Property struct { Code string `json:"code,omitempty"` Name string `json:"name,omitempty"` Value string `json:"value,omitempty"` - Sites []string `json:"Sites,omitempty,brackets"` + Sites []string `json:"Sites,omitempty"` } -// IdentifiersPair type +// IdentifiersPair type. type IdentifiersPair struct { ID int `json:"id,omitempty"` ExternalID string `json:"externalId,omitempty"` } -// DeliveryTime type +// DeliveryTime type. type DeliveryTime struct { From string `json:"from,omitempty"` To string `json:"to,omitempty"` @@ -118,7 +118,7 @@ type DeliveryTime struct { Customer related types */ -// Customer type +// Customer type. type Customer struct { ID int `json:"id,omitempty"` ExternalID string `json:"externalId,omitempty"` @@ -127,7 +127,7 @@ type Customer struct { Patronymic string `json:"patronymic,omitempty"` Sex string `json:"sex,omitempty"` Email string `json:"email,omitempty"` - Phones []Phone `json:"phones,brackets,omitempty"` + Phones []Phone `json:"phones,omitempty"` Address *Address `json:"address,omitempty"` CreatedAt string `json:"createdAt,omitempty"` Birthday string `json:"birthday,omitempty"` @@ -153,11 +153,11 @@ type Customer struct { BrowserID string `json:"browserId,omitempty"` MgCustomerID string `json:"mgCustomerId,omitempty"` PhotoURL string `json:"photoUrl,omitempty"` - CustomFields map[string]string `json:"customFields,omitempty,brackets"` - Tags []Tag `json:"tags,brackets,omitempty"` + CustomFields map[string]string `json:"customFields,omitempty"` + Tags []Tag `json:"tags,omitempty"` } -// CorporateCustomer type +// CorporateCustomer type. type CorporateCustomer struct { ID int `json:"id,omitempty"` ExternalID string `json:"externalId,omitempty"` @@ -165,7 +165,7 @@ type CorporateCustomer struct { CreatedAt string `json:"createdAt,omitempty"` Vip bool `json:"vip,omitempty"` Bad bool `json:"bad,omitempty"` - CustomFields map[string]string `json:"customFields,omitempty,brackets"` + CustomFields map[string]string `json:"customFields,omitempty"` PersonalDiscount float32 `json:"personalDiscount,omitempty"` DiscountCardNumber string `json:"discountCardNumber,omitempty"` ManagerID int `json:"managerId,omitempty"` @@ -226,22 +226,22 @@ type Company struct { CreatedAt string `json:"createdAt,omitempty"` Contragent *Contragent `json:"contragent,omitempty"` Address *IdentifiersPair `json:"address,omitempty"` - CustomFields map[string]string `json:"customFields,omitempty,brackets"` + CustomFields map[string]string `json:"customFields,omitempty"` } -// CorporateCustomerNote type +// CorporateCustomerNote type. type CorporateCustomerNote struct { ManagerID int `json:"managerId,omitempty"` Text string `json:"text,omitempty"` Customer *IdentifiersPair `json:"customer,omitempty"` } -// Phone type +// Phone type. type Phone struct { Number string `json:"number,omitempty"` } -// CustomerHistoryRecord type +// CustomerHistoryRecord type. type CustomerHistoryRecord struct { ID int `json:"id,omitempty"` CreatedAt string `json:"createdAt,omitempty"` @@ -249,12 +249,12 @@ type CustomerHistoryRecord struct { Deleted bool `json:"deleted,omitempty"` Source string `json:"source,omitempty"` Field string `json:"field,omitempty"` - User *User `json:"user,omitempty,brackets"` - APIKey *APIKey `json:"apiKey,omitempty,brackets"` - Customer *Customer `json:"customer,omitempty,brackets"` + User *User `json:"user,omitempty"` + APIKey *APIKey `json:"apiKey,omitempty"` + Customer *Customer `json:"customer,omitempty"` } -// CorporateCustomerHistoryRecord type +// CorporateCustomerHistoryRecord type. type CorporateCustomerHistoryRecord struct { ID int `json:"id,omitempty"` CreatedAt string `json:"createdAt,omitempty"` @@ -262,16 +262,16 @@ type CorporateCustomerHistoryRecord struct { Deleted bool `json:"deleted,omitempty"` Source string `json:"source,omitempty"` Field string `json:"field,omitempty"` - User *User `json:"user,omitempty,brackets"` - APIKey *APIKey `json:"apiKey,omitempty,brackets"` - CorporateCustomer *CorporateCustomer `json:"corporateCustomer,omitempty,brackets"` + User *User `json:"user,omitempty"` + APIKey *APIKey `json:"apiKey,omitempty"` + CorporateCustomer *CorporateCustomer `json:"corporateCustomer,omitempty"` } /** Order related types */ -// Order type +// Order type. type Order struct { ID int `json:"id,omitempty"` ExternalID string `json:"externalId,omitempty"` @@ -319,12 +319,12 @@ type Order struct { Customer *Customer `json:"customer,omitempty"` Delivery *OrderDelivery `json:"delivery,omitempty"` Marketplace *OrderMarketplace `json:"marketplace,omitempty"` - Items []OrderItem `json:"items,omitempty,brackets"` - CustomFields map[string]string `json:"customFields,omitempty,brackets"` - Payments map[string]OrderPayment `json:"payments,omitempty,brackets"` + Items []OrderItem `json:"items,omitempty"` + CustomFields map[string]string `json:"customFields,omitempty"` + Payments map[string]OrderPayment `json:"payments,omitempty"` } -// OrdersStatus type +// OrdersStatus type. type OrdersStatus struct { ID int `json:"id"` ExternalID string `json:"externalId,omitempty"` @@ -332,7 +332,7 @@ type OrdersStatus struct { Group string `json:"group"` } -// OrderDelivery type +// OrderDelivery type. type OrderDelivery struct { Code string `json:"code,omitempty"` IntegrationCode string `json:"integrationCode,omitempty"` @@ -346,21 +346,21 @@ type OrderDelivery struct { Data *OrderDeliveryData `json:"data,omitempty"` } -// OrderDeliveryTime type +// OrderDeliveryTime type. type OrderDeliveryTime struct { From string `json:"from,omitempty"` To string `json:"to,omitempty"` Custom string `json:"custom,omitempty"` } -// OrderDeliveryService type +// OrderDeliveryService type. type OrderDeliveryService struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` Active bool `json:"active,omitempty"` } -// OrderDeliveryDataBasic type +// OrderDeliveryDataBasic type. type OrderDeliveryDataBasic struct { TrackNumber string `json:"trackNumber,omitempty"` Status string `json:"status,omitempty"` @@ -368,13 +368,13 @@ type OrderDeliveryDataBasic struct { PayerType string `json:"payerType,omitempty"` } -// OrderDeliveryData type +// OrderDeliveryData type. type OrderDeliveryData struct { OrderDeliveryDataBasic AdditionalFields map[string]interface{} } -// UnmarshalJSON method +// UnmarshalJSON method. func (v *OrderDeliveryData) UnmarshalJSON(b []byte) error { var additionalData map[string]interface{} json.Unmarshal(b, &additionalData) @@ -396,7 +396,7 @@ func (v *OrderDeliveryData) UnmarshalJSON(b []byte) error { return nil } -// MarshalJSON method +// MarshalJSON method. func (v OrderDeliveryData) MarshalJSON() ([]byte, error) { result := map[string]interface{}{} data, _ := json.Marshal(v.OrderDeliveryDataBasic) @@ -409,13 +409,13 @@ func (v OrderDeliveryData) MarshalJSON() ([]byte, error) { return json.Marshal(result) } -// OrderMarketplace type +// OrderMarketplace type. type OrderMarketplace struct { Code string `json:"code,omitempty"` OrderID string `json:"orderId,omitempty"` } -// OrderPayment type +// OrderPayment type. type OrderPayment struct { ID int `json:"id,omitempty"` ExternalID string `json:"externalId,omitempty"` @@ -426,7 +426,7 @@ type OrderPayment struct { Comment string `json:"comment,omitempty"` } -// OrderItem type +// OrderItem type. type OrderItem struct { ID int `json:"id,omitempty"` InitialPrice float32 `json:"initialPrice,omitempty"` @@ -442,11 +442,11 @@ type OrderItem struct { Comment string `json:"comment,omitempty"` IsCanceled bool `json:"isCanceled,omitempty"` Offer Offer `json:"offer,omitempty"` - Properties map[string]Property `json:"properties,omitempty,brackets"` + Properties map[string]Property `json:"properties,omitempty"` PriceType *PriceType `json:"priceType,omitempty"` } -// OrdersHistoryRecord type +// OrdersHistoryRecord type. type OrdersHistoryRecord struct { ID int `json:"id,omitempty"` CreatedAt string `json:"createdAt,omitempty"` @@ -454,12 +454,12 @@ type OrdersHistoryRecord struct { Deleted bool `json:"deleted,omitempty"` Source string `json:"source,omitempty"` Field string `json:"field,omitempty"` - User *User `json:"user,omitempty,brackets"` - APIKey *APIKey `json:"apiKey,omitempty,brackets"` - Order *Order `json:"order,omitempty,brackets"` + User *User `json:"user,omitempty"` + APIKey *APIKey `json:"apiKey,omitempty"` + Order *Order `json:"order,omitempty"` } -// Pack type +// Pack type. type Pack struct { ID int `json:"id,omitempty"` PurchasePrice float32 `json:"purchasePrice,omitempty"` @@ -473,14 +473,14 @@ type Pack struct { Unit *Unit `json:"unit,omitempty"` } -// PackItem type +// PackItem type. type PackItem struct { ID int `json:"id,omitempty"` Order *Order `json:"order,omitempty"` Offer *Offer `json:"offer,omitempty"` } -// PacksHistoryRecord type +// PacksHistoryRecord type. type PacksHistoryRecord struct { ID int `json:"id,omitempty"` CreatedAt string `json:"createdAt,omitempty"` @@ -488,11 +488,11 @@ type PacksHistoryRecord struct { Deleted bool `json:"deleted,omitempty"` Source string `json:"source,omitempty"` Field string `json:"field,omitempty"` - User *User `json:"user,omitempty,brackets"` - Pack *Pack `json:"pack,omitempty,brackets"` + User *User `json:"user,omitempty"` + Pack *Pack `json:"pack,omitempty"` } -// Offer type +// Offer type. type Offer struct { ID int `json:"id,omitempty"` ExternalID string `json:"externalId,omitempty"` @@ -507,21 +507,21 @@ type Offer struct { Width float32 `json:"width,omitempty"` Length float32 `json:"length,omitempty"` Weight float32 `json:"weight,omitempty"` - Stores []Inventory `json:"stores,omitempty,brackets"` - Properties map[string]string `json:"properties,omitempty,brackets"` - Prices []OfferPrice `json:"prices,omitempty,brackets"` - Images []string `json:"images,omitempty,brackets"` - Unit *Unit `json:"unit,omitempty,brackets"` + Stores []Inventory `json:"stores,omitempty"` + Properties map[string]string `json:"properties,omitempty"` + Prices []OfferPrice `json:"prices,omitempty"` + Images []string `json:"images,omitempty"` + Unit *Unit `json:"unit,omitempty"` } -// Inventory type +// Inventory type. type Inventory struct { PurchasePrice float32 `json:"purchasePrice,omitempty"` Quantity float32 `json:"quantity,omitempty"` Store string `json:"store,omitempty"` } -// InventoryUpload type +// InventoryUpload type. type InventoryUpload struct { ID int `json:"id,omitempty"` ExternalID string `json:"externalId,omitempty"` @@ -529,21 +529,21 @@ type InventoryUpload struct { Stores []InventoryUploadStore `json:"stores,omitempty"` } -// InventoryUploadStore type +// InventoryUploadStore type. type InventoryUploadStore struct { PurchasePrice float32 `json:"purchasePrice,omitempty"` Available float32 `json:"available,omitempty"` Code string `json:"code,omitempty"` } -// OfferPrice type +// OfferPrice type. type OfferPrice struct { Price float32 `json:"price,omitempty"` Ordering int `json:"ordering,omitempty"` PriceType string `json:"priceType,omitempty"` } -// OfferPriceUpload type +// OfferPriceUpload type. type OfferPriceUpload struct { ID int `json:"id,omitempty"` ExternalID string `json:"externalId,omitempty"` @@ -552,13 +552,13 @@ type OfferPriceUpload struct { Prices []PriceUpload `json:"prices,omitempty"` } -// PriceUpload type +// PriceUpload type. type PriceUpload struct { Code string `json:"code,omitempty"` Price float32 `json:"price,omitempty"` } -// Unit type +// Unit type. type Unit struct { Code string `json:"code"` Name string `json:"name"` @@ -571,7 +571,7 @@ type Unit struct { User related types */ -// User type +// User type. type User struct { ID int `json:"id,omitempty"` FirstName string `json:"firstName,omitempty"` @@ -585,30 +585,30 @@ type User struct { Email string `json:"email,omitempty"` Phone string `json:"phone,omitempty"` Status string `json:"status,omitempty"` - Groups []UserGroup `json:"groups,omitempty,brackets"` + Groups []UserGroup `json:"groups,omitempty"` MgUserId uint64 `json:"mgUserId,omitempty"` } -// UserGroup type +// UserGroup type. type UserGroup struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` SignatureTemplate string `json:"signatureTemplate,omitempty"` IsManager bool `json:"isManager,omitempty"` IsDeliveryMen bool `json:"isDeliveryMen,omitempty"` - DeliveryTypes []string `json:"deliveryTypes,omitempty,brackets"` - BreakdownOrderTypes []string `json:"breakdownOrderTypes,omitempty,brackets"` - BreakdownSites []string `json:"breakdownSites,omitempty,brackets"` - BreakdownOrderMethods []string `json:"breakdownOrderMethods,omitempty,brackets"` - GrantedOrderTypes []string `json:"grantedOrderTypes,omitempty,brackets"` - GrantedSites []string `json:"grantedSites,omitempty,brackets"` + DeliveryTypes []string `json:"deliveryTypes,omitempty"` + BreakdownOrderTypes []string `json:"breakdownOrderTypes,omitempty"` + BreakdownSites []string `json:"breakdownSites,omitempty"` + BreakdownOrderMethods []string `json:"breakdownOrderMethods,omitempty"` + GrantedOrderTypes []string `json:"grantedOrderTypes,omitempty"` + GrantedSites []string `json:"grantedSites,omitempty"` } /** Task related types */ -// Task type +// Task type. type Task struct { ID int `json:"id,omitempty"` PerformerID int `json:"performerId,omitempty"` @@ -629,7 +629,7 @@ type Task struct { Notes related types */ -// Note type +// Note type. type Note struct { ID int `json:"id,omitempty"` ManagerID int `json:"managerId,omitempty"` @@ -642,7 +642,7 @@ type Note struct { Payments related types */ -// Payment type +// Payment type. type Payment struct { ID int `json:"id,omitempty"` ExternalID string `json:"externalId,omitempty"` @@ -658,7 +658,7 @@ type Payment struct { Segment related types */ -// Segment type +// Segment type. type Segment struct { ID int `json:"id,omitempty"` Code string `json:"code,omitempty"` @@ -690,7 +690,7 @@ type Settings struct { Reference related types */ -// CostGroup type +// CostGroup type. type CostGroup struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` @@ -699,7 +699,7 @@ type CostGroup struct { Ordering int `json:"ordering,omitempty"` } -// CostItem type +// CostItem type. type CostItem struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` @@ -712,7 +712,7 @@ type CostItem struct { Source *Source `json:"source,omitempty"` } -// Courier type +// Courier type. type Courier struct { ID int `json:"id,omitempty"` FirstName string `json:"firstName,omitempty"` @@ -724,14 +724,14 @@ type Courier struct { Phone *Phone `json:"phone,omitempty"` } -// DeliveryService type +// DeliveryService type. type DeliveryService struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` Active bool `json:"active,omitempty"` } -// DeliveryType type +// DeliveryType type. type DeliveryType struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` @@ -746,7 +746,7 @@ type DeliveryType struct { PaymentTypes []string `json:"paymentTypes,omitempty"` } -// LegalEntity type +// LegalEntity type. type LegalEntity struct { Code string `json:"code,omitempty"` VatRate string `json:"vatRate,omitempty"` @@ -768,7 +768,7 @@ type LegalEntity struct { BankAccount string `json:"bankAccount,omitempty"` } -// OrderMethod type +// OrderMethod type. type OrderMethod struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` @@ -777,7 +777,7 @@ type OrderMethod struct { DefaultForAPI bool `json:"defaultForApi,omitempty"` } -// OrderType type +// OrderType type. type OrderType struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` @@ -786,7 +786,7 @@ type OrderType struct { DefaultForAPI bool `json:"defaultForApi,omitempty"` } -// PaymentStatus type +// PaymentStatus type. type PaymentStatus struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` @@ -796,10 +796,10 @@ type PaymentStatus struct { PaymentComplete bool `json:"paymentComplete,omitempty"` Description string `json:"description,omitempty"` Ordering int `json:"ordering,omitempty"` - PaymentTypes []string `json:"paymentTypes,omitempty,brackets"` + PaymentTypes []string `json:"paymentTypes,omitempty"` } -// PaymentType type +// PaymentType type. type PaymentType struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` @@ -807,11 +807,11 @@ type PaymentType struct { DefaultForCRM bool `json:"defaultForCrm,omitempty"` DefaultForAPI bool `json:"defaultForApi,omitempty"` Description string `json:"description,omitempty"` - DeliveryTypes []string `json:"deliveryTypes,omitempty,brackets"` - PaymentStatuses []string `json:"PaymentStatuses,omitempty,brackets"` + DeliveryTypes []string `json:"deliveryTypes,omitempty"` + PaymentStatuses []string `json:"PaymentStatuses,omitempty"` } -// PriceType type +// PriceType type. type PriceType struct { ID int `json:"id,omitempty"` Code string `json:"code,omitempty"` @@ -821,11 +821,11 @@ type PriceType struct { Description string `json:"description,omitempty"` FilterExpression string `json:"filterExpression,omitempty"` Ordering int `json:"ordering,omitempty"` - Groups []string `json:"groups,omitempty,brackets"` - Geo []GeoHierarchyRow `json:"geo,omitempty,brackets"` + Groups []string `json:"groups,omitempty"` + Geo []GeoHierarchyRow `json:"geo,omitempty"` } -// ProductStatus type +// ProductStatus type. type ProductStatus struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` @@ -837,7 +837,7 @@ type ProductStatus struct { OrderStatusForProductStatus string `json:"orderStatusForProductStatus,omitempty"` } -// Status type +// Status type. type Status struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` @@ -846,17 +846,17 @@ type Status struct { Group string `json:"group,omitempty"` } -// StatusGroup type +// StatusGroup type. type StatusGroup struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` Active bool `json:"active,omitempty"` Ordering int `json:"ordering,omitempty"` Process bool `json:"process,omitempty"` - Statuses []string `json:"statuses,omitempty,brackets"` + Statuses []string `json:"statuses,omitempty"` } -// Site type +// Site type. type Site struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` @@ -873,7 +873,7 @@ type Site struct { Contragent *LegalEntity `json:"contragent,omitempty"` } -// Store type +// Store type. type Store struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` @@ -888,7 +888,7 @@ type Store struct { Address *Address `json:"address,omitempty"` } -// ProductGroup type +// ProductGroup type. type ProductGroup struct { ID int `json:"id,omitempty"` ParentID int `json:"parentId,omitempty"` @@ -897,7 +897,7 @@ type ProductGroup struct { Active bool `json:"active,omitempty"` } -// Product type +// Product type. type Product struct { ID int `json:"id,omitempty"` MaxPrice float32 `json:"maxPrice,omitempty"` @@ -915,19 +915,19 @@ type Product struct { Recommended bool `json:"recommended,omitempty"` Active bool `json:"active,omitempty"` Quantity float32 `json:"quantity,omitempty"` - Offers []Offer `json:"offers,omitempty,brackets"` - Groups []ProductGroup `json:"groups,omitempty,brackets"` - Properties map[string]string `json:"properties,omitempty,brackets"` + Offers []Offer `json:"offers,omitempty"` + Groups []ProductGroup `json:"groups,omitempty"` + Properties map[string]string `json:"properties,omitempty"` } -// DeliveryHistoryRecord type +// DeliveryHistoryRecord type. type DeliveryHistoryRecord struct { Code string `json:"code,omitempty"` UpdatedAt string `json:"updatedAt,omitempty"` Comment string `json:"comment,omitempty"` } -// DeliveryShipment type +// DeliveryShipment type. type DeliveryShipment struct { IntegrationCode string `json:"integrationCode,omitempty"` ID int `json:"id,omitempty"` @@ -940,11 +940,11 @@ type DeliveryShipment struct { Time *DeliveryTime `json:"time,omitempty"` LunchTime string `json:"lunchTime,omitempty"` Comment string `json:"comment,omitempty"` - Orders []Order `json:"orders,omitempty,brackets"` - ExtraData map[string]string `json:"extraData,omitempty,brackets"` + Orders []Order `json:"orders,omitempty"` + ExtraData map[string]string `json:"extraData,omitempty"` } -// IntegrationModule type +// IntegrationModule type. type IntegrationModule struct { Code string `json:"code,omitempty"` IntegrationCode string `json:"integrationCode,omitempty"` @@ -961,7 +961,7 @@ type IntegrationModule struct { Integrations *Integrations `json:"integrations,omitempty"` } -// Integrations type +// Integrations type. type Integrations struct { Telephony *Telephony `json:"telephony,omitempty"` Delivery *Delivery `json:"delivery,omitempty"` @@ -970,11 +970,11 @@ type Integrations struct { MgBot *MgBot `json:"mgBot,omitempty"` } -// Delivery type +// Delivery type. type Delivery struct { Description string `json:"description,omitempty"` - Actions map[string]string `json:"actions,omitempty,brackets"` - PayerType []string `json:"payerType,omitempty,brackets"` + Actions map[string]string `json:"actions,omitempty"` + PayerType []string `json:"payerType,omitempty"` PlatePrintLimit int `json:"platePrintLimit,omitempty"` RateDeliveryCost bool `json:"rateDeliveryCost,omitempty"` AllowPackages bool `json:"allowPackages,omitempty"` @@ -989,20 +989,20 @@ type Delivery struct { ShipmentDataFieldList []DeliveryDataField `json:"shipmentDataFieldList,omitempty"` } -// DeliveryStatus type +// DeliveryStatus type. type DeliveryStatus struct { Code string `json:"code,omitempty"` Name string `json:"name,omitempty"` IsEditable bool `json:"isEditable,omitempty"` } -// Plate type +// Plate type. type Plate struct { Code string `json:"code,omitempty"` Label string `json:"label,omitempty"` } -// DeliveryDataField type +// DeliveryDataField type. type DeliveryDataField struct { Code string `json:"code,omitempty"` Label string `json:"label,omitempty"` @@ -1015,7 +1015,7 @@ type DeliveryDataField struct { Editable bool `json:"editable,omitempty"` } -// Telephony type +// Telephony type. type Telephony struct { MakeCallURL string `json:"makeCallUrl,omitempty"` AllowEdit bool `json:"allowEdit,omitempty"` @@ -1023,47 +1023,47 @@ type Telephony struct { OutputEventSupported bool `json:"outputEventSupported,omitempty"` HangupEventSupported bool `json:"hangupEventSupported,omitempty"` ChangeUserStatusURL string `json:"changeUserStatusUrl,omitempty"` - AdditionalCodes []AdditionalCode `json:"additionalCodes,omitempty,brackets"` - ExternalPhones []ExternalPhone `json:"externalPhones,omitempty,brackets"` + AdditionalCodes []AdditionalCode `json:"additionalCodes,omitempty"` + ExternalPhones []ExternalPhone `json:"externalPhones,omitempty"` } -// AdditionalCode type +// AdditionalCode type. type AdditionalCode struct { Code string `json:"code,omitempty"` UserID string `json:"userId,omitempty"` } -// ExternalPhone type +// ExternalPhone type. type ExternalPhone struct { SiteCode string `json:"siteCode,omitempty"` ExternalPhone string `json:"externalPhone,omitempty"` } -// Warehouse type +// Warehouse type. type Warehouse struct { - Actions []Action `json:"actions,omitempty,brackets"` + Actions []Action `json:"actions,omitempty"` } -// Action type +// Action type. type Action struct { Code string `json:"code,omitempty"` URL string `json:"url,omitempty"` CallPoints []string `json:"callPoints,omitempty"` } -// MgTransport type +// MgTransport type. type MgTransport struct { WebhookUrl string `json:"webhookUrl,omitempty"` } -// MgBot type +// MgBot type. type MgBot struct{} /** Cost related types */ -// CostRecord type +// CostRecord type. type CostRecord struct { Source *Source `json:"source,omitempty"` Comment string `json:"comment,omitempty"` @@ -1073,10 +1073,10 @@ type CostRecord struct { CostItem string `json:"costItem,omitempty"` UserId int `json:"userId,omitempty"` Order *Order `json:"order,omitempty"` - Sites []string `json:"sites,omitempty,brackets"` + Sites []string `json:"sites,omitempty"` } -// Cost type +// Cost type. type Cost struct { Source *Source `json:"source,omitempty"` ID int `json:"id,omitempty"` @@ -1089,10 +1089,10 @@ type Cost struct { CreatedBy string `json:"createdBy,omitempty"` Order *Order `json:"order,omitempty"` UserId int `json:"userId,omitempty"` - Sites []string `json:"sites,omitempty,brackets"` + Sites []string `json:"sites,omitempty"` } -// File type +// File type. type File struct { ID int `json:"id,omitempty"` Filename string `json:"filename,omitempty"` @@ -1102,13 +1102,13 @@ type File struct { Attachment []Attachment `json:"attachment,omitempty"` } -// Attachment type +// Attachment type. type Attachment struct { Customer *Customer `json:"customer,omitempty"` Order *Order `json:"order,omitempty"` } -// CustomFields type +// CustomFields type. type CustomFields struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` @@ -1129,27 +1129,27 @@ type CustomFields struct { CustomDictionaries 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"` + Elements []Element `json:"elements,omitempty"` } -// Element type +// Element type. type Element struct { Name string `json:"name,omitempty"` Code string `json:"code,omitempty"` Ordering int `json:"ordering,omitempty"` } -// Activity struct +// Activity struct. type Activity struct { Active bool `json:"active"` Freeze bool `json:"freeze"` } -// Tag struct +// Tag struct. type Tag struct { Name string `json:"name,omitempty"` Color string `json:"color,omitempty"`