From e7c3cc481548ca34f1c6baa6d416a0f7ec8398e9 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Wed, 21 Mar 2018 00:54:37 +0300 Subject: [PATCH] remove pointers from response, update license, minor refactoring --- LICENSE | 21 + README.md | 22 +- v5/client.go | 1835 +++++++++++++++++++++++---------------------- v5/client_test.go | 19 +- v5/response.go | 4 +- 5 files changed, 964 insertions(+), 937 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..dce51a1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015-2018 RetailDriver LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md index d3f9522..3c1d5a6 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,13 @@ [![Build Status](https://img.shields.io/travis/retailcrm/api-client-go/master.svg?style=flat-square)](https://travis-ci.org/retailcrm/api-client-go) +[![GitHub release](https://img.shields.io/github/release/retailcrm/api-client-go.svg?style=flat-square)](https://github.com/retailcrm/api-client-go/releases) +[![GoLang version](https://img.shields.io/badge/GoLang-1.8%2C%201.9%2C%201.10-blue.svg?style=flat-square)](https://golang.org/dl/) + # retailCRM API Go client -Go client for [retailCRM API](http://www.retailcrm.pro/docs/Developers/ApiVersion5). +This is golang retailCRM API client. -## Installation +## Install ```bash go get -x github.com/retailcrm/api-client-go @@ -76,15 +79,8 @@ func main() { } ``` -## Testing +## Documentation -```bash -export RETAILCRM_URL="https://demo.retailcrm.pro" -export RETAILCRM_KEY="09jIJ09j0JKhgyfvyuUIKhiugF" -export RETAILCRM_USER="1" - -cd $GOPATH/src/github.com/retailcrm/api-client-go - -go test -v ./... - -``` +* [English](http://www.retailcrm.pro/docs/Developers/Index) +* [Russian](http://www.retailcrm.ru/docs/Developers/Index) +* [GoDoc](https://godoc.org/github.com/retailcrm/api-client-go) diff --git a/v5/client.go b/v5/client.go index a06025d..5bc5504 100644 --- a/v5/client.go +++ b/v5/client.go @@ -13,11 +13,6 @@ import ( "github.com/google/go-querystring/query" ) -const ( - versionedPrefix = "/api/v5" - unversionedPrefix = "/api" -) - // New initalize client func New(url string, key string) *Client { return &Client{ @@ -28,11 +23,20 @@ func New(url string, key string) *Client { } // GetRequest implements GET Request -func (c *Client) GetRequest(urlWithParameters string) ([]byte, int, ErrorResponse) { +func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte, int, ErrorResponse) { var res []byte var bug ErrorResponse + var prefix = "/api/v5" - req, err := http.NewRequest("GET", fmt.Sprintf("%s%s", c.URL, urlWithParameters), nil) + if len(versioned) > 0 { + s := versioned[0] + + if s == false { + prefix = "/api" + } + } + + req, err := http.NewRequest("GET", fmt.Sprintf("%s%s%s", c.URL, prefix, urlWithParameters), nil) if err != nil { bug.ErrorMsg = err.Error() return res, 0, bug @@ -68,10 +72,11 @@ func (c *Client) GetRequest(urlWithParameters string) ([]byte, int, ErrorRespons func (c *Client) PostRequest(url string, postParams url.Values) ([]byte, int, ErrorResponse) { var res []byte var bug ErrorResponse + var prefix = "/api/v5" req, err := http.NewRequest( "POST", - fmt.Sprintf("%s%s", c.URL, url), + fmt.Sprintf("%s%s%s", c.URL, prefix, url), strings.NewReader(postParams.Encode()), ) if err != nil { @@ -159,17 +164,17 @@ func fillSite(p *url.Values, site []string) { // for _, value := range data.versions { // fmt.Printf("%v\n", value) // } -func (c *Client) APIVersions() (*VersionResponse, int, ErrorResponse) { +func (c *Client) APIVersions() (VersionResponse, int, ErrorResponse) { var resp VersionResponse - data, status, err := c.GetRequest(fmt.Sprintf("%s/api-versions", unversionedPrefix)) + data, status, err := c.GetRequest("/api-versions", false) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } // APICredentials get all available API methods for exact account @@ -191,85 +196,59 @@ func (c *Client) APIVersions() (*VersionResponse, int, ErrorResponse) { // for _, value := range data.credentials { // fmt.Printf("%v\n", value) // } -func (c *Client) APICredentials() (*CredentialResponse, int, ErrorResponse) { +func (c *Client) APICredentials() (CredentialResponse, int, ErrorResponse) { var resp CredentialResponse - data, status, err := c.GetRequest(fmt.Sprintf("%s/credentials", unversionedPrefix)) + data, status, err := c.GetRequest("/credentials", false) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err -} - -// StaticticUpdate update statistic -func (c *Client) StaticticUpdate() (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/statistic/update", versionedPrefix)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// Segments get segments -func (c *Client) Segments(parameters SegmentsRequest) (*SegmentsResponse, int, ErrorResponse) { - var resp SegmentsResponse - - params, _ := query.Values(parameters) - - data, status, err := c.GetRequest(fmt.Sprintf("%s/segments?%s", versionedPrefix, params.Encode())) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// Customer get method -func (c *Client) Customer(id, by, site string) (*CustomerResponse, int, ErrorResponse) { - var resp CustomerResponse - var context = checkBy(by) - - fw := CustomerRequest{context, site} - params, _ := query.Values(fw) - - data, status, err := c.GetRequest(fmt.Sprintf("%s/customers/%s?%s", versionedPrefix, id, params.Encode())) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err + return resp, status, err } // Customers list method -func (c *Client) Customers(parameters CustomersRequest) (*CustomersResponse, int, ErrorResponse) { +func (c *Client) Customers(parameters CustomersRequest) (CustomersResponse, int, ErrorResponse) { var resp CustomersResponse params, _ := query.Values(parameters) - data, status, err := c.GetRequest(fmt.Sprintf("%s/customers?%s", versionedPrefix, params.Encode())) + data, status, err := c.GetRequest(fmt.Sprintf("/customers?%s", params.Encode())) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err +} + +// CustomersCombine method +func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse + + combineJSONIn, _ := json.Marshal(&customers) + combineJSONOut, _ := json.Marshal(&resultCustomer) + + p := url.Values{ + "customers": {string(combineJSONIn[:])}, + "resultCustomer": {string(combineJSONOut[:])}, + } + + data, status, err := c.PostRequest("/customers/combine", p) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err } // CustomerCreate method -func (c *Client) CustomerCreate(customer Customer, site ...string) (*CustomerChangeResponse, int, ErrorResponse) { +func (c *Client) CustomerCreate(customer Customer, site ...string) (CustomerChangeResponse, int, ErrorResponse) { var resp CustomerChangeResponse customerJSON, _ := json.Marshal(&customer) @@ -280,18 +259,150 @@ func (c *Client) CustomerCreate(customer Customer, site ...string) (*CustomerCha fillSite(&p, site) - data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/create", versionedPrefix), p) + data, status, err := c.PostRequest("/customers/create", p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err +} + +// CustomersFixExternalIds method +func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse + + customersJSON, _ := json.Marshal(&customers) + + p := url.Values{ + "customers": {string(customersJSON[:])}, + } + + data, status, err := c.PostRequest("/customers/fix-external-ids", p) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// CustomersHistory method +func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (CustomersHistoryResponse, int, ErrorResponse) { + var resp CustomersHistoryResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("/customers/history?%s", params.Encode())) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// CustomerNotes list method +func (c *Client) CustomerNotes(parameters NotesRequest) (NotesResponse, int, ErrorResponse) { + var resp NotesResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("/customers/notes?%s", params.Encode())) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// CustomerNoteCreate method +func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, int, ErrorResponse) { + var resp CreateResponse + + noteJSON, _ := json.Marshal(¬e) + + p := url.Values{ + "note": {string(noteJSON[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest("/customers/notes/create", p) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// CustomerNoteDelete method +func (c *Client) CustomerNoteDelete(id int) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse + + p := url.Values{ + "id": {string(id)}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("/customers/notes/%d/delete", id), p) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// CustomersUpload method +func (c *Client) CustomersUpload(customers []Customer, site ...string) (CustomersUploadResponse, int, ErrorResponse) { + var resp CustomersUploadResponse + + uploadJSON, _ := json.Marshal(&customers) + + p := url.Values{ + "customers": {string(uploadJSON[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest("/customers/upload", p) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// Customer get method +func (c *Client) Customer(id, by, site string) (CustomerResponse, int, ErrorResponse) { + var resp CustomerResponse + var context = checkBy(by) + + fw := CustomerRequest{context, site} + params, _ := query.Values(fw) + + data, status, err := c.GetRequest(fmt.Sprintf("/customers/%s?%s", id, params.Encode())) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err } // CustomerEdit method -func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (*CustomerChangeResponse, int, ErrorResponse) { +func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (CustomerChangeResponse, int, ErrorResponse) { var resp CustomerChangeResponse var uid = strconv.Itoa(customer.ID) var context = checkBy(by) @@ -309,132 +420,181 @@ func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (*Cu fillSite(&p, site) - data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/%s/edit", versionedPrefix, uid), p) + data, status, err := c.PostRequest(fmt.Sprintf("/customers/%s/edit", uid), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } -// CustomersUpload method -func (c *Client) CustomersUpload(customers []Customer, site ...string) (*CustomersUploadResponse, int, ErrorResponse) { - var resp CustomersUploadResponse +// DeliveryTracking method +func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode string) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse - uploadJSON, _ := json.Marshal(&customers) + updateJSON, _ := json.Marshal(¶meters) p := url.Values{ - "customers": {string(uploadJSON[:])}, + "statusUpdate": {string(updateJSON[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("/delivery/generic/%s/tracking", subcode), p) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// DeliveryShipments method +func (c *Client) DeliveryShipments(parameters DeliveryShipmentsRequest) (DeliveryShipmentsResponse, int, ErrorResponse) { + var resp DeliveryShipmentsResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("/delivery/shipments?%s", params.Encode())) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// DeliveryShipmentCreate method +func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType string, site ...string) (DeliveryShipmentUpdateResponse, int, ErrorResponse) { + var resp DeliveryShipmentUpdateResponse + updateJSON, _ := json.Marshal(&shipment) + + p := url.Values{ + "deliveryType": {string(deliveryType)}, + "deliveryShipment": {string(updateJSON[:])}, } fillSite(&p, site) - data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/upload", versionedPrefix), p) + data, status, err := c.PostRequest("/delivery/shipments/create", p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } -// CustomersCombine method -func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse +// DeliveryShipment method +func (c *Client) DeliveryShipment(id int) (DeliveryShipmentResponse, int, ErrorResponse) { + var resp DeliveryShipmentResponse - combineJSONIn, _ := json.Marshal(&customers) - combineJSONOut, _ := json.Marshal(&resultCustomer) + data, status, err := c.GetRequest(fmt.Sprintf("/delivery/shipments/%d", id)) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// DeliveryShipmentEdit method +func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) (DeliveryShipmentUpdateResponse, int, ErrorResponse) { + var resp DeliveryShipmentUpdateResponse + updateJSON, _ := json.Marshal(&shipment) p := url.Values{ - "customers": {string(combineJSONIn[:])}, - "resultCustomer": {string(combineJSONOut[:])}, + "deliveryShipment": {string(updateJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/combine", versionedPrefix), p) + fillSite(&p, site) + + data, status, err := c.PostRequest(fmt.Sprintf("/delivery/shipments/%s/edit", strconv.Itoa(shipment.ID)), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } -// CustomersFixExternalIds method -func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse +// IntegrationModule method +func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int, ErrorResponse) { + var resp IntegrationModuleResponse - customersJSON, _ := json.Marshal(&customers) - - p := url.Values{ - "customers": {string(customersJSON[:])}, - } - - data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/fix-external-ids", versionedPrefix), p) + data, status, err := c.GetRequest(fmt.Sprintf("/integration-modules/%s", code)) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } -// CustomersHistory method -func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (*CustomersHistoryResponse, int, ErrorResponse) { - var resp CustomersHistoryResponse +// IntegrationModuleEdit method +func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (IntegrationModuleEditResponse, int, ErrorResponse) { + var resp IntegrationModuleEditResponse + updateJSON, _ := json.Marshal(&integrationModule) - params, _ := query.Values(parameters) + p := url.Values{"integrationModule": {string(updateJSON[:])}} - data, status, err := c.GetRequest(fmt.Sprintf("%s/customers/history?%s", versionedPrefix, params.Encode())) + data, status, err := c.PostRequest(fmt.Sprintf("/integration-modules/%s/edit", integrationModule.Code), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err -} - -// Order get method -func (c *Client) Order(id, by, site string) (*OrderResponse, int, ErrorResponse) { - var resp OrderResponse - var context = checkBy(by) - - fw := OrderRequest{context, site} - params, _ := query.Values(fw) - - data, status, err := c.GetRequest(fmt.Sprintf("%s/orders/%s?%s", versionedPrefix, id, params.Encode())) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err + return resp, status, err } // Orders list method -func (c *Client) Orders(parameters OrdersRequest) (*OrdersResponse, int, ErrorResponse) { +func (c *Client) Orders(parameters OrdersRequest) (OrdersResponse, int, ErrorResponse) { var resp OrdersResponse params, _ := query.Values(parameters) - data, status, err := c.GetRequest(fmt.Sprintf("%s/orders?%s", versionedPrefix, params.Encode())) + data, status, err := c.GetRequest(fmt.Sprintf("/orders?%s", params.Encode())) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err +} + +// OrdersCombine method +func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (OperationResponse, int, ErrorResponse) { + var resp OperationResponse + + combineJSONIn, _ := json.Marshal(&order) + combineJSONOut, _ := json.Marshal(&resultOrder) + + p := url.Values{ + "technique": {technique}, + "order": {string(combineJSONIn[:])}, + "resultOrder": {string(combineJSONOut[:])}, + } + + data, status, err := c.PostRequest("/orders/combine", p) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err } // OrderCreate method -func (c *Client) OrderCreate(order Order, site ...string) (*CreateResponse, int, ErrorResponse) { +func (c *Client) OrderCreate(order Order, site ...string) (CreateResponse, int, ErrorResponse) { var resp CreateResponse orderJSON, _ := json.Marshal(&order) @@ -444,18 +604,162 @@ func (c *Client) OrderCreate(order Order, site ...string) (*CreateResponse, int, fillSite(&p, site) - data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/create", versionedPrefix), p) + data, status, err := c.PostRequest("/orders/create", p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err +} + +// OrdersFixExternalIds method +func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse + + ordersJSON, _ := json.Marshal(&orders) + + p := url.Values{ + "orders": {string(ordersJSON[:])}, + } + + data, status, err := c.PostRequest("/orders/fix-external-ids", p) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// OrdersHistory method +func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (CustomersHistoryResponse, int, ErrorResponse) { + var resp CustomersHistoryResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("/orders/history?%s", params.Encode())) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// OrderPaymentCreate method +func (c *Client) OrderPaymentCreate(payment Payment, site ...string) (CreateResponse, int, ErrorResponse) { + var resp CreateResponse + + paymentJSON, _ := json.Marshal(&payment) + + p := url.Values{ + "payment": {string(paymentJSON[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest("/orders/payments/create", p) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// OrderPaymentDelete method +func (c *Client) OrderPaymentDelete(id int) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse + + p := url.Values{ + "id": {string(id)}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("/orders/payments/%d/delete", id), p) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// OrderPaymentEdit method +func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse + var uid = strconv.Itoa(payment.ID) + var context = checkBy(by) + + if context == "externalId" { + uid = payment.ExternalID + } + + paymentJSON, _ := json.Marshal(&payment) + + p := url.Values{ + "payment": {string(paymentJSON[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest(fmt.Sprintf("/orders/payments/%s/edit", uid), p) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// OrdersUpload method +func (c *Client) OrdersUpload(orders []Order, site ...string) (OrdersUploadResponse, int, ErrorResponse) { + var resp OrdersUploadResponse + + uploadJSON, _ := json.Marshal(&orders) + + p := url.Values{ + "orders": {string(uploadJSON[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest("/orders/upload", p) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// Order get method +func (c *Client) Order(id, by, site string) (OrderResponse, int, ErrorResponse) { + var resp OrderResponse + var context = checkBy(by) + + fw := OrderRequest{context, site} + params, _ := query.Values(fw) + + data, status, err := c.GetRequest(fmt.Sprintf("/orders/%s?%s", id, params.Encode())) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err } // OrderEdit method -func (c *Client) OrderEdit(order Order, by string, site ...string) (*CreateResponse, int, ErrorResponse) { +func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateResponse, int, ErrorResponse) { var resp CreateResponse var uid = strconv.Itoa(order.ID) var context = checkBy(by) @@ -473,129 +777,34 @@ func (c *Client) OrderEdit(order Order, by string, site ...string) (*CreateRespo fillSite(&p, site) - data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/%s/edit", versionedPrefix, uid), p) + data, status, err := c.PostRequest(fmt.Sprintf("/orders/%s/edit", uid), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err -} - -// OrdersUpload method -func (c *Client) OrdersUpload(orders []Order, site ...string) (*OrdersUploadResponse, int, ErrorResponse) { - var resp OrdersUploadResponse - - uploadJSON, _ := json.Marshal(&orders) - - p := url.Values{ - "orders": {string(uploadJSON[:])}, - } - - fillSite(&p, site) - - data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/upload", versionedPrefix), p) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// OrdersCombine method -func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (*OperationResponse, int, ErrorResponse) { - var resp OperationResponse - - combineJSONIn, _ := json.Marshal(&order) - combineJSONOut, _ := json.Marshal(&resultOrder) - - p := url.Values{ - "technique": {technique}, - "order": {string(combineJSONIn[:])}, - "resultOrder": {string(combineJSONOut[:])}, - } - - data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/combine", versionedPrefix), p) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// OrdersFixExternalIds method -func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse - - ordersJSON, _ := json.Marshal(&orders) - - p := url.Values{ - "orders": {string(ordersJSON[:])}, - } - - data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/fix-external-ids", versionedPrefix), p) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// OrdersHistory method -func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (*CustomersHistoryResponse, int, ErrorResponse) { - var resp CustomersHistoryResponse - - params, _ := query.Values(parameters) - - data, status, err := c.GetRequest(fmt.Sprintf("%s/orders/history?%s", versionedPrefix, params.Encode())) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// Pack get method -func (c *Client) Pack(id int) (*PackResponse, int, ErrorResponse) { - var resp PackResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/orders/packs/%d", versionedPrefix, id)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err + return resp, status, err } // Packs list method -func (c *Client) Packs(parameters PacksRequest) (*PacksResponse, int, ErrorResponse) { +func (c *Client) Packs(parameters PacksRequest) (PacksResponse, int, ErrorResponse) { var resp PacksResponse params, _ := query.Values(parameters) - data, status, err := c.GetRequest(fmt.Sprintf("%s/orders/packs?%s", versionedPrefix, params.Encode())) + data, status, err := c.GetRequest(fmt.Sprintf("/orders/packs?%s", params.Encode())) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } // PackCreate method -func (c *Client) PackCreate(pack Pack) (*CreateResponse, int, ErrorResponse) { +func (c *Client) PackCreate(pack Pack) (CreateResponse, int, ErrorResponse) { var resp CreateResponse packJSON, _ := json.Marshal(&pack) @@ -603,567 +812,111 @@ func (c *Client) PackCreate(pack Pack) (*CreateResponse, int, ErrorResponse) { "pack": {string(packJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/packs/create", versionedPrefix), p) + data, status, err := c.PostRequest("/orders/packs/create", p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err -} - -// PackEdit method -func (c *Client) PackEdit(pack Pack) (*CreateResponse, int, ErrorResponse) { - var resp CreateResponse - - packJSON, _ := json.Marshal(&pack) - - p := url.Values{ - "pack": {string(packJSON[:])}, - } - - data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/packs/%d/edit", versionedPrefix, pack.ID), p) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// PackDelete method -func (c *Client) PackDelete(id int) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse - - data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/packs/%d/delete", versionedPrefix, id), url.Values{}) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err + return resp, status, err } // PacksHistory method -func (c *Client) PacksHistory(parameters PacksHistoryRequest) (*PacksHistoryResponse, int, ErrorResponse) { +func (c *Client) PacksHistory(parameters PacksHistoryRequest) (PacksHistoryResponse, int, ErrorResponse) { var resp PacksHistoryResponse params, _ := query.Values(parameters) - data, status, err := c.GetRequest(fmt.Sprintf("%s/orders/packs/history?%s", versionedPrefix, params.Encode())) + data, status, err := c.GetRequest(fmt.Sprintf("/orders/packs/history?%s", params.Encode())) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } -// User get method -func (c *Client) User(id int) (*UserResponse, int, ErrorResponse) { - var resp UserResponse +// Pack get method +func (c *Client) Pack(id int) (PackResponse, int, ErrorResponse) { + var resp PackResponse - data, status, err := c.GetRequest(fmt.Sprintf("%s/users/%d", versionedPrefix, id)) + data, status, err := c.GetRequest(fmt.Sprintf("/orders/packs/%d", id)) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } -// Users list method -func (c *Client) Users(parameters UsersRequest) (*UsersResponse, int, ErrorResponse) { - var resp UsersResponse +// PackDelete method +func (c *Client) PackDelete(id int) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse - params, _ := query.Values(parameters) - - data, status, err := c.GetRequest(fmt.Sprintf("%s/users?%s", versionedPrefix, params.Encode())) + data, status, err := c.PostRequest(fmt.Sprintf("/orders/packs/%d/delete", id), url.Values{}) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } -// UserGroups list method -func (c *Client) UserGroups(parameters UserGroupsRequest) (*UserGroupsResponse, int, ErrorResponse) { - var resp UserGroupsResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/user-groups", versionedPrefix)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// UserStatus update method -func (c *Client) UserStatus(id int, status string) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse - - p := url.Values{ - "status": {string(status)}, - } - - data, st, err := c.PostRequest(fmt.Sprintf("%s/users/%d/status", versionedPrefix, id), p) - if err.ErrorMsg != "" { - return &resp, st, err - } - - json.Unmarshal(data, &resp) - - return &resp, st, err -} - -// Task get method -func (c *Client) Task(id int) (*TaskResponse, int, ErrorResponse) { - var resp TaskResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/tasks/%d", versionedPrefix, id)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// Tasks list method -func (c *Client) Tasks(parameters TasksRequest) (*TasksResponse, int, ErrorResponse) { - var resp TasksResponse - - params, _ := query.Values(parameters) - - data, status, err := c.GetRequest(fmt.Sprintf("%s/tasks?%s", versionedPrefix, params.Encode())) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// TaskCreate method -func (c *Client) TaskCreate(task Task, site ...string) (*CreateResponse, int, ErrorResponse) { - var resp CreateResponse - taskJSON, _ := json.Marshal(&task) - - p := url.Values{ - "task": {string(taskJSON[:])}, - } - - fillSite(&p, site) - - data, status, err := c.PostRequest(fmt.Sprintf("%s/tasks/create", versionedPrefix), p) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// TaskEdit method -func (c *Client) TaskEdit(task Task, site ...string) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse - var uid = strconv.Itoa(task.ID) - - taskJSON, _ := json.Marshal(&task) - - p := url.Values{ - "task": {string(taskJSON[:])}, - } - - fillSite(&p, site) - - data, status, err := c.PostRequest(fmt.Sprintf("%s/tasks/%s/edit", versionedPrefix, uid), p) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// Notes list method -func (c *Client) Notes(parameters NotesRequest) (*NotesResponse, int, ErrorResponse) { - var resp NotesResponse - - params, _ := query.Values(parameters) - - data, status, err := c.GetRequest(fmt.Sprintf("%s/customers/notes?%s", versionedPrefix, params.Encode())) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// NoteCreate method -func (c *Client) NoteCreate(note Note, site ...string) (*CreateResponse, int, ErrorResponse) { +// PackEdit method +func (c *Client) PackEdit(pack Pack) (CreateResponse, int, ErrorResponse) { var resp CreateResponse - noteJSON, _ := json.Marshal(¬e) + packJSON, _ := json.Marshal(&pack) p := url.Values{ - "note": {string(noteJSON[:])}, + "pack": {string(packJSON[:])}, } - fillSite(&p, site) - - data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/notes/create", versionedPrefix), p) + data, status, err := c.PostRequest(fmt.Sprintf("/orders/packs/%d/edit", pack.ID), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err -} - -// NoteDelete method -func (c *Client) NoteDelete(id int) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse - - p := url.Values{ - "id": {string(id)}, - } - - data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/notes/%d/delete", versionedPrefix, id), p) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// PaymentCreate method -func (c *Client) PaymentCreate(payment Payment, site ...string) (*CreateResponse, int, ErrorResponse) { - var resp CreateResponse - - paymentJSON, _ := json.Marshal(&payment) - - p := url.Values{ - "payment": {string(paymentJSON[:])}, - } - - fillSite(&p, site) - - data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/payments/create", versionedPrefix), p) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// PaymentDelete method -func (c *Client) PaymentDelete(id int) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse - - p := url.Values{ - "id": {string(id)}, - } - - data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/payments/%d/delete", versionedPrefix, id), p) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// PaymentEdit method -func (c *Client) PaymentEdit(payment Payment, by string, site ...string) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse - var uid = strconv.Itoa(payment.ID) - var context = checkBy(by) - - if context == "externalId" { - uid = payment.ExternalID - } - - paymentJSON, _ := json.Marshal(&payment) - - p := url.Values{ - "payment": {string(paymentJSON[:])}, - } - - fillSite(&p, site) - - data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/payments/%s/edit", versionedPrefix, uid), p) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err + return resp, status, err } // Countries method -func (c *Client) Countries() (*CountriesResponse, int, ErrorResponse) { +func (c *Client) Countries() (CountriesResponse, int, ErrorResponse) { var resp CountriesResponse - data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/countries", versionedPrefix)) + data, status, err := c.GetRequest("/reference/countries") if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } // CostGroups method -func (c *Client) CostGroups() (*CostGroupsResponse, int, ErrorResponse) { +func (c *Client) CostGroups() (CostGroupsResponse, int, ErrorResponse) { var resp CostGroupsResponse - data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/cost-groups", versionedPrefix)) + data, status, err := c.GetRequest("/reference/cost-groups") if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err -} - -// CostItems method -func (c *Client) CostItems() (*CostItemsResponse, int, ErrorResponse) { - var resp CostItemsResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/cost-items", versionedPrefix)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// Couriers method -func (c *Client) Couriers() (*CouriersResponse, int, ErrorResponse) { - var resp CouriersResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/couriers", versionedPrefix)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// DeliveryServices method -func (c *Client) DeliveryServices() (*DeliveryServiceResponse, int, ErrorResponse) { - var resp DeliveryServiceResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/delivery-services", versionedPrefix)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// DeliveryTypes method -func (c *Client) DeliveryTypes() (*DeliveryTypesResponse, int, ErrorResponse) { - var resp DeliveryTypesResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/delivery-types", versionedPrefix)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// LegalEntities method -func (c *Client) LegalEntities() (*LegalEntitiesResponse, int, ErrorResponse) { - var resp LegalEntitiesResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/legal-entities", versionedPrefix)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// OrderMethods method -func (c *Client) OrderMethods() (*OrderMethodsResponse, int, ErrorResponse) { - var resp OrderMethodsResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/order-methods", versionedPrefix)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// OrderTypes method -func (c *Client) OrderTypes() (*OrderTypesResponse, int, ErrorResponse) { - var resp OrderTypesResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/order-types", versionedPrefix)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// PaymentStatuses method -func (c *Client) PaymentStatuses() (*PaymentStatusesResponse, int, ErrorResponse) { - var resp PaymentStatusesResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/payment-statuses", versionedPrefix)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// PaymentTypes method -func (c *Client) PaymentTypes() (*PaymentTypesResponse, int, ErrorResponse) { - var resp PaymentTypesResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/payment-types", versionedPrefix)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// PriceTypes method -func (c *Client) PriceTypes() (*PriceTypesResponse, int, ErrorResponse) { - var resp PriceTypesResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/price-types", versionedPrefix)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// ProductStatuses method -func (c *Client) ProductStatuses() (*ProductStatusesResponse, int, ErrorResponse) { - var resp ProductStatusesResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/product-statuses", versionedPrefix)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// Statuses method -func (c *Client) Statuses() (*StatusesResponse, int, ErrorResponse) { - var resp StatusesResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/statuses", versionedPrefix)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// StatusGroups method -func (c *Client) StatusGroups() (*StatusGroupsResponse, int, ErrorResponse) { - var resp StatusGroupsResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/status-groups", versionedPrefix)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// Sites method -func (c *Client) Sites() (*SitesResponse, int, ErrorResponse) { - var resp SitesResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/sites", versionedPrefix)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// Stores method -func (c *Client) Stores() (*StoresResponse, int, ErrorResponse) { - var resp StoresResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/stores", versionedPrefix)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err + return resp, status, err } // CostGroupEdit method -func (c *Client) CostGroupEdit(costGroup CostGroup) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse +func (c *Client) CostGroupEdit(costGroup CostGroup) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse objJSON, _ := json.Marshal(&costGroup) @@ -1171,19 +924,33 @@ func (c *Client) CostGroupEdit(costGroup CostGroup) (*SucessfulResponse, int, Er "costGroup": {string(objJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/cost-groups/%s/edit", versionedPrefix, costGroup.Code), p) + data, status, err := c.PostRequest(fmt.Sprintf("/reference/cost-groups/%s/edit", costGroup.Code), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err +} + +// CostItems method +func (c *Client) CostItems() (CostItemsResponse, int, ErrorResponse) { + var resp CostItemsResponse + + data, status, err := c.GetRequest("/reference/cost-items") + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err } // CostItemEdit method -func (c *Client) CostItemEdit(costItem CostItem) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse +func (c *Client) CostItemEdit(costItem CostItem) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse objJSON, _ := json.Marshal(&costItem) @@ -1191,18 +958,32 @@ func (c *Client) CostItemEdit(costItem CostItem) (*SucessfulResponse, int, Error "costItem": {string(objJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/cost-items/%s/edit", versionedPrefix, costItem.Code), p) + data, status, err := c.PostRequest(fmt.Sprintf("/reference/cost-items/%s/edit", costItem.Code), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err +} + +// Couriers method +func (c *Client) Couriers() (CouriersResponse, int, ErrorResponse) { + var resp CouriersResponse + + data, status, err := c.GetRequest("/reference/couriers") + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err } // CourierCreate method -func (c *Client) CourierCreate(courier Courier) (*CreateResponse, int, ErrorResponse) { +func (c *Client) CourierCreate(courier Courier) (CreateResponse, int, ErrorResponse) { var resp CreateResponse objJSON, _ := json.Marshal(&courier) @@ -1211,19 +992,19 @@ func (c *Client) CourierCreate(courier Courier) (*CreateResponse, int, ErrorResp "courier": {string(objJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/couriers/create", versionedPrefix), p) + data, status, err := c.PostRequest("/reference/couriers/create", p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } // CourierEdit method -func (c *Client) CourierEdit(courier Courier) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse +func (c *Client) CourierEdit(courier Courier) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse objJSON, _ := json.Marshal(&courier) @@ -1231,19 +1012,33 @@ func (c *Client) CourierEdit(courier Courier) (*SucessfulResponse, int, ErrorRes "courier": {string(objJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/couriers/%d/edit", versionedPrefix, courier.ID), p) + data, status, err := c.PostRequest(fmt.Sprintf("/reference/couriers/%d/edit", courier.ID), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err +} + +// DeliveryServices method +func (c *Client) DeliveryServices() (DeliveryServiceResponse, int, ErrorResponse) { + var resp DeliveryServiceResponse + + data, status, err := c.GetRequest("/reference/delivery-services") + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err } // DeliveryServiceEdit method -func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse +func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse objJSON, _ := json.Marshal(&deliveryService) @@ -1251,19 +1046,33 @@ func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (*Sucessfu "deliveryService": {string(objJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/delivery-services/%s/edit", versionedPrefix, deliveryService.Code), p) + data, status, err := c.PostRequest(fmt.Sprintf("/reference/delivery-services/%s/edit", deliveryService.Code), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err +} + +// DeliveryTypes method +func (c *Client) DeliveryTypes() (DeliveryTypesResponse, int, ErrorResponse) { + var resp DeliveryTypesResponse + + data, status, err := c.GetRequest("/reference/delivery-types") + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err } // DeliveryTypeEdit method -func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse +func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse objJSON, _ := json.Marshal(&deliveryType) @@ -1271,19 +1080,33 @@ func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (*SucessfulResponse "deliveryType": {string(objJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/delivery-types/%s/edit", versionedPrefix, deliveryType.Code), p) + data, status, err := c.PostRequest(fmt.Sprintf("/reference/delivery-types/%s/edit", deliveryType.Code), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err +} + +// LegalEntities method +func (c *Client) LegalEntities() (LegalEntitiesResponse, int, ErrorResponse) { + var resp LegalEntitiesResponse + + data, status, err := c.GetRequest("/reference/legal-entities") + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err } // LegalEntityEdit method -func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse +func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse objJSON, _ := json.Marshal(&legalEntity) @@ -1291,19 +1114,33 @@ func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (*SucessfulResponse, i "legalEntity": {string(objJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/legal-entities/%s/edit", versionedPrefix, legalEntity.Code), p) + data, status, err := c.PostRequest(fmt.Sprintf("/reference/legal-entities/%s/edit", legalEntity.Code), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err +} + +// OrderMethods method +func (c *Client) OrderMethods() (OrderMethodsResponse, int, ErrorResponse) { + var resp OrderMethodsResponse + + data, status, err := c.GetRequest("/reference/order-methods") + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err } // OrderMethodEdit method -func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse +func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse objJSON, _ := json.Marshal(&orderMethod) @@ -1311,19 +1148,33 @@ func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (*SucessfulResponse, i "orderMethod": {string(objJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/order-methods/%s/edit", versionedPrefix, orderMethod.Code), p) + data, status, err := c.PostRequest(fmt.Sprintf("/reference/order-methods/%s/edit", orderMethod.Code), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err +} + +// OrderTypes method +func (c *Client) OrderTypes() (OrderTypesResponse, int, ErrorResponse) { + var resp OrderTypesResponse + + data, status, err := c.GetRequest("/reference/order-types") + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err } // OrderTypeEdit method -func (c *Client) OrderTypeEdit(orderType OrderType) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse +func (c *Client) OrderTypeEdit(orderType OrderType) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse objJSON, _ := json.Marshal(&orderType) @@ -1331,19 +1182,33 @@ func (c *Client) OrderTypeEdit(orderType OrderType) (*SucessfulResponse, int, Er "orderType": {string(objJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/order-types/%s/edit", versionedPrefix, orderType.Code), p) + data, status, err := c.PostRequest(fmt.Sprintf("/reference/order-types/%s/edit", orderType.Code), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err +} + +// PaymentStatuses method +func (c *Client) PaymentStatuses() (PaymentStatusesResponse, int, ErrorResponse) { + var resp PaymentStatusesResponse + + data, status, err := c.GetRequest("/reference/payment-statuses") + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err } // PaymentStatusEdit method -func (c *Client) PaymentStatusEdit(paymentStatus PaymentStatus) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse +func (c *Client) PaymentStatusEdit(paymentStatus PaymentStatus) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse objJSON, _ := json.Marshal(&paymentStatus) @@ -1351,19 +1216,33 @@ func (c *Client) PaymentStatusEdit(paymentStatus PaymentStatus) (*SucessfulRespo "paymentStatus": {string(objJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/payment-statuses/%s/edit", versionedPrefix, paymentStatus.Code), p) + data, status, err := c.PostRequest(fmt.Sprintf("/reference/payment-statuses/%s/edit", paymentStatus.Code), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err +} + +// PaymentTypes method +func (c *Client) PaymentTypes() (PaymentTypesResponse, int, ErrorResponse) { + var resp PaymentTypesResponse + + data, status, err := c.GetRequest("/reference/payment-types") + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err } // PaymentTypeEdit method -func (c *Client) PaymentTypeEdit(paymentType PaymentType) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse +func (c *Client) PaymentTypeEdit(paymentType PaymentType) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse objJSON, _ := json.Marshal(&paymentType) @@ -1371,19 +1250,33 @@ func (c *Client) PaymentTypeEdit(paymentType PaymentType) (*SucessfulResponse, i "paymentType": {string(objJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/payment-types/%s/edit", versionedPrefix, paymentType.Code), p) + data, status, err := c.PostRequest(fmt.Sprintf("/reference/payment-types/%s/edit", paymentType.Code), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err +} + +// PriceTypes method +func (c *Client) PriceTypes() (PriceTypesResponse, int, ErrorResponse) { + var resp PriceTypesResponse + + data, status, err := c.GetRequest("/reference/price-types") + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err } // PriceTypeEdit method -func (c *Client) PriceTypeEdit(priceType PriceType) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse +func (c *Client) PriceTypeEdit(priceType PriceType) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse objJSON, _ := json.Marshal(&priceType) @@ -1391,19 +1284,33 @@ func (c *Client) PriceTypeEdit(priceType PriceType) (*SucessfulResponse, int, Er "priceType": {string(objJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/price-types/%s/edit", versionedPrefix, priceType.Code), p) + data, status, err := c.PostRequest(fmt.Sprintf("/reference/price-types/%s/edit", priceType.Code), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err +} + +// ProductStatuses method +func (c *Client) ProductStatuses() (ProductStatusesResponse, int, ErrorResponse) { + var resp ProductStatusesResponse + + data, status, err := c.GetRequest("/reference/product-statuses") + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err } // ProductStatusEdit method -func (c *Client) ProductStatusEdit(productStatus ProductStatus) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse +func (c *Client) ProductStatusEdit(productStatus ProductStatus) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse objJSON, _ := json.Marshal(&productStatus) @@ -1411,39 +1318,33 @@ func (c *Client) ProductStatusEdit(productStatus ProductStatus) (*SucessfulRespo "productStatus": {string(objJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/product-statuses/%s/edit", versionedPrefix, productStatus.Code), p) + data, status, err := c.PostRequest(fmt.Sprintf("/reference/product-statuses/%s/edit", productStatus.Code), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } -// StatusEdit method -func (c *Client) StatusEdit(st Status) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse +// Sites method +func (c *Client) Sites() (SitesResponse, int, ErrorResponse) { + var resp SitesResponse - objJSON, _ := json.Marshal(&st) - - p := url.Values{ - "status": {string(objJSON[:])}, - } - - data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/statuses/%s/edit", versionedPrefix, st.Code), p) + data, status, err := c.GetRequest("/reference/sites") if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } // SiteEdit method -func (c *Client) SiteEdit(site Site) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse +func (c *Client) SiteEdit(site Site) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse objJSON, _ := json.Marshal(&site) @@ -1451,19 +1352,81 @@ func (c *Client) SiteEdit(site Site) (*SucessfulResponse, int, ErrorResponse) { "site": {string(objJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/sites/%s/edit", versionedPrefix, site.Code), p) + data, status, err := c.PostRequest(fmt.Sprintf("/reference/sites/%s/edit", site.Code), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err +} + +// StatusGroups method +func (c *Client) StatusGroups() (StatusGroupsResponse, int, ErrorResponse) { + var resp StatusGroupsResponse + + data, status, err := c.GetRequest("/reference/status-groups") + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// Statuses method +func (c *Client) Statuses() (StatusesResponse, int, ErrorResponse) { + var resp StatusesResponse + + data, status, err := c.GetRequest("/reference/statuses") + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// StatusEdit method +func (c *Client) StatusEdit(st Status) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse + + objJSON, _ := json.Marshal(&st) + + p := url.Values{ + "status": {string(objJSON[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("/reference/statuses/%s/edit", st.Code), p) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// Stores method +func (c *Client) Stores() (StoresResponse, int, ErrorResponse) { + var resp StoresResponse + + data, status, err := c.GetRequest("/reference/stores") + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err } // StoreEdit method -func (c *Client) StoreEdit(store Store) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse +func (c *Client) StoreEdit(store Store) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse objJSON, _ := json.Marshal(&store) @@ -1471,34 +1434,50 @@ func (c *Client) StoreEdit(store Store) (*SucessfulResponse, int, ErrorResponse) "store": {string(objJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/stores/%s/edit", versionedPrefix, store.Code), p) + data, status, err := c.PostRequest(fmt.Sprintf("/reference/stores/%s/edit", store.Code), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err +} + +// Segments get segments +func (c *Client) Segments(parameters SegmentsRequest) (SegmentsResponse, int, ErrorResponse) { + var resp SegmentsResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("/segments?%s", params.Encode())) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err } // Inventories method -func (c *Client) Inventories(parameters InventoriesRequest) (*InventoriesResponse, int, ErrorResponse) { +func (c *Client) Inventories(parameters InventoriesRequest) (InventoriesResponse, int, ErrorResponse) { var resp InventoriesResponse params, _ := query.Values(parameters) - data, status, err := c.GetRequest(fmt.Sprintf("%s/store/inventories?%s", versionedPrefix, params.Encode())) + data, status, err := c.GetRequest(fmt.Sprintf("/store/inventories?%s", params.Encode())) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } // InventoriesUpload method -func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string) (*StoreUploadResponse, int, ErrorResponse) { +func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string) (StoreUploadResponse, int, ErrorResponse) { var resp StoreUploadResponse uploadJSON, _ := json.Marshal(&inventories) @@ -1509,18 +1488,18 @@ func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string fillSite(&p, site) - data, status, err := c.PostRequest(fmt.Sprintf("%s/store/inventories/upload", versionedPrefix), p) + data, status, err := c.PostRequest("/store/inventories/upload", p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } // PricesUpload method -func (c *Client) PricesUpload(prices []OfferPriceUpload) (*StoreUploadResponse, int, ErrorResponse) { +func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, int, ErrorResponse) { var resp StoreUploadResponse uploadJSON, _ := json.Marshal(&prices) @@ -1529,184 +1508,212 @@ func (c *Client) PricesUpload(prices []OfferPriceUpload) (*StoreUploadResponse, "prices": {string(uploadJSON[:])}, } - data, status, err := c.PostRequest(fmt.Sprintf("%s/store/prices/upload", versionedPrefix), p) + data, status, err := c.PostRequest("/store/prices/upload", p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } // ProductsGroup method -func (c *Client) ProductsGroup(parameters ProductsGroupsRequest) (*ProductsGroupsResponse, int, ErrorResponse) { +func (c *Client) ProductsGroup(parameters ProductsGroupsRequest) (ProductsGroupsResponse, int, ErrorResponse) { var resp ProductsGroupsResponse params, _ := query.Values(parameters) - data, status, err := c.GetRequest(fmt.Sprintf("%s/store/product-groups?%s", versionedPrefix, params.Encode())) + data, status, err := c.GetRequest(fmt.Sprintf("/store/product-groups?%s", params.Encode())) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } // Products method -func (c *Client) Products(parameters ProductsRequest) (*ProductsResponse, int, ErrorResponse) { +func (c *Client) Products(parameters ProductsRequest) (ProductsResponse, int, ErrorResponse) { var resp ProductsResponse params, _ := query.Values(parameters) - data, status, err := c.GetRequest(fmt.Sprintf("%s/store/products?%s", versionedPrefix, params.Encode())) + data, status, err := c.GetRequest(fmt.Sprintf("/store/products?%s", params.Encode())) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } // ProductsProperties method -func (c *Client) ProductsProperties(parameters ProductsPropertiesRequest) (*ProductsPropertiesResponse, int, ErrorResponse) { +func (c *Client) ProductsProperties(parameters ProductsPropertiesRequest) (ProductsPropertiesResponse, int, ErrorResponse) { var resp ProductsPropertiesResponse params, _ := query.Values(parameters) - data, status, err := c.GetRequest(fmt.Sprintf("%s/store/products/properties?%s", versionedPrefix, params.Encode())) + data, status, err := c.GetRequest(fmt.Sprintf("/store/products/properties?%s", params.Encode())) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } -// DeliveryTracking method -func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode string) (*SucessfulResponse, int, ErrorResponse) { - var resp SucessfulResponse - - updateJSON, _ := json.Marshal(¶meters) - - p := url.Values{ - "statusUpdate": {string(updateJSON[:])}, - } - - data, status, err := c.PostRequest(fmt.Sprintf("%s/delivery/generic/%s/tracking", versionedPrefix, subcode), p) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// DeliveryShipments method -func (c *Client) DeliveryShipments(parameters DeliveryShipmentsRequest) (*DeliveryShipmentsResponse, int, ErrorResponse) { - var resp DeliveryShipmentsResponse +// Tasks list method +func (c *Client) Tasks(parameters TasksRequest) (TasksResponse, int, ErrorResponse) { + var resp TasksResponse params, _ := query.Values(parameters) - data, status, err := c.GetRequest(fmt.Sprintf("%s/delivery/shipments?%s", versionedPrefix, params.Encode())) + data, status, err := c.GetRequest(fmt.Sprintf("/tasks?%s", params.Encode())) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } -// DeliveryShipment method -func (c *Client) DeliveryShipment(id int) (*DeliveryShipmentResponse, int, ErrorResponse) { - var resp DeliveryShipmentResponse - - data, status, err := c.GetRequest(fmt.Sprintf("%s/delivery/shipments/%d", versionedPrefix, id)) - if err.ErrorMsg != "" { - return &resp, status, err - } - - json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// DeliveryShipmentEdit method -func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) (*DeliveryShipmentUpdateResponse, int, ErrorResponse) { - var resp DeliveryShipmentUpdateResponse - updateJSON, _ := json.Marshal(&shipment) +// TaskCreate method +func (c *Client) TaskCreate(task Task, site ...string) (CreateResponse, int, ErrorResponse) { + var resp CreateResponse + taskJSON, _ := json.Marshal(&task) p := url.Values{ - "deliveryShipment": {string(updateJSON[:])}, + "task": {string(taskJSON[:])}, } fillSite(&p, site) - data, status, err := c.PostRequest(fmt.Sprintf("%s/delivery/shipments/%s/edit", versionedPrefix, strconv.Itoa(shipment.ID)), p) + data, status, err := c.PostRequest("/tasks/create", p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } -// DeliveryShipmentCreate method -func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType string, site ...string) (*DeliveryShipmentUpdateResponse, int, ErrorResponse) { - var resp DeliveryShipmentUpdateResponse - updateJSON, _ := json.Marshal(&shipment) +// Task get method +func (c *Client) Task(id int) (TaskResponse, int, ErrorResponse) { + var resp TaskResponse + + data, status, err := c.GetRequest(fmt.Sprintf("/tasks/%d", id)) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// TaskEdit method +func (c *Client) TaskEdit(task Task, site ...string) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse + var uid = strconv.Itoa(task.ID) + + taskJSON, _ := json.Marshal(&task) p := url.Values{ - "deliveryType": {string(deliveryType)}, - "deliveryShipment": {string(updateJSON[:])}, + "task": {string(taskJSON[:])}, } fillSite(&p, site) - data, status, err := c.PostRequest(fmt.Sprintf("%s/delivery/shipments/create", versionedPrefix), p) + data, status, err := c.PostRequest(fmt.Sprintf("/tasks/%s/edit", uid), p) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } -// IntegrationModule method -func (c *Client) IntegrationModule(code string) (*IntegrationModuleResponse, int, ErrorResponse) { - var resp IntegrationModuleResponse +// UserGroups list method +func (c *Client) UserGroups(parameters UserGroupsRequest) (UserGroupsResponse, int, ErrorResponse) { + var resp UserGroupsResponse - data, status, err := c.GetRequest(fmt.Sprintf("%s/integration-modules/%s", versionedPrefix, code)) + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("/user-groups?%s", params.Encode())) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err } -// IntegrationModuleEdit method -func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (*IntegrationModuleEditResponse, int, ErrorResponse) { - var resp IntegrationModuleEditResponse - updateJSON, _ := json.Marshal(&integrationModule) +// Users list method +func (c *Client) Users(parameters UsersRequest) (UsersResponse, int, ErrorResponse) { + var resp UsersResponse - p := url.Values{"integrationModule": {string(updateJSON[:])}} + params, _ := query.Values(parameters) - data, status, err := c.PostRequest(fmt.Sprintf("%s/integration-modules/%s/edit", versionedPrefix, integrationModule.Code), p) + data, status, err := c.GetRequest(fmt.Sprintf("/users?%s", params.Encode())) if err.ErrorMsg != "" { - return &resp, status, err + return resp, status, err } json.Unmarshal(data, &resp) - return &resp, status, err + return resp, status, err +} + +// User get method +func (c *Client) User(id int) (UserResponse, int, ErrorResponse) { + var resp UserResponse + + data, status, err := c.GetRequest(fmt.Sprintf("/users/%d", id)) + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err +} + +// UserStatus update method +func (c *Client) UserStatus(id int, status string) (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse + + p := url.Values{ + "status": {string(status)}, + } + + data, st, err := c.PostRequest(fmt.Sprintf("/users/%d/status", id), p) + if err.ErrorMsg != "" { + return resp, st, err + } + + json.Unmarshal(data, &resp) + + return resp, st, err +} + +// StaticticsUpdate update statistic +func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, ErrorResponse) { + var resp SuccessfulResponse + + data, status, err := c.GetRequest("/statistic/update") + if err.ErrorMsg != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + return resp, status, err } diff --git a/v5/client_test.go b/v5/client_test.go index 2460989..e304ebd 100644 --- a/v5/client_test.go +++ b/v5/client_test.go @@ -57,14 +57,17 @@ func TestClient_ApiVersionsVersions(t *testing.T) { data, status, err := c.APIVersions() if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) t.Fail() } if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) t.Fail() } if data.Success != true { + t.Errorf("%v", err.ErrorMsg) t.Fail() } } @@ -378,7 +381,7 @@ func TestClient_CustomersHistory(t *testing.T) { func TestClient_NotesNotes(t *testing.T) { c := client() - data, status, err := c.Notes(NotesRequest{Page: 1}) + data, status, err := c.CustomerNotes(NotesRequest{Page: 1}) if err.ErrorMsg != "" { t.Errorf("%v", err.ErrorMsg) t.Fail() @@ -420,7 +423,7 @@ func TestClient_NotesCreateDelete(t *testing.T) { t.Fail() } - noteCreateResponse, noteCreateStatus, err := c.NoteCreate(Note{ + noteCreateResponse, noteCreateStatus, err := c.CustomerNoteCreate(Note{ Text: "some text", ManagerID: user, Customer: &Customer{ @@ -442,7 +445,7 @@ func TestClient_NotesCreateDelete(t *testing.T) { t.Fail() } - noteDeleteResponse, noteDeleteStatus, err := c.NoteDelete(noteCreateResponse.ID) + noteDeleteResponse, noteDeleteStatus, err := c.CustomerNoteDelete(noteCreateResponse.ID) if err.ErrorMsg != "" { t.Errorf("%v", err.ErrorMsg) t.Fail() @@ -748,7 +751,7 @@ func TestClient_PaymentCreateEditDelete(t *testing.T) { Type: "cash", } - paymentCreateResponse, status, err := c.PaymentCreate(f) + paymentCreateResponse, status, err := c.OrderPaymentCreate(f) if err.ErrorMsg != "" { t.Errorf("%v", err.ErrorMsg) t.Fail() @@ -769,7 +772,7 @@ func TestClient_PaymentCreateEditDelete(t *testing.T) { Amount: 500, } - paymentEditResponse, status, err := c.PaymentEdit(k, "id") + paymentEditResponse, status, err := c.OrderPaymentEdit(k, "id") if err.ErrorMsg != "" { t.Errorf("%v", err.ErrorMsg) t.Fail() @@ -785,7 +788,7 @@ func TestClient_PaymentCreateEditDelete(t *testing.T) { t.Fail() } - paymentDeleteResponse, status, err := c.PaymentDelete(paymentCreateResponse.ID) + paymentDeleteResponse, status, err := c.OrderPaymentDelete(paymentCreateResponse.ID) if err.ErrorMsg != "" { t.Errorf("%v", err.ErrorMsg) t.Fail() @@ -969,10 +972,10 @@ func TestClient_UsersUpdate(t *testing.T) { } } -func TestClient_StaticticUpdate(t *testing.T) { +func TestClient_StaticticsUpdate(t *testing.T) { c := client() - data, st, err := c.StaticticUpdate() + data, st, err := c.StaticticsUpdate() if err.ErrorMsg != "" { t.Errorf("%v", err.ErrorMsg) t.Fail() diff --git a/v5/response.go b/v5/response.go index 15ce146..e33b9a3 100644 --- a/v5/response.go +++ b/v5/response.go @@ -16,8 +16,8 @@ func (c *Client) ErrorResponse(data []byte) (ErrorResponse, error) { return resp, err } -// SucessfulResponse type -type SucessfulResponse struct { +// SuccessfulResponse type +type SuccessfulResponse struct { Success bool `json:"success,omitempty"` }