Customers & Orders combine methods

This commit is contained in:
Alex Lushpai 2018-02-06 15:54:07 +03:00
parent a04578926c
commit 76761cc927
4 changed files with 364 additions and 168 deletions

View file

@ -305,6 +305,28 @@ func (c *Client) CustomersUpload(customers []Customer, site ...string) (*Custome
return &resp, status, err
}
// CustomersCombine method
func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) (*SucessfulResponse, int, ErrorResponse) {
var resp SucessfulResponse
combineJsonIn, _ := json.Marshal(&customers)
combineJsonOut, _ := json.Marshal(&resultCustomer)
p := url.Values{
"customers": {string(combineJsonIn[:])},
"resultCustomer": {string(combineJsonOut[:])},
}
data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/combine", versionedPrefix), p)
if err.ErrorMsg != "" {
return &resp, status, err
}
json.Unmarshal(data, &resp)
return &resp, status, err
}
// CustomersFixExternalIds method
func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (*SucessfulResponse, int, ErrorResponse) {
var resp SucessfulResponse
@ -447,6 +469,29 @@ func (c *Client) OrdersUpload(orders []Order, site ...string) (*OrdersUploadResp
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

File diff suppressed because it is too large Load diff

View file

@ -41,8 +41,8 @@ type OrdersRequest struct {
// OrdersUploadRequest type
type OrdersUploadRequest struct {
Customers []Order `url:"orders,omitempty,brackets"`
Site string `url:"site,omitempty"`
Orders []Order `url:"orders,omitempty,brackets"`
Site string `url:"site,omitempty"`
}
// OrdersHistoryRequest type

View file

@ -27,6 +27,12 @@ type CreateResponse struct {
Id int `json:"id,omitempty"`
}
// OperationResponse type
type OperationResponse struct {
Success bool `json:"success"`
Errors map[string]string `json:"errors,omitempty,brackets"`
}
// VersionResponse return available API versions
type VersionResponse struct {
Success bool `json:"success,omitempty"`