From ed9b0a439650c447053a3e47a92aa9977c2a6894 Mon Sep 17 00:00:00 2001 From: DmitryZagorulko Date: Thu, 12 Apr 2018 16:43:53 +0300 Subject: [PATCH] add documentation, bug fix --- v5/client.go | 1773 ++++++++++++++++++++++++++++++++++++++++----- v5/client_test.go | 236 +++--- v5/request.go | 7 +- 3 files changed, 1683 insertions(+), 333 deletions(-) diff --git a/v5/client.go b/v5/client.go index 3746a31..ac6bf00 100644 --- a/v5/client.go +++ b/v5/client.go @@ -148,6 +148,8 @@ func fillSite(p *url.Values, site []string) { // APIVersions get all available API versions for exact account // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-api-versions +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") @@ -155,11 +157,11 @@ func fillSite(p *url.Values, site []string) { // data, status, err := client.APIVersions() // // if err.RuntimeErr != nil { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // for _, value := range data.versions { @@ -184,6 +186,8 @@ func (c *Client) APIVersions() (VersionResponse, int, errs.Failure) { // APICredentials get all available API methods for exact account // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-api-versions +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") @@ -191,11 +195,11 @@ func (c *Client) APIVersions() (VersionResponse, int, errs.Failure) { // data, status, err := client.APICredentials() // // if err.RuntimeErr != nil { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // for _, value := range data.credentials { @@ -218,7 +222,32 @@ func (c *Client) APICredentials() (CredentialResponse, int, errs.Failure) { return resp, status, err } -// Customers list method +// Getting the list of customers matched the specified filter +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Customers(v5.CustomersRequest{ +// Filter: CustomersFilter{ +// City: "Moscow", +// }, +// Page: 3, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Customers { +// fmt.Printf("%v\n", value) +// } func (c *Client) Customers(parameters CustomersRequest) (CustomersResponse, int, errs.Failure) { var resp CustomersResponse @@ -238,7 +267,23 @@ func (c *Client) Customers(parameters CustomersRequest) (CustomersResponse, int, return resp, status, err } -// CustomersCombine method +// Combining of customers +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-combine +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomersCombine([]v5.Customer{{ID: 1}, {ID: 2}}, Customer{ID: 3}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -264,7 +309,37 @@ func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) return resp, status, err } -// CustomerCreate method +// Customer creation +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-create +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomersCombine(v5.Customer{ +// FirstName: "Ivan", +// LastName: "Ivanov", +// Patronymic: "Ivanovich", +// ExternalID: 1, +// Email: "ivanov@example.com", +// Address: &v5.Address{ +// City: "Moscow", +// Street: "Kutuzovsky", +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v", err.Id) +// } func (c *Client) CustomerCreate(customer Customer, site ...string) (CustomerChangeResponse, int, errs.Failure) { var resp CustomerChangeResponse @@ -290,7 +365,26 @@ func (c *Client) CustomerCreate(customer Customer, site ...string) (CustomerChan return resp, status, err } -// CustomersFixExternalIds method +// The mass recording of customers external ID +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-fix-external-ids +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomersFixExternalIds([]v5.IdentifiersPair{{ +// ID: 1, +// ExternalID: 12, +// }}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -314,7 +408,31 @@ func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (Successfu return resp, status, err } -// CustomersHistory method +// Getting the customer change history +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers-history +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomersHistory(v5.CustomersHistoryRequest{ +// Filter: v5.CustomersHistoryFilter{ +// SinceID: 20, +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.History { +// fmt.Printf("%v\n", value) +// } func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (CustomersHistoryResponse, int, errs.Failure) { var resp CustomersHistoryResponse @@ -334,7 +452,32 @@ func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (Customers return resp, status, err } -// CustomerNotes list method +// Getting the notes +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers-notes +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomerNotes(v5.NotesRequest{ +// Filter: v5.NotesFilter{ +// CustomerIds: []int{1,2,3} +// }, +// Page: 1, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Notes { +// fmt.Printf("%v\n", value) +// } func (c *Client) CustomerNotes(parameters NotesRequest) (NotesResponse, int, errs.Failure) { var resp NotesResponse @@ -354,7 +497,33 @@ func (c *Client) CustomerNotes(parameters NotesRequest) (NotesResponse, int, err return resp, status, err } -// CustomerNoteCreate method +// Note creation +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-notes-create +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomerNoteCreate(v5.Note{ +// Text: "some text", +// ManagerID: 12, +// Customer: &v5.Customer{ +// ID: 1, +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.ID) +// } func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, int, errs.Failure) { var resp CreateResponse @@ -380,7 +549,23 @@ func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, return resp, status, err } -// CustomerNoteDelete method +// Note removing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-notes-id-delete +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomerNoteDelete(12) + +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) CustomerNoteDelete(id int) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -402,7 +587,42 @@ func (c *Client) CustomerNoteDelete(id int) (SuccessfulResponse, int, errs.Failu return resp, status, err } -// CustomersUpload method +// Packet customers uploading +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-upload +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomersUpload([]v5.Customer{ +// { +// FirstName: "Ivan", +// LastName: "Ivanov", +// Patronymic: "Ivanovich", +// ExternalID: 1, +// Email: "ivanov@example.com", +// }, +// { +// FirstName: "Petr", +// LastName: "Petrov", +// Patronymic: "Petrovich", +// ExternalID: 2, +// Email: "petrov@example.com", +// }, +// }} +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.UploadedCustomers) +// } func (c *Client) CustomersUpload(customers []Customer, site ...string) (CustomersUploadResponse, int, errs.Failure) { var resp CustomersUploadResponse @@ -428,7 +648,27 @@ func (c *Client) CustomersUpload(customers []Customer, site ...string) (Customer return resp, status, err } -// Customer get method +// Getting information on customer +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers-externalId +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Customer(12, "externalId", "") +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.Customer) +// } func (c *Client) Customer(id, by, site string) (CustomerResponse, int, errs.Failure) { var resp CustomerResponse var context = checkBy(by) @@ -450,7 +690,36 @@ func (c *Client) Customer(id, by, site string) (CustomerResponse, int, errs.Fail return resp, status, err } -// CustomerEdit method +// Customer editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-externalId-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CustomerEdit( +// v5.Customer{ +// FirstName: "Ivan", +// LastName: "Ivanov", +// Patronymic: "Ivanovich", +// ID: 1, +// Email: "ivanov@example.com", +// }, +// "id", +// ) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.Customer) +// } func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (CustomerChangeResponse, int, errs.Failure) { var resp CustomerChangeResponse var uid = strconv.Itoa(customer.ID) @@ -483,7 +752,36 @@ func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (Cus return resp, status, err } -// DeliveryTracking method +// Updating of delivery statuses +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-delivery-generic-subcode-tracking +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.DeliveryTracking( +// v5.DeliveryTrackingRequest{ +// DeliveryID: "1", +// TrackNumber "123", +// History: []DeliveryHistoryRecord{ +// { +// Code: "cancel", +// UpdatedAt: "2012-12-12 12:12:12" +// }, +// } +// }, +// "delivery-1", +// ) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode string) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -507,7 +805,32 @@ func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode st return resp, status, err } -// DeliveryShipments method +// Getting the list of shipments to delivery services +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-delivery-shipments +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.DeliveryShipments(v5.DeliveryShipmentsRequest{ +// Limit: 12, +// Filter: v5.ShipmentFilter{ +// DateFrom: "2012-12-12", +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.DeliveryShipments { +// fmt.Printf("%v\n", value) +// } func (c *Client) DeliveryShipments(parameters DeliveryShipmentsRequest) (DeliveryShipmentsResponse, int, errs.Failure) { var resp DeliveryShipmentsResponse @@ -527,7 +850,37 @@ func (c *Client) DeliveryShipments(parameters DeliveryShipmentsRequest) (Deliver return resp, status, err } -// DeliveryShipmentCreate method +// Shipment creation +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-delivery-shipments-create +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.DeliveryShipmentCreate( +// v5.DeliveryShipment{ +// Date: "2012-12-12", +// Time: v5.DeliveryTime{ +// From: "18:00", +// To: "20:00", +// }, +// Orders: []v5.Order{{Number: "12"}}, +// }, +// "sdek", +// ) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.ID) +// } func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType string, site ...string) (DeliveryShipmentUpdateResponse, int, errs.Failure) { var resp DeliveryShipmentUpdateResponse updateJSON, _ := json.Marshal(&shipment) @@ -553,7 +906,27 @@ func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType return resp, status, err } -// DeliveryShipment method +// Getting information on shipment +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-delivery-shipments-id +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.DeliveryShipment(12) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.DeliveryShipment) +// } func (c *Client) DeliveryShipment(id int) (DeliveryShipmentResponse, int, errs.Failure) { var resp DeliveryShipmentResponse @@ -571,7 +944,29 @@ func (c *Client) DeliveryShipment(id int) (DeliveryShipmentResponse, int, errs.F return resp, status, err } -// DeliveryShipmentEdit method +// Shipment editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-delivery-shipments-id-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.DeliveryShipmentEdit(v5.DeliveryShipment{ +// ID: "12", +// Time: v5.DeliveryTime{ +// From: "14:00", +// To: "18:00", +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) (DeliveryShipmentUpdateResponse, int, errs.Failure) { var resp DeliveryShipmentUpdateResponse updateJSON, _ := json.Marshal(&shipment) @@ -596,7 +991,27 @@ func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) return resp, status, err } -// IntegrationModule method +// Getting the integration module +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-integration-modules-code +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.IntegrationModule("moysklad3") +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.IntegrationModule) +// } func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int, errs.Failure) { var resp IntegrationModuleResponse @@ -614,7 +1029,39 @@ func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int, return resp, status, err } -// IntegrationModuleEdit method +// Integration module creation/editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-integration-modules-code +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") + +// name := "MS" +// code := "moysklad3" + +// data, status, err := client.IntegrationModuleEdit(v5.IntegrationModule{ +// Code: code, +// IntegrationCode: code, +// Active: false, +// Name: fmt.Sprintf("Integration module %s", name), +// AccountURL: fmt.Sprintf("http://example.com/%s/account", name), +// BaseURL: fmt.Sprintf("http://example.com/%s", name), +// ClientID: "123", +// Logo: "https://cdn.worldvectorlogo.com/logos/github-icon.svg", +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.Info) +// } func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (IntegrationModuleEditResponse, int, errs.Failure) { var resp IntegrationModuleEditResponse updateJSON, _ := json.Marshal(&integrationModule) @@ -635,7 +1082,27 @@ func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (Int return resp, status, err } -// Orders list method +// Getting the list of orders matched the specified filter +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Orders(v5.OrdersRequest{Filter: v5.OrdersFilter{City: "Moscow"}, Page: 1}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Orders { +// fmt.Printf("%v\n", value) +// } func (c *Client) Orders(parameters OrdersRequest) (OrdersResponse, int, errs.Failure) { var resp OrdersResponse @@ -655,7 +1122,23 @@ func (c *Client) Orders(parameters OrdersRequest) (OrdersResponse, int, errs.Fai return resp, status, err } -// OrdersCombine method +// Combining of orders +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-combine +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrdersCombine("ours", v5.Order{ID: 1}, v5.Order{ID: 1}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (OperationResponse, int, errs.Failure) { var resp OperationResponse @@ -682,7 +1165,33 @@ func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (Oper return resp, status, err } -// OrderCreate method +// Order creation +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-create +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrderCreate(v5.Order{ +// FirstName: "Ivan", +// LastName: "Ivanov", +// Patronymic: "Ivanovich", +// Email: "ivanov@example.com", +// Items: []v5.OrderItem{{Offer: v5.Offer{ID: 12}, Quantity: 5}}, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.ID) +// } func (c *Client) OrderCreate(order Order, site ...string) (CreateResponse, int, errs.Failure) { var resp CreateResponse orderJSON, _ := json.Marshal(&order) @@ -707,7 +1216,30 @@ func (c *Client) OrderCreate(order Order, site ...string) (CreateResponse, int, return resp, status, err } -// OrdersFixExternalIds method +// The mass recording of orders external ID +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-fix-external-ids +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrdersFixExternalIds(([]v5.IdentifiersPair{{ +//// ID: 1, +//// ExternalID: 12, +//// }}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.ID) +// } func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -731,7 +1263,27 @@ func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulRespo return resp, status, err } -// OrdersHistory method +// Getting the order change history +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-history +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrdersHistory(v5.OrdersHistoryRequest{Filter: v5.OrdersHistoryFilter{SinceID: 20}}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.History { +// fmt.Printf("%v\n", value) +// } func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (CustomersHistoryResponse, int, errs.Failure) { var resp CustomersHistoryResponse @@ -751,7 +1303,33 @@ func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (CustomersHistor return resp, status, err } -// OrderPaymentCreate method +// Payment creation +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-payments-create +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrderPaymentCreate(v5.Payment{ +// Order: &v5.Order{ +// ID: 12, +// }, +// Amount: 300, +// Type: "cash", +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.ID) +// } func (c *Client) OrderPaymentCreate(payment Payment, site ...string) (CreateResponse, int, errs.Failure) { var resp CreateResponse @@ -777,7 +1355,23 @@ func (c *Client) OrderPaymentCreate(payment Payment, site ...string) (CreateResp return resp, status, err } -// OrderPaymentDelete method +// Payment removing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-payments-id-delete +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrderPaymentDelete(12) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) OrderPaymentDelete(id int) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -799,7 +1393,29 @@ func (c *Client) OrderPaymentDelete(id int) (SuccessfulResponse, int, errs.Failu return resp, status, err } -// OrderPaymentEdit method +// Payment editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-payments-id-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrderPaymentEdit( +// v5.Payment{ +// ID: 12, +// Amount: 500, +// }, +// "id", +// ) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse var uid = strconv.Itoa(payment.ID) @@ -831,7 +1447,42 @@ func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (S return resp, status, err } -// OrdersUpload method +// Packet orders uploading +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-upload +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrdersUpload([]v5.Order{ +// { +// FirstName: "Ivan", +// LastName: "Ivanov", +// Patronymic: "Ivanovich", +// Email: "ivanov@example.com", +// Items: []v5.OrderItem{{Offer: v5.Offer{ID: 12}, Quantity: 5}}, +// }, +// { +// FirstName: "Pert", +// LastName: "Petrov", +// Patronymic: "Petrovich", +// Email: "petrov@example.com", +// Items: []v5.OrderItem{{Offer: v5.Offer{ID: 13}, Quantity: 1}}, +// } +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.UploadedOrders) +// } func (c *Client) OrdersUpload(orders []Order, site ...string) (OrdersUploadResponse, int, errs.Failure) { var resp OrdersUploadResponse @@ -857,7 +1508,27 @@ func (c *Client) OrdersUpload(orders []Order, site ...string) (OrdersUploadRespo return resp, status, err } -// Order get method +// Getting information on order +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-externalId +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Order(12, "externalId", "") +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.Order) +// } func (c *Client) Order(id, by, site string) (OrderResponse, int, errs.Failure) { var resp OrderResponse var context = checkBy(by) @@ -879,7 +1550,29 @@ func (c *Client) Order(id, by, site string) (OrderResponse, int, errs.Failure) { return resp, status, err } -// OrderEdit method +// Order editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-externalId-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrderEdit( +// v5.Order{ +// ID: 12, +// Items: []v5.OrderItem{{Offer: v5.Offer{ID: 13}, Quantity: 6}}, +// }, +// "id", +// ) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateResponse, int, errs.Failure) { var resp CreateResponse var uid = strconv.Itoa(order.ID) @@ -912,7 +1605,27 @@ func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateRespon return resp, status, err } -// Packs list method +// Getting the list of packs matched the specified filter +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-packs +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Packs(v5.PacksRequest{Filter: v5.PacksFilter{OrderID: 12}}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Packs { +// fmt.Printf("%v\n", value) +// } func (c *Client) Packs(parameters PacksRequest) (PacksResponse, int, errs.Failure) { var resp PacksResponse @@ -932,7 +1645,31 @@ func (c *Client) Packs(parameters PacksRequest) (PacksResponse, int, errs.Failur return resp, status, err } -// PackCreate method +// Pack creation +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-packs-create +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.PackCreate(Pack{ +// Store: "store-1", +// ItemID: 12, +// Quantity: 1, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.ID) +// } func (c *Client) PackCreate(pack Pack) (CreateResponse, int, errs.Failure) { var resp CreateResponse packJSON, _ := json.Marshal(&pack) @@ -955,7 +1692,27 @@ func (c *Client) PackCreate(pack Pack) (CreateResponse, int, errs.Failure) { return resp, status, err } -// PacksHistory method +// Getting the history of order packing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-packs-history +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.PacksHistory(v5.PacksHistoryRequest{Filter: v5.OrdersHistoryFilter{SinceID: 5}}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.History { +// fmt.Printf("%v\n", value) +// } func (c *Client) PacksHistory(parameters PacksHistoryRequest) (PacksHistoryResponse, int, errs.Failure) { var resp PacksHistoryResponse @@ -975,7 +1732,26 @@ func (c *Client) PacksHistory(parameters PacksHistoryRequest) (PacksHistoryRespo return resp, status, err } -// Pack get method +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-packs-id +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Pack(112) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.Pack) +// } func (c *Client) Pack(id int) (PackResponse, int, errs.Failure) { var resp PackResponse @@ -993,7 +1769,23 @@ func (c *Client) Pack(id int) (PackResponse, int, errs.Failure) { return resp, status, err } -// PackDelete method +// Pack removing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-packs-id-delete +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.PackDelete(112) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) PackDelete(id int) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1011,7 +1803,23 @@ func (c *Client) PackDelete(id int) (SuccessfulResponse, int, errs.Failure) { return resp, status, err } -// PackEdit method +// Pack editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-packs-id-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.PackEdit(Pack{ID: 12, Quantity: 2}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) PackEdit(pack Pack) (CreateResponse, int, errs.Failure) { var resp CreateResponse @@ -1035,7 +1843,9 @@ func (c *Client) PackEdit(pack Pack) (CreateResponse, int, errs.Failure) { return resp, status, err } -// Countries method +// Getting the list of available country codes +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-countries func (c *Client) Countries() (CountriesResponse, int, errs.Failure) { var resp CountriesResponse @@ -1053,7 +1863,9 @@ func (c *Client) Countries() (CountriesResponse, int, errs.Failure) { return resp, status, err } -// CostGroups method +// Getting of the costs groups list +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-cost-groups func (c *Client) CostGroups() (CostGroupsResponse, int, errs.Failure) { var resp CostGroupsResponse @@ -1071,7 +1883,26 @@ func (c *Client) CostGroups() (CostGroupsResponse, int, errs.Failure) { return resp, status, err } -// CostGroupEdit method +// Editing costs groups +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-cost-groups-code-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CostGroupEdit(v5.CostGroup{ +// Code: "group-1", +// Color: "#da5c98", +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) CostGroupEdit(costGroup CostGroup) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1095,7 +1926,9 @@ func (c *Client) CostGroupEdit(costGroup CostGroup) (SuccessfulResponse, int, er return resp, status, err } -// CostItems method +// Getting of the costs items list +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-cost-items func (c *Client) CostItems() (CostItemsResponse, int, errs.Failure) { var resp CostItemsResponse @@ -1113,7 +1946,26 @@ func (c *Client) CostItems() (CostItemsResponse, int, errs.Failure) { return resp, status, err } -// CostItemEdit method +// Editing costs items +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-cost-items-code-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CostItemEdit(v5.CostItem{ +// Code: "seo", +// Active: false, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) CostItemEdit(costItem CostItem) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1137,7 +1989,9 @@ func (c *Client) CostItemEdit(costItem CostItem) (SuccessfulResponse, int, errs. return resp, status, err } -// Couriers method +// Getting the list of couriers +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-couriers func (c *Client) Couriers() (CouriersResponse, int, errs.Failure) { var resp CouriersResponse @@ -1155,7 +2009,32 @@ func (c *Client) Couriers() (CouriersResponse, int, errs.Failure) { return resp, status, err } -// CourierCreate method +// Courier creation +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-couriers +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CostItemEdit(v5.Courier{ +// Active: true, +// Email: "courier1@example.com", +// FirstName: "Ivan", +// LastName: "Ivanov", +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v", data.ID) +// } func (c *Client) CourierCreate(courier Courier) (CreateResponse, int, errs.Failure) { var resp CreateResponse @@ -1179,7 +2058,26 @@ func (c *Client) CourierCreate(courier Courier) (CreateResponse, int, errs.Failu return resp, status, err } -// CourierEdit method +// Courier editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-couriers-id-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.CostItemEdit(v5.Courier{ +// ID: 1, +// Patronymic: "Ivanovich", +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) CourierEdit(courier Courier) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1203,7 +2101,9 @@ func (c *Client) CourierEdit(courier Courier) (SuccessfulResponse, int, errs.Fai return resp, status, err } -// DeliveryServices method +// Getting the list of delivery services +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-delivery-services func (c *Client) DeliveryServices() (DeliveryServiceResponse, int, errs.Failure) { var resp DeliveryServiceResponse @@ -1221,7 +2121,26 @@ func (c *Client) DeliveryServices() (DeliveryServiceResponse, int, errs.Failure) return resp, status, err } -// DeliveryServiceEdit method +// Delivery service creation/editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-delivery-services-code-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.DeliveryServiceEdit(v5.DeliveryService{ +// Active: false, +// Code: "delivery-1", +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1245,7 +2164,9 @@ func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (Successfu return resp, status, err } -// DeliveryTypes method +// Getting the list of delivery types +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-delivery-types func (c *Client) DeliveryTypes() (DeliveryTypesResponse, int, errs.Failure) { var resp DeliveryTypesResponse @@ -1263,7 +2184,28 @@ func (c *Client) DeliveryTypes() (DeliveryTypesResponse, int, errs.Failure) { return resp, status, err } -// DeliveryTypeEdit method +// Delivery type creation/editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-delivery-types-code-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.DeliveryTypeEdit(v5.DeliveryType{ +// Active: false, +// Code: "type-1", +// DefaultCost: 300, +// DefaultForCrm: false, +// } +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1287,7 +2229,9 @@ func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (SuccessfulResponse return resp, status, err } -// LegalEntities method +// Getting the list of legal entities +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-legal-entities func (c *Client) LegalEntities() (LegalEntitiesResponse, int, errs.Failure) { var resp LegalEntitiesResponse @@ -1305,7 +2249,26 @@ func (c *Client) LegalEntities() (LegalEntitiesResponse, int, errs.Failure) { return resp, status, err } -// LegalEntityEdit method +// Editing of information on legal entity +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-legal-entities-code-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.LegalEntityEdit(v5.LegalEntity{ +// Code: "legal-entity-1", +// CertificateDate: "2012-12-12", +// } +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1329,7 +2292,9 @@ func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (SuccessfulResponse, i return resp, status, err } -// OrderMethods method +// Getting the list of order methods +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-order-methods func (c *Client) OrderMethods() (OrderMethodsResponse, int, errs.Failure) { var resp OrderMethodsResponse @@ -1347,7 +2312,27 @@ func (c *Client) OrderMethods() (OrderMethodsResponse, int, errs.Failure) { return resp, status, err } -// OrderMethodEdit method +// Order method creation/editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-order-methods-code-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrderMethodEdit(v5.OrderMethod{ +// Code: "method-1", +// Active: false, +// DefaultForCRM: false, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1371,7 +2356,9 @@ func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (SuccessfulResponse, i return resp, status, err } -// OrderTypes method +// Getting the list of order types +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-order-types func (c *Client) OrderTypes() (OrderTypesResponse, int, errs.Failure) { var resp OrderTypesResponse @@ -1389,7 +2376,26 @@ func (c *Client) OrderTypes() (OrderTypesResponse, int, errs.Failure) { return resp, status, err } -// OrderTypeEdit method +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-order-methods-code-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrderTypeEdit(v5.OrderType{ +// Code: "order-type-1", +// Active: false, +// DefaultForCRM: false, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) OrderTypeEdit(orderType OrderType) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1413,7 +2419,9 @@ func (c *Client) OrderTypeEdit(orderType OrderType) (SuccessfulResponse, int, er return resp, status, err } -// PaymentStatuses method +// Getting the list of payment statuses +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-payment-statuses func (c *Client) PaymentStatuses() (PaymentStatusesResponse, int, errs.Failure) { var resp PaymentStatusesResponse @@ -1431,7 +2439,9 @@ func (c *Client) PaymentStatuses() (PaymentStatusesResponse, int, errs.Failure) return resp, status, err } -// PaymentStatusEdit method +// Payment status creation/editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-payment-statuses-code-edit func (c *Client) PaymentStatusEdit(paymentStatus PaymentStatus) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1455,7 +2465,9 @@ func (c *Client) PaymentStatusEdit(paymentStatus PaymentStatus) (SuccessfulRespo return resp, status, err } -// PaymentTypes method +// Getting the list of payment types +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-payment-types func (c *Client) PaymentTypes() (PaymentTypesResponse, int, errs.Failure) { var resp PaymentTypesResponse @@ -1473,7 +2485,9 @@ func (c *Client) PaymentTypes() (PaymentTypesResponse, int, errs.Failure) { return resp, status, err } -// PaymentTypeEdit method +// Payment type creation/editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-payment-types-code-edit func (c *Client) PaymentTypeEdit(paymentType PaymentType) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1497,7 +2511,9 @@ func (c *Client) PaymentTypeEdit(paymentType PaymentType) (SuccessfulResponse, i return resp, status, err } -// PriceTypes method +// Getting the list of price types +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-price-types func (c *Client) PriceTypes() (PriceTypesResponse, int, errs.Failure) { var resp PriceTypesResponse @@ -1515,7 +2531,9 @@ func (c *Client) PriceTypes() (PriceTypesResponse, int, errs.Failure) { return resp, status, err } -// PriceTypeEdit method +// Price type creation/editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-price-types-code-edit func (c *Client) PriceTypeEdit(priceType PriceType) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1539,7 +2557,9 @@ func (c *Client) PriceTypeEdit(priceType PriceType) (SuccessfulResponse, int, er return resp, status, err } -// ProductStatuses method +// Getting the list of item statuses in order +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-product-statuses func (c *Client) ProductStatuses() (ProductStatusesResponse, int, errs.Failure) { var resp ProductStatusesResponse @@ -1557,7 +2577,9 @@ func (c *Client) ProductStatuses() (ProductStatusesResponse, int, errs.Failure) return resp, status, err } -// ProductStatusEdit method +// Item status creation/editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-product-statuses-code-edit func (c *Client) ProductStatusEdit(productStatus ProductStatus) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1581,7 +2603,9 @@ func (c *Client) ProductStatusEdit(productStatus ProductStatus) (SuccessfulRespo return resp, status, err } -// Sites method +// Getting the stores list +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-sites func (c *Client) Sites() (SitesResponse, int, errs.Failure) { var resp SitesResponse @@ -1599,7 +2623,9 @@ func (c *Client) Sites() (SitesResponse, int, errs.Failure) { return resp, status, err } -// SiteEdit method +// Store creation/editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-sites-code-edit func (c *Client) SiteEdit(site Site) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1623,7 +2649,9 @@ func (c *Client) SiteEdit(site Site) (SuccessfulResponse, int, errs.Failure) { return resp, status, err } -// StatusGroups method +// Getting the list of order status groups +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-status-groups func (c *Client) StatusGroups() (StatusGroupsResponse, int, errs.Failure) { var resp StatusGroupsResponse @@ -1641,7 +2669,9 @@ func (c *Client) StatusGroups() (StatusGroupsResponse, int, errs.Failure) { return resp, status, err } -// Statuses method +// Getting the list of order statuses +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-statuses func (c *Client) Statuses() (StatusesResponse, int, errs.Failure) { var resp StatusesResponse @@ -1659,7 +2689,9 @@ func (c *Client) Statuses() (StatusesResponse, int, errs.Failure) { return resp, status, err } -// StatusEdit method +// Order status creation/editing +// +// For more information see www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-sites-code-edit func (c *Client) StatusEdit(st Status) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1683,7 +2715,9 @@ func (c *Client) StatusEdit(st Status) (SuccessfulResponse, int, errs.Failure) { return resp, status, err } -// Stores method +// Getting the list of warehouses +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-stores func (c *Client) Stores() (StoresResponse, int, errs.Failure) { var resp StoresResponse @@ -1701,7 +2735,9 @@ func (c *Client) Stores() (StoresResponse, int, errs.Failure) { return resp, status, err } -// StoreEdit method +// Editing of information on warehouse +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-stores-code-edit func (c *Client) StoreEdit(store Store) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -1725,7 +2761,31 @@ func (c *Client) StoreEdit(store Store) (SuccessfulResponse, int, errs.Failure) return resp, status, err } -// Segments get segments +// Get segments +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-segments +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Segments(SegmentsRequest{ +// Filter: v5.SegmentsFilter{ +// Ids: []int{1,2,3} +// } +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Segments { +// fmt.Printf("%v\n", value) +// } func (c *Client) Segments(parameters SegmentsRequest) (SegmentsResponse, int, errs.Failure) { var resp SegmentsResponse @@ -1745,7 +2805,27 @@ func (c *Client) Segments(parameters SegmentsRequest) (SegmentsResponse, int, er return resp, status, err } -// Inventories method +// Getting the leftover stocks and purchasing prices +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-store-inventories +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Inventories(v5.InventoriesRequest{Filter: v5.InventoriesFilter{Details: 1, ProductActive: 1}, Page: 1}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Offers { +// fmt.Printf("%v\n", value) +// } func (c *Client) Inventories(parameters InventoriesRequest) (InventoriesResponse, int, errs.Failure) { var resp InventoriesResponse @@ -1765,7 +2845,44 @@ func (c *Client) Inventories(parameters InventoriesRequest) (InventoriesResponse return resp, status, err } -// InventoriesUpload method +// Updating the leftover stocks and purchasing prices +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-store-inventories-upload +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := clientc.InventoriesUpload( +// []v5.InventoryUpload{ +// { +// XMLID: "pTKIKAeghYzX21HTdzFCe1", +// Stores: []InventoryUploadStore{ +// {Code: "test-store-v5", Available: 10, PurchasePrice: 1500}, +// {Code: "test-store-v4", Available: 20, PurchasePrice: 1530}, +// {Code: "test-store", Available: 30, PurchasePrice: 1510}, +// }, +// }, +// { +// XMLID: "JQIvcrCtiSpOV3AAfMiQB3", +// Stores: []InventoryUploadStore{ +// {Code: "test-store-v5", Available: 45, PurchasePrice: 1500}, +// {Code: "test-store-v4", Available: 32, PurchasePrice: 1530}, +// {Code: "test-store", Available: 46, PurchasePrice: 1510}, +// }, +// }, +// }, +// ) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// fmt.Printf("%v\n", data.NotFoundOffers) func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string) (StoreUploadResponse, int, errs.Failure) { var resp StoreUploadResponse @@ -1791,7 +2908,36 @@ func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string return resp, status, err } -// PricesUpload method +// Offers prices updating +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-store-prices-upload +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.PricesUpload([]v5.OfferPriceUpload{ +// { +// ID 1 +// Site "store-1" +// Prices []PriceUpload{{Code: "price-1"}} +// }, +// { +// ID 2 +// Site "store-1" +// Prices []PriceUpload{{Code: "price-2"}} +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// fmt.Printf("%v\n", data.NotFoundOffers) func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, int, errs.Failure) { var resp StoreUploadResponse @@ -1815,7 +2961,31 @@ func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, i return resp, status, err } -// ProductsGroup method +// Getting the list of product groups +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-store-product-groups +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.ProductsGroup(v5.ProductsGroupsRequest{ +// Filter: v5.ProductsGroupsFilter{ +// Active: 1, +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.ProductGroup { +// fmt.Printf("%v\n", value) +// } func (c *Client) ProductsGroup(parameters ProductsGroupsRequest) (ProductsGroupsResponse, int, errs.Failure) { var resp ProductsGroupsResponse @@ -1835,7 +3005,32 @@ func (c *Client) ProductsGroup(parameters ProductsGroupsRequest) (ProductsGroups return resp, status, err } -// Products method +// Getting the list of products and SKU +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-store-products +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Products(v5.ProductsRequest{ +// Filter: v5.ProductsFilter{ +// Active: 1, +// MinPrice: 1000, +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Products { +// fmt.Printf("%v\n", value) +// } func (c *Client) Products(parameters ProductsRequest) (ProductsResponse, int, errs.Failure) { var resp ProductsResponse @@ -1855,7 +3050,31 @@ func (c *Client) Products(parameters ProductsRequest) (ProductsResponse, int, er return resp, status, err } -// ProductsProperties method +// Getting the list of item properties, matching the specified filter +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-store-products-properties +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.ProductsProperties(v5.ProductsPropertiesRequest{ +// Filter: v5.ProductsPropertiesFilter{ +// Sites: []string["store"], +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Properties { +// fmt.Printf("%v\n", value) +// } func (c *Client) ProductsProperties(parameters ProductsPropertiesRequest) (ProductsPropertiesResponse, int, errs.Failure) { var resp ProductsPropertiesResponse @@ -1875,7 +3094,31 @@ func (c *Client) ProductsProperties(parameters ProductsPropertiesRequest) (Produ return resp, status, err } -// Tasks list method +// Getting the task list +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-tasks +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Tasks(v5.TasksRequest{ +// Filter: TasksFilter{ +// DateFrom: "2012-12-12", +// }, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Tasks { +// fmt.Printf("%v\n", value) +// } func (c *Client) Tasks(parameters TasksRequest) (TasksResponse, int, errs.Failure) { var resp TasksResponse @@ -1895,7 +3138,30 @@ func (c *Client) Tasks(parameters TasksRequest) (TasksResponse, int, errs.Failur return resp, status, err } -// TaskCreate method +// Task creation +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-tasks-create +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Tasks(v5.Task{ +// Text: "task №1", +// PerformerID: 12, +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.ID) +// } func (c *Client) TaskCreate(task Task, site ...string) (CreateResponse, int, errs.Failure) { var resp CreateResponse taskJSON, _ := json.Marshal(&task) @@ -1920,7 +3186,27 @@ func (c *Client) TaskCreate(task Task, site ...string) (CreateResponse, int, err return resp, status, err } -// Task get method +// Getting information on task +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-tasks-id +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Task(12) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.Task) +// } func (c *Client) Task(id int) (TaskResponse, int, errs.Failure) { var resp TaskResponse @@ -1937,8 +3223,26 @@ func (c *Client) Task(id int) (TaskResponse, int, errs.Failure) { return resp, status, err } - -// TaskEdit method +// Task editing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-tasks-id-edit +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Task(v5.Task{ +// ID: 12 +// Text: "task №2", +// }) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) TaskEdit(task Task, site ...string) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse var uid = strconv.Itoa(task.ID) @@ -1965,7 +3269,27 @@ func (c *Client) TaskEdit(task Task, site ...string) (SuccessfulResponse, int, e return resp, status, err } -// UserGroups list method +// Getting the list of user groups +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-user-groups +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.UserGroups(v5.UserGroupsRequest{Page: 1}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Groups { +// fmt.Printf("%v\n", value) +// } func (c *Client) UserGroups(parameters UserGroupsRequest) (UserGroupsResponse, int, errs.Failure) { var resp UserGroupsResponse @@ -1985,7 +3309,27 @@ func (c *Client) UserGroups(parameters UserGroupsRequest) (UserGroupsResponse, i return resp, status, err } -// Users list method +// Getting the list of users matched the specified filter +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-users +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.Users(v5.UsersRequest{Filter: v5.UsersFilter{Active: 1}, Page: 1}) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// for _, value := range data.Users { +// fmt.Printf("%v\n", value) +// } func (c *Client) Users(parameters UsersRequest) (UsersResponse, int, errs.Failure) { var resp UsersResponse @@ -2005,7 +3349,27 @@ func (c *Client) Users(parameters UsersRequest) (UsersResponse, int, errs.Failur return resp, status, err } -// User get method +// Getting information on user +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-users-id +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.User(12) +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if data.Success == true { +// fmt.Printf("%v\n", data.User) +// } func (c *Client) User(id int) (UserResponse, int, errs.Failure) { var resp UserResponse @@ -2023,7 +3387,23 @@ func (c *Client) User(id int) (UserResponse, int, errs.Failure) { return resp, status, err } -// UserStatus update method +// Change user status +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-users +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.UserStatus(12, "busy") +// +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.RuntimeErr) +// } func (c *Client) UserStatus(id int, status string) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -2045,7 +3425,9 @@ func (c *Client) UserStatus(id int, status string) (SuccessfulResponse, int, err return resp, st, err } -// StaticticsUpdate update statistic +// Statistics updating +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-statistic-update func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse @@ -2065,6 +3447,8 @@ func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, errs.Failure) { // Getting of the cost list, adequate for the given filter // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-costs +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") @@ -2076,25 +3460,25 @@ func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, errs.Failure) { // }, // }) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // for _, value := range data.Costs { // fmt.Printf("%v\n", value.Summ) // } -func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, ErrorResponse) { +func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, errs.Failure) { var resp CostsResponse params, _ := query.Values(costs) data, status, err := c.GetRequest(fmt.Sprintf("/costs?%s", params.Encode())) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2105,6 +3489,8 @@ func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, ErrorResponse) { // Creation of the cost // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-create +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") @@ -2123,18 +3509,18 @@ func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, ErrorResponse) { // "store" // ) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("%v", data.ID) // } -func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, int, ErrorResponse) { +func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, int, errs.Failure) { var resp CreateResponse costJSON, _ := json.Marshal(&cost) @@ -2146,7 +3532,7 @@ func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, in fillSite(&p, site) data, status, err := c.PostRequest("/costs/create", p) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2155,7 +3541,9 @@ func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, in return resp, status, err } -// Method allows to remove batch up to 50 costs. +// Cost removing +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-delete // // Example: // @@ -2163,18 +3551,18 @@ func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, in // // data, status, err := client.client.CostsDelete([]int{1, 2, 3, 48, 49, 50}) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("Not removed costs: %v", data.NotRemovedIds) // } -func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, ErrorResponse) { +func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, errs.Failure) { var resp CostsDeleteResponse costJSON, _ := json.Marshal(&ids) @@ -2184,7 +3572,7 @@ func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, ErrorResponse } data, status, err := c.PostRequest("/costs/delete", p) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2193,7 +3581,9 @@ func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, ErrorResponse return resp, status, err } -// Method allows to upload as packet up to 50 costs. +// Batch loading of costs +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-upload // // Example: // @@ -2218,18 +3608,18 @@ func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, ErrorResponse // } // }) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("Uploaded costs: %v", data.UploadedCosts) // } -func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, ErrorResponse) { +func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, errs.Failure) { var resp CostsUploadResponse costJSON, _ := json.Marshal(&cost) @@ -2239,7 +3629,7 @@ func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, Error } data, status, err := c.PostRequest("/costs/upload", p) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2250,29 +3640,31 @@ func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, Error // Getting of cost information // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-costs-id +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") // // data, status, err := client.Cost(1) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("%v", data.Cost) // } -func (c *Client) Cost(id int) (CostResponse, int, ErrorResponse) { +func (c *Client) Cost(id int) (CostResponse, int, errs.Failure) { var resp CostResponse data, status, err := c.GetRequest(fmt.Sprintf("/costs/%d", id)) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2283,20 +3675,22 @@ func (c *Client) Cost(id int) (CostResponse, int, ErrorResponse) { // Cost removing // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-id-delete +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") // // data, status, err := client.CostDelete(1) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } -func (c *Client) CostDelete(id int) (SuccessfulResponse, int, ErrorResponse) { +func (c *Client) CostDelete(id int) (SuccessfulResponse, int, errs.Failure) { var resp SuccessfulResponse costJSON, _ := json.Marshal(&id) @@ -2307,7 +3701,7 @@ func (c *Client) CostDelete(id int) (SuccessfulResponse, int, ErrorResponse) { data, status, err := c.PostRequest(fmt.Sprintf("/costs/%d/delete", id), p) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2318,6 +3712,8 @@ func (c *Client) CostDelete(id int) (SuccessfulResponse, int, ErrorResponse) { // Cost editing // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-id-edit +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") @@ -2329,18 +3725,18 @@ func (c *Client) CostDelete(id int) (SuccessfulResponse, int, ErrorResponse) { // CostItem: "seo", // }) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("%v", data.Id) // } -func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateResponse, int, ErrorResponse) { +func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateResponse, int, errs.Failure) { var resp CreateResponse costJSON, _ := json.Marshal(&cost) @@ -2352,7 +3748,7 @@ func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateRespon fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/costs/%d/edit", id), p) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2363,6 +3759,8 @@ func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateRespon // Getting the list of custom fields // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-custom-fields +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") @@ -2372,25 +3770,25 @@ func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateRespon // Entity: "customer", // }) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // for _, value := range data.CustomFields { // fmt.Printf("%v\n", value) // } -func (c *Client) CustomFields(customFields CustomFieldsRequest) (CustomFieldsResponse, int, ErrorResponse) { +func (c *Client) CustomFields(customFields CustomFieldsRequest) (CustomFieldsResponse, int, errs.Failure) { var resp CustomFieldsResponse params, _ := query.Values(customFields) data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields?%s", params.Encode())) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2401,6 +3799,8 @@ func (c *Client) CustomFields(customFields CustomFieldsRequest) (CustomFieldsRes // Getting the list of custom directory // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-custom-fields-dictionaries +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") @@ -2411,25 +3811,25 @@ func (c *Client) CustomFields(customFields CustomFieldsRequest) (CustomFieldsRes // }, // }) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // for _, value := range data.CustomDictionaries { // fmt.Printf("%v\n", value.Elements) // } -func (c *Client) CustomDictionaries(customDictionaries CustomDictionariesRequest) (CustomDictionariesResponse, int, ErrorResponse) { +func (c *Client) CustomDictionaries(customDictionaries CustomDictionariesRequest) (CustomDictionariesResponse, int, errs.Failure) { var resp CustomDictionariesResponse params, _ := query.Values(customDictionaries) data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields/dictionaries?%s", params.Encode())) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2440,6 +3840,8 @@ func (c *Client) CustomDictionaries(customDictionaries CustomDictionariesRequest // Directory fields creation // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-custom-fields-dictionaries-create +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") @@ -2459,18 +3861,18 @@ func (c *Client) CustomDictionaries(customDictionaries CustomDictionariesRequest // }, // }) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("%v", data.Code) // } -func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (CustomResponse, int, ErrorResponse) { +func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (CustomResponse, int, errs.Failure) { var resp CustomResponse costJSON, _ := json.Marshal(&customDictionary) @@ -2481,7 +3883,7 @@ func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (Cu data, status, err := c.PostRequest("/custom-fields/dictionaries/create", p) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2492,29 +3894,31 @@ func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (Cu // Getting information on directory // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-custom-fields-entity-code +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") // // data, status, err := client.CustomDictionary("courier-profiles") // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("%v", data.CustomDictionary.Name) // } -func (c *Client) CustomDictionary(code string) (CustomDictionaryResponse, int, ErrorResponse) { +func (c *Client) CustomDictionary(code string) (CustomDictionaryResponse, int, errs.Failure) { var resp CustomDictionaryResponse data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields/dictionaries/%s", code)) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2525,6 +3929,8 @@ func (c *Client) CustomDictionary(code string) (CustomDictionaryResponse, int, E // Directory fields editing // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-custom-fields-dictionaries-code-edit +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") @@ -2544,18 +3950,18 @@ func (c *Client) CustomDictionary(code string) (CustomDictionaryResponse, int, E // }, // }) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("%v", data.Code) // } -func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (CustomResponse, int, ErrorResponse) { +func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (CustomResponse, int, errs.Failure) { var resp CustomResponse costJSON, _ := json.Marshal(&customDictionary) @@ -2565,7 +3971,7 @@ func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (Custom } data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/dictionaries/%s/edit", customDictionary.Code), p) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2576,32 +3982,32 @@ func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (Custom // Custom fields creation // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-custom-fields-entity-create +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") // -// data, status, err := client.CustomFieldsCreate(v5.CustomFieldsEditRequest{ -// CustomField: v5.CustomFields{ -// Name: "First order", -// Code: "first-order", -// Type: "bool", -// Entity: "order", -// DisplayArea: "customer", -// }, +// data, status, err := client.CustomFieldsCreate(CustomFields{ +// Name: "First order", +// Code: "first-order", +// Type: "bool", +// Entity: "order", +// DisplayArea: "customer", // }) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("%v", data.Code) // } -func (c *Client) CustomFieldsCreate(customFields CustomFieldsEditRequest) (CustomResponse, int, ErrorResponse) { +func (c *Client) CustomFieldsCreate(customFields CustomFields) (CustomResponse, int, errs.Failure) { var resp CustomResponse costJSON, _ := json.Marshal(&customFields) @@ -2610,9 +4016,9 @@ func (c *Client) CustomFieldsCreate(customFields CustomFieldsEditRequest) (Custo "customField": {string(costJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/%s/create", customFields.CustomField.Entity), p) + data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/%s/create", customFields.Entity), p) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2623,29 +4029,31 @@ func (c *Client) CustomFieldsCreate(customFields CustomFieldsEditRequest) (Custo // Getting information on custom fields // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-custom-fields-entity-code +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") // // data, status, err := client.CustomField("order", "first-order") // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("%v", data.CustomField) // } -func (c *Client) CustomField(entity, code string) (CustomFieldResponse, int, ErrorResponse) { +func (c *Client) CustomField(entity, code string) (CustomFieldResponse, int, errs.Failure) { var resp CustomFieldResponse data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields/%s/%s", entity, code)) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } @@ -2656,29 +4064,30 @@ func (c *Client) CustomField(entity, code string) (CustomFieldResponse, int, Err // CustomFieldEdit list method // +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-custom-fields-entity-code-edit +// // Example: // // var client = v5.New("https://demo.url", "09jIJ") // -// data, status, err := client.CustomFieldEdit("order", v5.CustomFieldsEditRequest{ -// CustomField: v5.CustomFields{ -// Name: "First customer order", -// Code: "first-order", -// }, -// }) +// data, status, err := client.CustomFieldEdit(CustomFields{ +// Code: "first-order", +// Entity: "order", +// DisplayArea: "delivery", +// }) // -// if err.ErrorMsg != "" { -// fmt.Printf("%v", err.ErrorMsg) +// if err.RuntimeErr != nil { +// fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ErrorMsg) +// fmt.Printf("%v", err.RuntimeErr) // } // // If data.Success == true { // fmt.Printf("%v", data.Code) // } -func (c *Client) CustomFieldEdit(entity string, customFields CustomFieldsEditRequest) (CustomResponse, int, ErrorResponse) { +func (c *Client) CustomFieldEdit(customFields CustomFields) (CustomResponse, int, errs.Failure) { var resp CustomResponse costJSON, _ := json.Marshal(&customFields) @@ -2687,9 +4096,9 @@ func (c *Client) CustomFieldEdit(entity string, customFields CustomFieldsEditReq "customField": {string(costJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/%s/%s/edit", entity, customFields.CustomField.Code), p) + data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/%s/%s/edit", customFields.Entity, customFields.Code), p) - if err.ErrorMsg != "" { + if err.RuntimeErr != nil { return resp, status, err } diff --git a/v5/client_test.go b/v5/client_test.go index f5fe87e..5548a75 100644 --- a/v5/client_test.go +++ b/v5/client_test.go @@ -16,6 +16,7 @@ var user, _ = strconv.Atoi(os.Getenv("RETAILCRM_USER")) var statuses = map[int]bool{http.StatusOK: true, http.StatusCreated: true} var id int var ids []int +var codeCustomField string func init() { r = rand.New(rand.NewSource(time.Now().UnixNano())) @@ -49,7 +50,6 @@ func TestGetRequest(t *testing.T) { _, status, _ := c.GetRequest("/fake-method") if status != http.StatusNotFound { - t.Fail() } } @@ -58,7 +58,6 @@ func TestPostRequest(t *testing.T) { _, status, _ := c.PostRequest("/fake-method", url.Values{}) if status != http.StatusNotFound { - t.Fail() } } @@ -118,7 +117,6 @@ func TestClient_ApiCredentialsCredentials(t *testing.T) { data, status, err := c.APICredentials() if err.RuntimeErr != nil { - t.Fail() } if status >= http.StatusBadRequest { @@ -1534,7 +1532,7 @@ func TestClient_PackChange(t *testing.T) { Patronymic: "Аристархович", ExternalID: RandomString(8), Email: fmt.Sprintf("%s@example.com", RandomString(8)), - Items: []OrderItem{{Offer: Offer{ID: 1609}, Quantity: 5}}, + Items: []OrderItem{{Offer: Offer{ID: 25472}, Quantity: 5}}, }) if err.RuntimeErr != nil { t.Errorf("%v", err.Error()) @@ -1740,28 +1738,22 @@ func TestClient_IntegrationModuleFail(t *testing.T) { Code: code, }) if err.RuntimeErr == nil { - t.Fail() } if status < http.StatusBadRequest { - t.Fail() } if m.Success != false { - t.Fail() } g, status, err := c.IntegrationModule(RandomString(12)) if err.RuntimeErr == nil { - t.Fail() } if status < http.StatusBadRequest { - t.Fail() } if g.Success != false { - t.Fail() } } @@ -1863,19 +1855,16 @@ func TestClient_CostCreate(t *testing.T) { CostItem: "seo", }) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } id = data.ID @@ -1892,19 +1881,16 @@ func TestClient_Costs(t *testing.T) { Page: 1, }) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } @@ -1913,19 +1899,16 @@ func TestClient_Cost(t *testing.T) { data, status, err := c.Cost(id) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } @@ -1940,19 +1923,16 @@ func TestClient_CostEdit(t *testing.T) { Order: nil, }) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } @@ -1961,19 +1941,16 @@ func TestClient_CostDelete(t *testing.T) { data, status, err := c.CostDelete(id) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } @@ -1996,23 +1973,20 @@ func TestClient_CostsUpload(t *testing.T) { Summ: 125, CostItem: "seo", Order: nil, - Sites: []string{"catalog-test"}, + Sites: []string{"retailcrm-ru"}, }, }) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } ids = data.UploadedCosts @@ -2022,19 +1996,16 @@ func TestClient_CostsDelete(t *testing.T) { c := client() data, status, err := c.CostsDelete(ids) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } @@ -2043,19 +2014,16 @@ func TestClient_CustomFields(t *testing.T) { data, status, err := c.CustomFields(CustomFieldsRequest{}) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } func TestClient_CustomDictionaries(t *testing.T) { @@ -2069,19 +2037,16 @@ func TestClient_CustomDictionaries(t *testing.T) { Page: 1, }) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } @@ -2090,19 +2055,16 @@ func TestClient_CustomDictionary(t *testing.T) { data, status, err := c.CustomDictionary("test2") - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } @@ -2111,7 +2073,7 @@ func TestClient_CustomDictionariesCreate(t *testing.T) { data, status, err := c.CustomDictionariesCreate(CustomDictionary{ Name: "test2", - Code: "test2", + Code: RandomString(8), Elements: []Element{ { Name: "test", @@ -2120,19 +2082,16 @@ func TestClient_CustomDictionariesCreate(t *testing.T) { }, }) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } @@ -2150,93 +2109,80 @@ func TestClient_CustomDictionaryEdit(t *testing.T) { }, }) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } func TestClient_CustomFieldsCreate(t *testing.T) { c := client() + codeCustomField = RandomString(8) - data, status, err := c.CustomFieldsCreate(CustomFieldsEditRequest{ - CustomField: CustomFields{ - Name: "test4", - Code: "test4", - Type: "text", - Entity: "order", - DisplayArea: "customer", - }, + data, status, err := c.CustomFieldsCreate(CustomFields{ + Name: codeCustomField, + Code: codeCustomField, + Type: "text", + Entity: "order", + DisplayArea: "customer", }) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } func TestClient_CustomField(t *testing.T) { c := client() - data, status, err := c.CustomField("customer", "testtest") + data, status, err := c.CustomField("order", codeCustomField) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } func TestClient_CustomFieldEdit(t *testing.T) { c := client() - data, status, err := c.CustomFieldEdit("customer", CustomFieldsEditRequest{ - CustomField: CustomFields{ - Name: "testtesttest", - }, + data, status, err := c.CustomFieldEdit(CustomFields{ + Code: codeCustomField, + Entity: "order", + DisplayArea: "delivery", }) - if err.ErrorMsg != "" { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if err.RuntimeErr != nil { + t.Errorf("%v", err.Error()) } - if status != http.StatusOK { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + if !statuses[status] { + t.Errorf("%v", err.ApiError()) } if data.Success != true { - t.Errorf("%v", err.ErrorMsg) - t.Fail() + t.Errorf("%v", err.ApiError()) } } diff --git a/v5/request.go b/v5/request.go index 9c024a1..3bf4fb5 100644 --- a/v5/request.go +++ b/v5/request.go @@ -88,7 +88,7 @@ type TasksRequest struct { // NotesRequest type type NotesRequest struct { - Filter TasksFilter `url:"filter,omitempty"` + Filter NotesFilter `url:"filter,omitempty"` Limit int `url:"limit,omitempty"` Page int `url:"page,omitempty"` } @@ -164,8 +164,3 @@ type CustomDictionariesRequest struct { Page int `url:"page,omitempty"` } -// CustomFieldsEditRequest type -type CustomFieldsEditRequest struct { - CustomField CustomFields `url:"customField,omitempty"` - Entity string `url:"entity,omitempty"` -}