2018-02-27 11:37:15 +03:00
|
|
|
package v5
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/google/go-querystring/query"
|
|
|
|
)
|
|
|
|
|
|
|
|
// New initalize client
|
|
|
|
func New(url string, key string) *Client {
|
|
|
|
return &Client{
|
|
|
|
url,
|
|
|
|
key,
|
|
|
|
&http.Client{Timeout: 20 * time.Second},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetRequest implements GET Request
|
2018-03-21 00:54:37 +03:00
|
|
|
func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte, int, ErrorResponse) {
|
2018-02-27 11:37:15 +03:00
|
|
|
var res []byte
|
|
|
|
var bug ErrorResponse
|
2018-03-21 00:54:37 +03:00
|
|
|
var prefix = "/api/v5"
|
|
|
|
|
|
|
|
if len(versioned) > 0 {
|
|
|
|
s := versioned[0]
|
|
|
|
|
|
|
|
if s == false {
|
|
|
|
prefix = "/api"
|
|
|
|
}
|
|
|
|
}
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
req, err := http.NewRequest("GET", fmt.Sprintf("%s%s%s", c.URL, prefix, urlWithParameters), nil)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err != nil {
|
|
|
|
bug.ErrorMsg = err.Error()
|
|
|
|
return res, 0, bug
|
|
|
|
}
|
|
|
|
|
|
|
|
req.Header.Set("X-API-KEY", c.Key)
|
|
|
|
|
|
|
|
resp, err := c.httpClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
bug.ErrorMsg = err.Error()
|
|
|
|
return res, 0, bug
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.StatusCode >= http.StatusInternalServerError {
|
|
|
|
bug.ErrorMsg = fmt.Sprintf("HTTP request error. Status code: %d.\n", resp.StatusCode)
|
|
|
|
return res, resp.StatusCode, bug
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err = buildRawResponse(resp)
|
|
|
|
if err != nil {
|
|
|
|
bug.ErrorMsg = err.Error()
|
|
|
|
}
|
|
|
|
|
|
|
|
eresp, _ := c.ErrorResponse(res)
|
|
|
|
if eresp.ErrorMsg != "" {
|
|
|
|
return res, resp.StatusCode, eresp
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, resp.StatusCode, bug
|
|
|
|
}
|
|
|
|
|
|
|
|
// PostRequest implements POST Request
|
|
|
|
func (c *Client) PostRequest(url string, postParams url.Values) ([]byte, int, ErrorResponse) {
|
|
|
|
var res []byte
|
|
|
|
var bug ErrorResponse
|
2018-03-21 00:54:37 +03:00
|
|
|
var prefix = "/api/v5"
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
req, err := http.NewRequest(
|
|
|
|
"POST",
|
2018-03-21 00:54:37 +03:00
|
|
|
fmt.Sprintf("%s%s%s", c.URL, prefix, url),
|
2018-02-27 11:37:15 +03:00
|
|
|
strings.NewReader(postParams.Encode()),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
bug.ErrorMsg = err.Error()
|
|
|
|
return res, 0, bug
|
|
|
|
}
|
|
|
|
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("X-API-KEY", c.Key)
|
|
|
|
|
|
|
|
resp, err := c.httpClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
bug.ErrorMsg = err.Error()
|
|
|
|
return res, 0, bug
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.StatusCode >= http.StatusInternalServerError {
|
|
|
|
bug.ErrorMsg = fmt.Sprintf("HTTP request error. Status code: %d.\n", resp.StatusCode)
|
|
|
|
return res, resp.StatusCode, bug
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err = buildRawResponse(resp)
|
|
|
|
if err != nil {
|
|
|
|
bug.ErrorMsg = err.Error()
|
|
|
|
return res, 0, bug
|
|
|
|
}
|
|
|
|
|
|
|
|
eresp, _ := c.ErrorResponse(res)
|
|
|
|
if eresp.ErrorMsg != "" {
|
|
|
|
return res, resp.StatusCode, eresp
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, resp.StatusCode, bug
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildRawResponse(resp *http.Response) ([]byte, error) {
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
res, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// checkBy select identifier type
|
|
|
|
func checkBy(by string) string {
|
|
|
|
var context = "id"
|
|
|
|
|
|
|
|
if by != "id" {
|
|
|
|
context = "externalId"
|
|
|
|
}
|
|
|
|
|
|
|
|
return context
|
|
|
|
}
|
|
|
|
|
|
|
|
// fillSite add site code to parameters if present
|
|
|
|
func fillSite(p *url.Values, site []string) {
|
|
|
|
if len(site) > 0 {
|
|
|
|
s := site[0]
|
|
|
|
|
|
|
|
if s != "" {
|
|
|
|
p.Add("site", s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
// APIVersions get all available API versions for exact account
|
2018-02-27 11:37:15 +03:00
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
2018-03-19 23:18:36 +03:00
|
|
|
// data, status, err := client.APIVersions()
|
2018-02-27 11:37:15 +03:00
|
|
|
//
|
|
|
|
// if err.ErrorMsg != "" {
|
|
|
|
// fmt.Printf("%v", err.ErrorMsg)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
|
|
|
// fmt.Printf("%v", err.ErrorMsg)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.versions {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2018-03-21 00:54:37 +03:00
|
|
|
func (c *Client) APIVersions() (VersionResponse, int, ErrorResponse) {
|
2018-02-27 11:37:15 +03:00
|
|
|
var resp VersionResponse
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/api-versions", false)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
// APICredentials get all available API methods for exact account
|
2018-02-27 15:22:52 +03:00
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
2018-03-19 23:18:36 +03:00
|
|
|
// data, status, err := client.APICredentials()
|
2018-02-27 15:22:52 +03:00
|
|
|
//
|
|
|
|
// if err.ErrorMsg != "" {
|
|
|
|
// fmt.Printf("%v", err.ErrorMsg)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
|
|
|
// fmt.Printf("%v", err.ErrorMsg)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.credentials {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2018-03-21 00:54:37 +03:00
|
|
|
func (c *Client) APICredentials() (CredentialResponse, int, ErrorResponse) {
|
2018-02-27 11:37:15 +03:00
|
|
|
var resp CredentialResponse
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/credentials", false)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// Customers list method
|
|
|
|
func (c *Client) Customers(parameters CustomersRequest) (CustomersResponse, int, ErrorResponse) {
|
|
|
|
var resp CustomersResponse
|
|
|
|
|
|
|
|
params, _ := query.Values(parameters)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/customers?%s", params.Encode()))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// CustomersCombine method
|
|
|
|
func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
combineJSONIn, _ := json.Marshal(&customers)
|
|
|
|
combineJSONOut, _ := json.Marshal(&resultCustomer)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
p := url.Values{
|
|
|
|
"customers": {string(combineJSONIn[:])},
|
|
|
|
"resultCustomer": {string(combineJSONOut[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest("/customers/combine", p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// CustomerCreate method
|
|
|
|
func (c *Client) CustomerCreate(customer Customer, site ...string) (CustomerChangeResponse, int, ErrorResponse) {
|
|
|
|
var resp CustomerChangeResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
customerJSON, _ := json.Marshal(&customer)
|
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"customer": {string(customerJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
fillSite(&p, site)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest("/customers/create", p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// CustomersFixExternalIds method
|
|
|
|
func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
customersJSON, _ := json.Marshal(&customers)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
p := url.Values{
|
|
|
|
"customers": {string(customersJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest("/customers/fix-external-ids", p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// CustomersHistory method
|
|
|
|
func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (CustomersHistoryResponse, int, ErrorResponse) {
|
|
|
|
var resp CustomersHistoryResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
params, _ := query.Values(parameters)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/customers/history?%s", params.Encode()))
|
|
|
|
if err.ErrorMsg != "" {
|
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
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)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/customers/notes?%s", params.Encode()))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// CustomerNoteCreate method
|
|
|
|
func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, int, ErrorResponse) {
|
|
|
|
var resp CreateResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
noteJSON, _ := json.Marshal(¬e)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"note": {string(noteJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fillSite(&p, site)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
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)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// CustomersUpload method
|
2018-03-21 00:54:37 +03:00
|
|
|
func (c *Client) CustomersUpload(customers []Customer, site ...string) (CustomersUploadResponse, int, ErrorResponse) {
|
2018-02-27 11:37:15 +03:00
|
|
|
var resp CustomersUploadResponse
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
uploadJSON, _ := json.Marshal(&customers)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-19 23:18:36 +03:00
|
|
|
"customers": {string(uploadJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fillSite(&p, site)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest("/customers/upload", p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// Customer get method
|
|
|
|
func (c *Client) Customer(id, by, site string) (CustomerResponse, int, ErrorResponse) {
|
|
|
|
var resp CustomerResponse
|
|
|
|
var context = checkBy(by)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
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) {
|
|
|
|
var resp CustomerChangeResponse
|
|
|
|
var uid = strconv.Itoa(customer.ID)
|
|
|
|
var context = checkBy(by)
|
|
|
|
|
|
|
|
if context == "externalId" {
|
|
|
|
uid = customer.ExternalID
|
|
|
|
}
|
|
|
|
|
|
|
|
customerJSON, _ := json.Marshal(&customer)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"by": {string(context)},
|
|
|
|
"customer": {string(customerJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
fillSite(&p, site)
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/customers/%s/edit", uid), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// DeliveryTracking method
|
|
|
|
func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode string) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
updateJSON, _ := json.Marshal(¶meters)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"statusUpdate": {string(updateJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/delivery/generic/%s/tracking", subcode), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// DeliveryShipments method
|
|
|
|
func (c *Client) DeliveryShipments(parameters DeliveryShipmentsRequest) (DeliveryShipmentsResponse, int, ErrorResponse) {
|
|
|
|
var resp DeliveryShipmentsResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
params, _ := query.Values(parameters)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/delivery/shipments?%s", params.Encode()))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// DeliveryShipmentCreate method
|
|
|
|
func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType string, site ...string) (DeliveryShipmentUpdateResponse, int, ErrorResponse) {
|
|
|
|
var resp DeliveryShipmentUpdateResponse
|
|
|
|
updateJSON, _ := json.Marshal(&shipment)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
p := url.Values{
|
|
|
|
"deliveryType": {string(deliveryType)},
|
|
|
|
"deliveryShipment": {string(updateJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
fillSite(&p, site)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest("/delivery/shipments/create", p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// DeliveryShipment method
|
|
|
|
func (c *Client) DeliveryShipment(id int) (DeliveryShipmentResponse, int, ErrorResponse) {
|
|
|
|
var resp DeliveryShipmentResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/delivery/shipments/%d", id))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// DeliveryShipmentEdit method
|
|
|
|
func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) (DeliveryShipmentUpdateResponse, int, ErrorResponse) {
|
|
|
|
var resp DeliveryShipmentUpdateResponse
|
|
|
|
updateJSON, _ := json.Marshal(&shipment)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"deliveryShipment": {string(updateJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fillSite(&p, site)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/delivery/shipments/%s/edit", strconv.Itoa(shipment.ID)), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// IntegrationModule method
|
|
|
|
func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int, ErrorResponse) {
|
|
|
|
var resp IntegrationModuleResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/integration-modules/%s", code))
|
|
|
|
if err.ErrorMsg != "" {
|
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
json.Unmarshal(data, &resp)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// IntegrationModuleEdit method
|
|
|
|
func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (IntegrationModuleEditResponse, int, ErrorResponse) {
|
|
|
|
var resp IntegrationModuleEditResponse
|
|
|
|
updateJSON, _ := json.Marshal(&integrationModule)
|
|
|
|
|
|
|
|
p := url.Values{"integrationModule": {string(updateJSON[:])}}
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/integration-modules/%s/edit", integrationModule.Code), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// Orders list method
|
|
|
|
func (c *Client) Orders(parameters OrdersRequest) (OrdersResponse, int, ErrorResponse) {
|
|
|
|
var resp OrdersResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
params, _ := query.Values(parameters)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/orders?%s", params.Encode()))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// OrdersCombine method
|
2018-03-21 00:54:37 +03:00
|
|
|
func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (OperationResponse, int, ErrorResponse) {
|
2018-02-27 11:37:15 +03:00
|
|
|
var resp OperationResponse
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
combineJSONIn, _ := json.Marshal(&order)
|
|
|
|
combineJSONOut, _ := json.Marshal(&resultOrder)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"technique": {technique},
|
2018-03-19 23:18:36 +03:00
|
|
|
"order": {string(combineJSONIn[:])},
|
|
|
|
"resultOrder": {string(combineJSONOut[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest("/orders/combine", p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// OrderCreate method
|
|
|
|
func (c *Client) OrderCreate(order Order, site ...string) (CreateResponse, int, ErrorResponse) {
|
|
|
|
var resp CreateResponse
|
|
|
|
orderJSON, _ := json.Marshal(&order)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"order": {string(orderJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
fillSite(&p, site)
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest("/orders/create", p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// OrdersFixExternalIds method
|
|
|
|
func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
ordersJSON, _ := json.Marshal(&orders)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
p := url.Values{
|
|
|
|
"orders": {string(ordersJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest("/orders/fix-external-ids", p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// OrdersHistory method
|
|
|
|
func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (CustomersHistoryResponse, int, ErrorResponse) {
|
|
|
|
var resp CustomersHistoryResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
params, _ := query.Values(parameters)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/orders/history?%s", params.Encode()))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// OrderPaymentCreate method
|
|
|
|
func (c *Client) OrderPaymentCreate(payment Payment, site ...string) (CreateResponse, int, ErrorResponse) {
|
2018-02-27 11:37:15 +03:00
|
|
|
var resp CreateResponse
|
2018-03-21 00:54:37 +03:00
|
|
|
|
|
|
|
paymentJSON, _ := json.Marshal(&payment)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"payment": {string(paymentJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
fillSite(&p, site)
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest("/orders/payments/create", p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// OrderPaymentDelete method
|
|
|
|
func (c *Client) OrderPaymentDelete(id int) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"id": {string(id)},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/orders/payments/%d/delete", id), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// 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)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
if context == "externalId" {
|
|
|
|
uid = payment.ExternalID
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
paymentJSON, _ := json.Marshal(&payment)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
p := url.Values{
|
|
|
|
"payment": {string(paymentJSON[:])},
|
|
|
|
}
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
fillSite(&p, site)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/orders/payments/%s/edit", uid), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// OrdersUpload method
|
|
|
|
func (c *Client) OrdersUpload(orders []Order, site ...string) (OrdersUploadResponse, int, ErrorResponse) {
|
|
|
|
var resp OrdersUploadResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
uploadJSON, _ := json.Marshal(&orders)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"orders": {string(uploadJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
fillSite(&p, site)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest("/orders/upload", p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// Order get method
|
|
|
|
func (c *Client) Order(id, by, site string) (OrderResponse, int, ErrorResponse) {
|
|
|
|
var resp OrderResponse
|
|
|
|
var context = checkBy(by)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
fw := OrderRequest{context, site}
|
|
|
|
params, _ := query.Values(fw)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/orders/%s?%s", id, params.Encode()))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// OrderEdit method
|
|
|
|
func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateResponse, int, ErrorResponse) {
|
2018-02-27 11:37:15 +03:00
|
|
|
var resp CreateResponse
|
2018-03-21 00:54:37 +03:00
|
|
|
var uid = strconv.Itoa(order.ID)
|
|
|
|
var context = checkBy(by)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
if context == "externalId" {
|
|
|
|
uid = order.ExternalID
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
orderJSON, _ := json.Marshal(&order)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"by": {string(context)},
|
|
|
|
"order": {string(orderJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fillSite(&p, site)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/orders/%s/edit", uid), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// Packs list method
|
|
|
|
func (c *Client) Packs(parameters PacksRequest) (PacksResponse, int, ErrorResponse) {
|
|
|
|
var resp PacksResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
params, _ := query.Values(parameters)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/orders/packs?%s", params.Encode()))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// PackCreate method
|
|
|
|
func (c *Client) PackCreate(pack Pack) (CreateResponse, int, ErrorResponse) {
|
2018-02-27 11:37:15 +03:00
|
|
|
var resp CreateResponse
|
2018-03-21 00:54:37 +03:00
|
|
|
packJSON, _ := json.Marshal(&pack)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"pack": {string(packJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest("/orders/packs/create", p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// PacksHistory method
|
|
|
|
func (c *Client) PacksHistory(parameters PacksHistoryRequest) (PacksHistoryResponse, int, ErrorResponse) {
|
|
|
|
var resp PacksHistoryResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
params, _ := query.Values(parameters)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/orders/packs/history?%s", params.Encode()))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// Pack get method
|
|
|
|
func (c *Client) Pack(id int) (PackResponse, int, ErrorResponse) {
|
|
|
|
var resp PackResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/orders/packs/%d", id))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// PackDelete method
|
|
|
|
func (c *Client) PackDelete(id int) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/orders/packs/%d/delete", id), url.Values{})
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// PackEdit method
|
|
|
|
func (c *Client) PackEdit(pack Pack) (CreateResponse, int, ErrorResponse) {
|
|
|
|
var resp CreateResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
packJSON, _ := json.Marshal(&pack)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"pack": {string(packJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/orders/packs/%d/edit", pack.ID), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Countries method
|
2018-03-21 00:54:37 +03:00
|
|
|
func (c *Client) Countries() (CountriesResponse, int, ErrorResponse) {
|
2018-02-27 11:37:15 +03:00
|
|
|
var resp CountriesResponse
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/reference/countries")
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// CostGroups method
|
2018-03-21 00:54:37 +03:00
|
|
|
func (c *Client) CostGroups() (CostGroupsResponse, int, ErrorResponse) {
|
2018-02-27 11:37:15 +03:00
|
|
|
var resp CostGroupsResponse
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/reference/cost-groups")
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// CostGroupEdit method
|
|
|
|
func (c *Client) CostGroupEdit(costGroup CostGroup) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
|
|
|
|
|
|
|
objJSON, _ := json.Marshal(&costGroup)
|
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"costGroup": {string(objJSON[:])},
|
|
|
|
}
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/cost-groups/%s/edit", costGroup.Code), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// CostItems method
|
|
|
|
func (c *Client) CostItems() (CostItemsResponse, int, ErrorResponse) {
|
|
|
|
var resp CostItemsResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/reference/cost-items")
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// CostItemEdit method
|
|
|
|
func (c *Client) CostItemEdit(costItem CostItem) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
|
|
|
|
|
|
|
objJSON, _ := json.Marshal(&costItem)
|
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"costItem": {string(objJSON[:])},
|
|
|
|
}
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/cost-items/%s/edit", costItem.Code), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// Couriers method
|
|
|
|
func (c *Client) Couriers() (CouriersResponse, int, ErrorResponse) {
|
|
|
|
var resp CouriersResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/reference/couriers")
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// CourierCreate method
|
|
|
|
func (c *Client) CourierCreate(courier Courier) (CreateResponse, int, ErrorResponse) {
|
|
|
|
var resp CreateResponse
|
|
|
|
|
|
|
|
objJSON, _ := json.Marshal(&courier)
|
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"courier": {string(objJSON[:])},
|
|
|
|
}
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest("/reference/couriers/create", p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// CourierEdit method
|
|
|
|
func (c *Client) CourierEdit(courier Courier) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
|
|
|
|
|
|
|
objJSON, _ := json.Marshal(&courier)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
p := url.Values{
|
|
|
|
"courier": {string(objJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/couriers/%d/edit", courier.ID), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// DeliveryServices method
|
|
|
|
func (c *Client) DeliveryServices() (DeliveryServiceResponse, int, ErrorResponse) {
|
|
|
|
var resp DeliveryServiceResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/reference/delivery-services")
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// DeliveryServiceEdit method
|
|
|
|
func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
|
|
|
|
|
|
|
objJSON, _ := json.Marshal(&deliveryService)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
p := url.Values{
|
|
|
|
"deliveryService": {string(objJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/delivery-services/%s/edit", deliveryService.Code), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// DeliveryTypes method
|
|
|
|
func (c *Client) DeliveryTypes() (DeliveryTypesResponse, int, ErrorResponse) {
|
|
|
|
var resp DeliveryTypesResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/reference/delivery-types")
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// DeliveryTypeEdit method
|
|
|
|
func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
|
|
|
|
|
|
|
objJSON, _ := json.Marshal(&deliveryType)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
p := url.Values{
|
|
|
|
"deliveryType": {string(objJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/delivery-types/%s/edit", deliveryType.Code), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// LegalEntities method
|
|
|
|
func (c *Client) LegalEntities() (LegalEntitiesResponse, int, ErrorResponse) {
|
|
|
|
var resp LegalEntitiesResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/reference/legal-entities")
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// LegalEntityEdit method
|
|
|
|
func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
|
|
|
|
|
|
|
objJSON, _ := json.Marshal(&legalEntity)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
p := url.Values{
|
|
|
|
"legalEntity": {string(objJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/legal-entities/%s/edit", legalEntity.Code), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// OrderMethods method
|
|
|
|
func (c *Client) OrderMethods() (OrderMethodsResponse, int, ErrorResponse) {
|
|
|
|
var resp OrderMethodsResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/reference/order-methods")
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// OrderMethodEdit method
|
|
|
|
func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
|
|
|
|
|
|
|
objJSON, _ := json.Marshal(&orderMethod)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
p := url.Values{
|
|
|
|
"orderMethod": {string(objJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/order-methods/%s/edit", orderMethod.Code), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// OrderTypes method
|
|
|
|
func (c *Client) OrderTypes() (OrderTypesResponse, int, ErrorResponse) {
|
|
|
|
var resp OrderTypesResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/reference/order-types")
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// OrderTypeEdit method
|
|
|
|
func (c *Client) OrderTypeEdit(orderType OrderType) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
objJSON, _ := json.Marshal(&orderType)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"orderType": {string(objJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/order-types/%s/edit", orderType.Code), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// PaymentStatuses method
|
|
|
|
func (c *Client) PaymentStatuses() (PaymentStatusesResponse, int, ErrorResponse) {
|
|
|
|
var resp PaymentStatusesResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/reference/payment-statuses")
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// PaymentStatusEdit method
|
|
|
|
func (c *Client) PaymentStatusEdit(paymentStatus PaymentStatus) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
objJSON, _ := json.Marshal(&paymentStatus)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"paymentStatus": {string(objJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/payment-statuses/%s/edit", paymentStatus.Code), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// PaymentTypes method
|
|
|
|
func (c *Client) PaymentTypes() (PaymentTypesResponse, int, ErrorResponse) {
|
|
|
|
var resp PaymentTypesResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/reference/payment-types")
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// PaymentTypeEdit method
|
|
|
|
func (c *Client) PaymentTypeEdit(paymentType PaymentType) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
objJSON, _ := json.Marshal(&paymentType)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"paymentType": {string(objJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/payment-types/%s/edit", paymentType.Code), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// PriceTypes method
|
|
|
|
func (c *Client) PriceTypes() (PriceTypesResponse, int, ErrorResponse) {
|
|
|
|
var resp PriceTypesResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/reference/price-types")
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// PriceTypeEdit method
|
|
|
|
func (c *Client) PriceTypeEdit(priceType PriceType) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
objJSON, _ := json.Marshal(&priceType)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"priceType": {string(objJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/price-types/%s/edit", priceType.Code), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// ProductStatuses method
|
|
|
|
func (c *Client) ProductStatuses() (ProductStatusesResponse, int, ErrorResponse) {
|
|
|
|
var resp ProductStatusesResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/reference/product-statuses")
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// ProductStatusEdit method
|
|
|
|
func (c *Client) ProductStatusEdit(productStatus ProductStatus) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
objJSON, _ := json.Marshal(&productStatus)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"productStatus": {string(objJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/product-statuses/%s/edit", productStatus.Code), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// Sites method
|
|
|
|
func (c *Client) Sites() (SitesResponse, int, ErrorResponse) {
|
|
|
|
var resp SitesResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/reference/sites")
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// SiteEdit method
|
|
|
|
func (c *Client) SiteEdit(site Site) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
objJSON, _ := json.Marshal(&site)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"site": {string(objJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/sites/%s/edit", site.Code), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// StatusGroups method
|
|
|
|
func (c *Client) StatusGroups() (StatusGroupsResponse, int, ErrorResponse) {
|
|
|
|
var resp StatusGroupsResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/reference/status-groups")
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// Statuses method
|
|
|
|
func (c *Client) Statuses() (StatusesResponse, int, ErrorResponse) {
|
|
|
|
var resp StatusesResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/reference/statuses")
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// StatusEdit method
|
2018-03-21 00:54:37 +03:00
|
|
|
func (c *Client) StatusEdit(st Status) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
objJSON, _ := json.Marshal(&st)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-19 23:18:36 +03:00
|
|
|
"status": {string(objJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/statuses/%s/edit", st.Code), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// Stores method
|
|
|
|
func (c *Client) Stores() (StoresResponse, int, ErrorResponse) {
|
|
|
|
var resp StoresResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/reference/stores")
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// StoreEdit method
|
2018-03-21 00:54:37 +03:00
|
|
|
func (c *Client) StoreEdit(store Store) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
objJSON, _ := json.Marshal(&store)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-19 23:18:36 +03:00
|
|
|
"store": {string(objJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/stores/%s/edit", store.Code), p)
|
|
|
|
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("/segments?%s", params.Encode()))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Inventories method
|
2018-03-21 00:54:37 +03:00
|
|
|
func (c *Client) Inventories(parameters InventoriesRequest) (InventoriesResponse, int, ErrorResponse) {
|
2018-02-27 11:37:15 +03:00
|
|
|
var resp InventoriesResponse
|
|
|
|
|
|
|
|
params, _ := query.Values(parameters)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/store/inventories?%s", params.Encode()))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// InventoriesUpload method
|
2018-03-21 00:54:37 +03:00
|
|
|
func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string) (StoreUploadResponse, int, ErrorResponse) {
|
2018-02-27 11:37:15 +03:00
|
|
|
var resp StoreUploadResponse
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
uploadJSON, _ := json.Marshal(&inventories)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-19 23:18:36 +03:00
|
|
|
"offers": {string(uploadJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fillSite(&p, site)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest("/store/inventories/upload", p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// PricesUpload method
|
2018-03-21 00:54:37 +03:00
|
|
|
func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, int, ErrorResponse) {
|
2018-02-27 11:37:15 +03:00
|
|
|
var resp StoreUploadResponse
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
uploadJSON, _ := json.Marshal(&prices)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-19 23:18:36 +03:00
|
|
|
"prices": {string(uploadJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest("/store/prices/upload", p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// ProductsGroup method
|
2018-03-21 00:54:37 +03:00
|
|
|
func (c *Client) ProductsGroup(parameters ProductsGroupsRequest) (ProductsGroupsResponse, int, ErrorResponse) {
|
2018-02-27 11:37:15 +03:00
|
|
|
var resp ProductsGroupsResponse
|
|
|
|
|
|
|
|
params, _ := query.Values(parameters)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/store/product-groups?%s", params.Encode()))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
// Products method
|
2018-03-21 00:54:37 +03:00
|
|
|
func (c *Client) Products(parameters ProductsRequest) (ProductsResponse, int, ErrorResponse) {
|
2018-02-27 11:37:15 +03:00
|
|
|
var resp ProductsResponse
|
|
|
|
|
|
|
|
params, _ := query.Values(parameters)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/store/products?%s", params.Encode()))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// ProductsProperties method
|
2018-03-21 00:54:37 +03:00
|
|
|
func (c *Client) ProductsProperties(parameters ProductsPropertiesRequest) (ProductsPropertiesResponse, int, ErrorResponse) {
|
2018-02-27 11:37:15 +03:00
|
|
|
var resp ProductsPropertiesResponse
|
|
|
|
|
|
|
|
params, _ := query.Values(parameters)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/store/products/properties?%s", params.Encode()))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// Tasks list method
|
|
|
|
func (c *Client) Tasks(parameters TasksRequest) (TasksResponse, int, ErrorResponse) {
|
|
|
|
var resp TasksResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
params, _ := query.Values(parameters)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/tasks?%s", params.Encode()))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// TaskCreate method
|
|
|
|
func (c *Client) TaskCreate(task Task, site ...string) (CreateResponse, int, ErrorResponse) {
|
|
|
|
var resp CreateResponse
|
|
|
|
taskJSON, _ := json.Marshal(&task)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
p := url.Values{
|
|
|
|
"task": {string(taskJSON[:])},
|
|
|
|
}
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
fillSite(&p, site)
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest("/tasks/create", p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// Task get method
|
|
|
|
func (c *Client) Task(id int) (TaskResponse, int, ErrorResponse) {
|
|
|
|
var resp TaskResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/tasks/%d", id))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// 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)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"task": {string(taskJSON[:])},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fillSite(&p, site)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/tasks/%s/edit", uid), p)
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// UserGroups list method
|
|
|
|
func (c *Client) UserGroups(parameters UserGroupsRequest) (UserGroupsResponse, int, ErrorResponse) {
|
|
|
|
var resp UserGroupsResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
params, _ := query.Values(parameters)
|
|
|
|
|
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/user-groups?%s", params.Encode()))
|
|
|
|
if err.ErrorMsg != "" {
|
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Users list method
|
|
|
|
func (c *Client) Users(parameters UsersRequest) (UsersResponse, int, ErrorResponse) {
|
|
|
|
var resp UsersResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
params, _ := query.Values(parameters)
|
|
|
|
|
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/users?%s", params.Encode()))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// User get method
|
|
|
|
func (c *Client) User(id int) (UserResponse, int, ErrorResponse) {
|
|
|
|
var resp UserResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/users/%d", id))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
// UserStatus update method
|
|
|
|
func (c *Client) UserStatus(id int, status string) (SuccessfulResponse, int, ErrorResponse) {
|
|
|
|
var resp SuccessfulResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
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
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.GetRequest("/statistic/update")
|
2018-02-27 11:37:15 +03:00
|
|
|
if err.ErrorMsg != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|