mirror of
https://github.com/retailcrm/api-client-go.git
synced 2024-11-24 05:46:05 +03:00
Adding functionality from recent updates to the library
This commit is contained in:
parent
5c6d2ebead
commit
ab648cd06a
1
api-client-go
Submodule
1
api-client-go
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 5c6d2ebead217f5916767a9a542117fa496c677b
|
40
client.go
40
client.go
@ -2136,10 +2136,14 @@ func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int,
|
|||||||
func (c *Client) LinksCreate(link SerializedOrderLink, site ...string) (SuccessfulResponse, int, error) {
|
func (c *Client) LinksCreate(link SerializedOrderLink, site ...string) (SuccessfulResponse, int, error) {
|
||||||
var resp SuccessfulResponse
|
var resp SuccessfulResponse
|
||||||
|
|
||||||
linkJson, _ := json.Marshal(link)
|
linkJSON, err := json.Marshal(link)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return resp, http.StatusBadRequest, err
|
||||||
|
}
|
||||||
|
|
||||||
p := url.Values{
|
p := url.Values{
|
||||||
"link": {string(linkJson)},
|
"link": {string(linkJSON)},
|
||||||
}
|
}
|
||||||
|
|
||||||
fillSite(&p, site)
|
fillSite(&p, site)
|
||||||
@ -2166,7 +2170,7 @@ func (c *Client) LinksCreate(link SerializedOrderLink, site ...string) (Successf
|
|||||||
//
|
//
|
||||||
// var client = retailcrm.New("https://demo.url", "09jIJ")
|
// var client = retailcrm.New("https://demo.url", "09jIJ")
|
||||||
//
|
//
|
||||||
// data, status, err := client.ClientIdsUpload([]retailcrm.ClientId{
|
// data, status, err := client.ClientIdsUpload([]retailcrm.ClientID{
|
||||||
// {
|
// {
|
||||||
// Value: "value",
|
// Value: "value",
|
||||||
// Order: LinkedOrder{ID: 10, ExternalID: "externalID", Number: "number"},
|
// Order: LinkedOrder{ID: 10, ExternalID: "externalID", Number: "number"},
|
||||||
@ -2192,9 +2196,13 @@ func (c *Client) LinksCreate(link SerializedOrderLink, site ...string) (Successf
|
|||||||
// if data.Success == true {
|
// if data.Success == true {
|
||||||
// log.Println("Upload is successful")
|
// log.Println("Upload is successful")
|
||||||
// }
|
// }
|
||||||
func (c *Client) ClientIdsUpload(clientIds []ClientId) (ClientIdResponse, int, error) {
|
func (c *Client) ClientIdsUpload(clientIds []ClientID) (ClientIDResponse, int, error) {
|
||||||
var resp ClientIdResponse
|
var resp ClientIDResponse
|
||||||
clientIdsJSON, _ := json.Marshal(&clientIds)
|
clientIdsJSON, err := json.Marshal(&clientIds)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return resp, http.StatusBadRequest, err
|
||||||
|
}
|
||||||
|
|
||||||
p := url.Values{
|
p := url.Values{
|
||||||
"clientIds": {string(clientIdsJSON)},
|
"clientIds": {string(clientIdsJSON)},
|
||||||
@ -2228,7 +2236,7 @@ func (c *Client) ClientIdsUpload(clientIds []ClientId) (ClientIdResponse, int, e
|
|||||||
// Campaign: "campaign",
|
// Campaign: "campaign",
|
||||||
// Keyword: "keyword",
|
// Keyword: "keyword",
|
||||||
// Content: "content",
|
// Content: "content",
|
||||||
// ClientId: "10",
|
// ClientID: "10",
|
||||||
// Order: LinkedOrder{ID: 10, ExternalID: "externalId", Number: "number"},
|
// Order: LinkedOrder{ID: 10, ExternalID: "externalId", Number: "number"},
|
||||||
// Customer: SerializedEntityCustomer{ID: 10, ExternalID: "externalId"},
|
// Customer: SerializedEntityCustomer{ID: 10, ExternalID: "externalId"},
|
||||||
// Site: "site",
|
// Site: "site",
|
||||||
@ -2248,7 +2256,11 @@ func (c *Client) ClientIdsUpload(clientIds []ClientId) (ClientIdResponse, int, e
|
|||||||
// }
|
// }
|
||||||
func (c *Client) SourcesUpload(sources []Source) (SourcesResponse, int, error) {
|
func (c *Client) SourcesUpload(sources []Source) (SourcesResponse, int, error) {
|
||||||
var resp SourcesResponse
|
var resp SourcesResponse
|
||||||
sourcesJSON, _ := json.Marshal(&sources)
|
sourcesJSON, err := json.Marshal(&sources)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return resp, http.StatusBadRequest, err
|
||||||
|
}
|
||||||
|
|
||||||
p := url.Values{
|
p := url.Values{
|
||||||
"sources": {string(sourcesJSON)},
|
"sources": {string(sourcesJSON)},
|
||||||
@ -2335,7 +2347,11 @@ func (c *Client) Currencies() (CurrencyResponse, int, error) {
|
|||||||
// }
|
// }
|
||||||
func (c *Client) CurrenciesCreate(currency Currency) (CurrencyCreateResponse, int, error) {
|
func (c *Client) CurrenciesCreate(currency Currency) (CurrencyCreateResponse, int, error) {
|
||||||
var resp CurrencyCreateResponse
|
var resp CurrencyCreateResponse
|
||||||
currencyJSON, _ := json.Marshal(¤cy)
|
currencyJSON, err := json.Marshal(¤cy)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return resp, http.StatusBadRequest, err
|
||||||
|
}
|
||||||
|
|
||||||
p := url.Values{
|
p := url.Values{
|
||||||
"currency": {string(currencyJSON)},
|
"currency": {string(currencyJSON)},
|
||||||
@ -2388,7 +2404,11 @@ func (c *Client) CurrenciesEdit(currency Currency) (SuccessfulResponse, int, err
|
|||||||
var resp SuccessfulResponse
|
var resp SuccessfulResponse
|
||||||
var uid = strconv.Itoa(currency.ID)
|
var uid = strconv.Itoa(currency.ID)
|
||||||
|
|
||||||
currencyJSON, _ := json.Marshal(¤cy)
|
currencyJSON, err := json.Marshal(¤cy)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return resp, http.StatusBadRequest, err
|
||||||
|
}
|
||||||
|
|
||||||
p := url.Values{
|
p := url.Values{
|
||||||
"currency": {string(currencyJSON)},
|
"currency": {string(currencyJSON)},
|
||||||
|
103
client_test.go
103
client_test.go
@ -1998,10 +1998,10 @@ func TestClient_LinksCreate(t *testing.T) {
|
|||||||
Orders: orders,
|
Orders: orders,
|
||||||
}
|
}
|
||||||
|
|
||||||
linkJson, _ := json.Marshal(link)
|
linkJSON, _ := json.Marshal(link)
|
||||||
|
|
||||||
p := url.Values{
|
p := url.Values{
|
||||||
"link": {string(linkJson)},
|
"link": {string(linkJSON)},
|
||||||
}
|
}
|
||||||
|
|
||||||
defer gock.Off()
|
defer gock.Off()
|
||||||
@ -2028,10 +2028,45 @@ func TestClient_LinksCreate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClient_LinksCreate_Fail(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
|
||||||
|
orders := []LinkedOrder{{ID: 10}}
|
||||||
|
|
||||||
|
link := SerializedOrderLink{
|
||||||
|
Comment: "comment",
|
||||||
|
Orders: orders,
|
||||||
|
}
|
||||||
|
|
||||||
|
linkJSON, _ := json.Marshal(link)
|
||||||
|
|
||||||
|
p := url.Values{
|
||||||
|
"link": {string(linkJSON)},
|
||||||
|
}
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
|
||||||
|
gock.New(crmURL).
|
||||||
|
Post("/links/create").
|
||||||
|
BodyString(p.Encode()).
|
||||||
|
Reply(400).
|
||||||
|
BodyString(`{"errorMsg": "Errors in the entity format", errors: [orders: "This collection should contain 2 elements or more."}`)
|
||||||
|
|
||||||
|
data, _, err := c.LinksCreate(link)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Error must be return")
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.Success != false {
|
||||||
|
t.Error(successFail)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestClient_ClientIdsUpload(t *testing.T) {
|
func TestClient_ClientIdsUpload(t *testing.T) {
|
||||||
c := client()
|
c := client()
|
||||||
|
|
||||||
clientIds := []ClientId{
|
clientIds := []ClientID{
|
||||||
{
|
{
|
||||||
Value: "value",
|
Value: "value",
|
||||||
Order: LinkedOrder{ID: 10, ExternalID: "externalID", Number: "number"},
|
Order: LinkedOrder{ID: 10, ExternalID: "externalID", Number: "number"},
|
||||||
@ -2078,18 +2113,11 @@ func TestClient_ClientIdsUpload(t *testing.T) {
|
|||||||
func TestClient_ClientIdsUpload_Fail(t *testing.T) {
|
func TestClient_ClientIdsUpload_Fail(t *testing.T) {
|
||||||
c := client()
|
c := client()
|
||||||
|
|
||||||
clientIds := []ClientId{
|
clientIds := []ClientID{
|
||||||
{
|
{
|
||||||
Value: "value",
|
Value: "value",
|
||||||
Order: LinkedOrder{ID: 10, ExternalID: "externalID", Number: "number"},
|
Order: LinkedOrder{ID: 10},
|
||||||
Customer: SerializedEntityCustomer{},
|
Customer: SerializedEntityCustomer{},
|
||||||
Site: "site",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Value: "value2",
|
|
||||||
Order: LinkedOrder{ID: 12, ExternalID: "externalID2", Number: "number2"},
|
|
||||||
Customer: SerializedEntityCustomer{ID: 12, ExternalID: "externalID2"},
|
|
||||||
Site: "site2",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2103,22 +2131,11 @@ func TestClient_ClientIdsUpload_Fail(t *testing.T) {
|
|||||||
gock.New(crmURL).
|
gock.New(crmURL).
|
||||||
Post("/web-analytics/client-ids/upload").
|
Post("/web-analytics/client-ids/upload").
|
||||||
BodyString(p.Encode()).
|
BodyString(p.Encode()).
|
||||||
Reply(460).
|
Reply(400).
|
||||||
BodyString(`
|
BodyString(`
|
||||||
{
|
{
|
||||||
"success": false,
|
"errorMsg": "ClientIds are loaded with errors",
|
||||||
"failedClientIds": {
|
"errors": [0: "customer: Set one of the following fields: id, externalId"]
|
||||||
"value": "value",
|
|
||||||
"order": {
|
|
||||||
"id": 10,
|
|
||||||
"externalID": "externalID",
|
|
||||||
"number": "number"
|
|
||||||
},
|
|
||||||
"customer": {}.
|
|
||||||
"site": "site2"
|
|
||||||
},
|
|
||||||
"errorMsg": "customer is required",
|
|
||||||
"errors": [460]
|
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
@ -2143,7 +2160,7 @@ func TestClient_SourcesUpload(t *testing.T) {
|
|||||||
Campaign: "campaign",
|
Campaign: "campaign",
|
||||||
Keyword: "keyword",
|
Keyword: "keyword",
|
||||||
Content: "content",
|
Content: "content",
|
||||||
ClientId: "10",
|
ClientID: "10",
|
||||||
Order: LinkedOrder{ID: 10, ExternalID: "externalId", Number: "number"},
|
Order: LinkedOrder{ID: 10, ExternalID: "externalId", Number: "number"},
|
||||||
Customer: SerializedEntityCustomer{ID: 10, ExternalID: "externalId"},
|
Customer: SerializedEntityCustomer{ID: 10, ExternalID: "externalId"},
|
||||||
Site: "site",
|
Site: "site",
|
||||||
@ -2189,19 +2206,8 @@ func TestClient_SourcesUpload_Fail(t *testing.T) {
|
|||||||
Campaign: "campaign",
|
Campaign: "campaign",
|
||||||
Keyword: "keyword",
|
Keyword: "keyword",
|
||||||
Content: "content",
|
Content: "content",
|
||||||
ClientId: "10",
|
ClientID: "12",
|
||||||
Order: LinkedOrder{ID: 10, ExternalID: "externalId", Number: "number"},
|
Order: LinkedOrder{ID: 10, ExternalID: "externalId", Number: "number"},
|
||||||
Customer: SerializedEntityCustomer{ID: 10, ExternalID: "externalId"},
|
|
||||||
Site: "site",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Source: "source",
|
|
||||||
Medium: "medium",
|
|
||||||
Campaign: "campaign",
|
|
||||||
Keyword: "keyword",
|
|
||||||
Content: "content",
|
|
||||||
ClientId: "12",
|
|
||||||
Order: LinkedOrder{},
|
|
||||||
Customer: SerializedEntityCustomer{},
|
Customer: SerializedEntityCustomer{},
|
||||||
Site: "site",
|
Site: "site",
|
||||||
},
|
},
|
||||||
@ -2216,22 +2222,11 @@ func TestClient_SourcesUpload_Fail(t *testing.T) {
|
|||||||
gock.New(crmURL).
|
gock.New(crmURL).
|
||||||
Post("/web-analytics/sources/upload").
|
Post("/web-analytics/sources/upload").
|
||||||
BodyString(p.Encode()).
|
BodyString(p.Encode()).
|
||||||
Reply(460).
|
Reply(400).
|
||||||
BodyString(`
|
BodyString(`
|
||||||
{
|
{
|
||||||
"success": false,
|
"errorMsg": "ClientIds are loaded with errors",
|
||||||
"failedSources": {
|
"errors": [0: "customer: Set one of the following fields: id, externalId"]
|
||||||
"source": "source",
|
|
||||||
"medium": "medium",
|
|
||||||
"campaign": "campaign",
|
|
||||||
"keyword": "keyword",
|
|
||||||
"content": "content",
|
|
||||||
"order": {},
|
|
||||||
"customer": {}.
|
|
||||||
"site": "sitey"
|
|
||||||
},
|
|
||||||
"errorMsg": "order and customer is required",
|
|
||||||
"errors": [460]
|
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
@ -2325,7 +2320,7 @@ func TestClient_CurrenciesCreate(t *testing.T) {
|
|||||||
|
|
||||||
currency := Currency{
|
currency := Currency{
|
||||||
ID: 10,
|
ID: 10,
|
||||||
Code: "code",
|
Code: "RUB",
|
||||||
IsBase: true,
|
IsBase: true,
|
||||||
IsAutoConvert: true,
|
IsAutoConvert: true,
|
||||||
AutoConvertExtraPercent: 1,
|
AutoConvertExtraPercent: 1,
|
||||||
|
10
response.go
10
response.go
@ -596,18 +596,18 @@ type AccountBonusOperationsResponse struct {
|
|||||||
BonusOperations []BonusOperation `json:"bonusOperations,omitempty"`
|
BonusOperations []BonusOperation `json:"bonusOperations,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientIdResponse type
|
// ClientIDResponse type.
|
||||||
type ClientIdResponse struct {
|
type ClientIDResponse struct {
|
||||||
Success bool `json:"success"`
|
|
||||||
FailedClientIds []ClientId `json:"failed_client_ids,omitempty"`
|
|
||||||
ErrorMsg string `json:"errorMsg,omitempty"`
|
ErrorMsg string `json:"errorMsg,omitempty"`
|
||||||
Errors map[string]string `json:"errors,omitempty"`
|
Errors map[string]string `json:"errors,omitempty"`
|
||||||
|
FailedClientIds []ClientID `json:"failed_client_ids,omitempty"`
|
||||||
|
Success bool `json:"success"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SourcesResponse type
|
// SourcesResponse type
|
||||||
type SourcesResponse struct {
|
type SourcesResponse struct {
|
||||||
Success bool `json:"success"`
|
Success bool `json:"success"`
|
||||||
FailedSources []Source `json:"failed_sources,omitempty"`
|
FailedSources []Source `json:"failedSources,omitempty"`
|
||||||
ErrorMsg string `json:"errorMsg,omitempty"`
|
ErrorMsg string `json:"errorMsg,omitempty"`
|
||||||
Errors map[string]string `json:"errors,omitempty"`
|
Errors map[string]string `json:"errors,omitempty"`
|
||||||
}
|
}
|
||||||
|
32
types.go
32
types.go
@ -69,7 +69,7 @@ type Source struct {
|
|||||||
Campaign string `json:"campaign,omitempty"`
|
Campaign string `json:"campaign,omitempty"`
|
||||||
Keyword string `json:"keyword,omitempty"`
|
Keyword string `json:"keyword,omitempty"`
|
||||||
Content string `json:"content,omitempty"`
|
Content string `json:"content,omitempty"`
|
||||||
ClientId string `json:"client_id,omitempty"`
|
ClientID string `json:"client_id,omitempty"`
|
||||||
Order LinkedOrder `json:"order,omitempty"`
|
Order LinkedOrder `json:"order,omitempty"`
|
||||||
Customer SerializedEntityCustomer `json:"customer,omitempty"`
|
Customer SerializedEntityCustomer `json:"customer,omitempty"`
|
||||||
Site string `json:"site,omitempty"`
|
Site string `json:"site,omitempty"`
|
||||||
@ -352,45 +352,45 @@ type Order struct {
|
|||||||
Currency string `json:"currency,omitempty"`
|
Currency string `json:"currency,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LinkedOrder type
|
// LinkedOrder type.
|
||||||
type LinkedOrder struct {
|
type LinkedOrder struct {
|
||||||
ID int `json:"id,omitempty"`
|
|
||||||
Number string `json:"number,omitempty"`
|
Number string `json:"number,omitempty"`
|
||||||
ExternalID string `json:"externalID,omitempty"`
|
ExternalID string `json:"externalID,omitempty"`
|
||||||
|
ID int `json:"id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderLink type
|
// OrderLink type.
|
||||||
type OrderLink struct {
|
type OrderLink struct {
|
||||||
Comment string `json:"comment,omitempty"`
|
Comment string `json:"comment,omitempty"`
|
||||||
Order LinkedOrder `json:"order,omitempty"`
|
|
||||||
CreatedAt string `json:"createdAt,omitempty"`
|
CreatedAt string `json:"createdAt,omitempty"`
|
||||||
|
Order LinkedOrder `json:"order,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SerializedOrderLink type
|
// SerializedOrderLink type.
|
||||||
type SerializedOrderLink struct {
|
type SerializedOrderLink struct {
|
||||||
Comment string `json:"comment,omitempty"`
|
Comment string `json:"comment,omitempty"`
|
||||||
Orders []LinkedOrder `json:"orders,omitempty"`
|
|
||||||
CreatedAt string `json:"createdAt,omitempty"`
|
CreatedAt string `json:"createdAt,omitempty"`
|
||||||
|
Orders []LinkedOrder `json:"orders,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientId type
|
// ClientID type.
|
||||||
type ClientId struct {
|
type ClientID struct {
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
CreateAt string `json:"createAt,omitempty"`
|
CreateAt string `json:"createAt,omitempty"`
|
||||||
Order LinkedOrder `json:"order,omitempty"`
|
|
||||||
Customer SerializedEntityCustomer `json:"customer,omitempty"`
|
|
||||||
Site string `json:"site,omitempty"`
|
Site string `json:"site,omitempty"`
|
||||||
|
Customer SerializedEntityCustomer `json:"customer,omitempty"`
|
||||||
|
Order LinkedOrder `json:"order,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Currency type
|
// Currency type.
|
||||||
type Currency struct {
|
type Currency struct {
|
||||||
ID int `json:"id,omitempty"`
|
|
||||||
Code string `json:"code,omitempty"`
|
Code string `json:"code,omitempty"`
|
||||||
|
ID int `json:"id,omitempty"`
|
||||||
|
ManualConvertNominal int `json:"manualConvertNominal,omitempty"`
|
||||||
|
AutoConvertExtraPercent int `json:"autoConvertExtraPercent,omitempty"`
|
||||||
IsBase bool `json:"isBase,omitempty"`
|
IsBase bool `json:"isBase,omitempty"`
|
||||||
IsAutoConvert bool `json:"isAutoConvert,omitempty"`
|
IsAutoConvert bool `json:"isAutoConvert,omitempty"`
|
||||||
AutoConvertExtraPercent int `json:"autoConvertExtraPercent,omitempty"`
|
ManualConvertValue float32 `json:"manualConvertValue,omitempty"`
|
||||||
ManualConvertNominal int `json:"manualConvertNominal,omitempty"`
|
|
||||||
ManualConvertValue float64 `json:"manualConvertValue,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrdersStatus type.
|
// OrdersStatus type.
|
||||||
|
Loading…
Reference in New Issue
Block a user