mirror of
https://github.com/retailcrm/api-client-go.git
synced 2024-11-21 20:36:03 +03:00
add offers method
This commit is contained in:
parent
c9e5b1f79d
commit
2333dbf493
@ -79,7 +79,6 @@ linters-settings:
|
|||||||
- unmarshal
|
- unmarshal
|
||||||
- unreachable
|
- unreachable
|
||||||
- unsafeptr
|
- unsafeptr
|
||||||
- fieldalignment
|
|
||||||
settings:
|
settings:
|
||||||
printf:
|
printf:
|
||||||
funcs:
|
funcs:
|
||||||
|
23
client.go
23
client.go
@ -6907,3 +6907,26 @@ func (c *Client) EditMGChannelTemplate(req EditMGChannelTemplateRequest) (int, e
|
|||||||
|
|
||||||
return code, nil
|
return code, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) StoreOffers(req OffersRequest) (StoreOffersResponse, int, error) {
|
||||||
|
var result StoreOffersResponse
|
||||||
|
|
||||||
|
filter, err := query.Values(req)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return StoreOffersResponse{}, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, status, err := c.GetRequest(fmt.Sprintf("/store/offers?%s", filter.Encode()))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return StoreOffersResponse{}, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(resp, &result)
|
||||||
|
if err != nil {
|
||||||
|
return StoreOffersResponse{}, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, status, nil
|
||||||
|
}
|
||||||
|
@ -8332,3 +8332,39 @@ func TestClient_EditMGChannelTemplate(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, statuses[code])
|
assert.True(t, statuses[code])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClient_StoreOffers(t *testing.T) {
|
||||||
|
cl := client()
|
||||||
|
|
||||||
|
gock.New(cl.URL).
|
||||||
|
Get(prefix+"/store/offers").
|
||||||
|
MatchParam("filter[active]", "1").
|
||||||
|
MatchParam("filter[ids][]", "76").
|
||||||
|
Reply(http.StatusOK).
|
||||||
|
JSON(getStoreOfferResponse())
|
||||||
|
|
||||||
|
a := 1
|
||||||
|
f := OffersRequest{OffersFilter{Ids: []int{76}, Active: &a}}
|
||||||
|
|
||||||
|
resp, status, err := cl.StoreOffers(f)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !statuses[status] {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.Success != true {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Len(t, resp.Offers, 1)
|
||||||
|
assert.Equal(t, 76, resp.Offers[0].ID)
|
||||||
|
assert.Equal(t, "Название\nПеревод строки", resp.Offers[0].Name)
|
||||||
|
assert.Equal(t, 222, resp.Offers[0].Product.ID)
|
||||||
|
assert.Equal(t, "base", resp.Offers[0].Prices[0].PriceType)
|
||||||
|
assert.Equal(t, float32(10000), resp.Offers[0].Prices[0].Price)
|
||||||
|
assert.Equal(t, "RUB", resp.Offers[0].Prices[0].Currency)
|
||||||
|
}
|
||||||
|
@ -474,3 +474,8 @@ type LoyaltyAPIFilter struct {
|
|||||||
Ids []int `url:"ids,omitempty,brackets"`
|
Ids []int `url:"ids,omitempty,brackets"`
|
||||||
Sites []string `url:"sites,omitempty,brackets"`
|
Sites []string `url:"sites,omitempty,brackets"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OffersFilter struct {
|
||||||
|
Ids []int `url:"ids,omitempty,brackets"`
|
||||||
|
Active *int `url:"active,omitempty"`
|
||||||
|
}
|
||||||
|
@ -310,3 +310,7 @@ func (r ConnectRequest) Verify(secret string) bool {
|
|||||||
}
|
}
|
||||||
return hmac.Equal([]byte(r.Token), []byte(hex.EncodeToString(mac.Sum(nil))))
|
return hmac.Equal([]byte(r.Token), []byte(hex.EncodeToString(mac.Sum(nil))))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OffersRequest struct {
|
||||||
|
OffersFilter `url:"filter,omitempty"`
|
||||||
|
}
|
||||||
|
@ -685,3 +685,9 @@ type MGChannelTemplatesResponse struct {
|
|||||||
Templates []MGChannelTemplate `json:"templates"`
|
Templates []MGChannelTemplate `json:"templates"`
|
||||||
SuccessfulResponse
|
SuccessfulResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type StoreOffersResponse struct {
|
||||||
|
Pagination *Pagination `json:"pagination"`
|
||||||
|
SuccessfulResponse
|
||||||
|
Offers []Offer `json:"offers,omitempty"`
|
||||||
|
}
|
||||||
|
44
testutils.go
44
testutils.go
@ -519,3 +519,47 @@ func getMGTemplatesResponse() string {
|
|||||||
func getMGTemplatesForEdit() string {
|
func getMGTemplatesForEdit() string {
|
||||||
return `[{"header":{"text":{"parts":["Hello,",{"var":"custom"}],"example":["Henry"]},"document":{"example":"https://example.com/file/123.pdf"},"image":{"example":"https://example.com/file/123.png"},"video":{"example":"https://example.com/file/123.mp4"}},"lang":"en","category":"test_0","code":"namespace#name_0#ru","name":"name_0","namespace":"namespace","footer":"footer_0","verificationStatus":"REJECTED","template":["Text_0",{"var":"custom"}],"buttons":[{"type":"PHONE_NUMBER","text":"your-phone-button-text","phoneNumber":"+79895553535"},{"type":"QUICK_REPLY","text":"Yes"},{"type":"URL","url":"https://example.com/file/{{1}}","text":"button","example":["https://www.website.com/dynamic-url-example"]}],"templateExample":["WIU"],"id":1,"externalId":10,"mgChannelId":110,"active":true}]`
|
return `[{"header":{"text":{"parts":["Hello,",{"var":"custom"}],"example":["Henry"]},"document":{"example":"https://example.com/file/123.pdf"},"image":{"example":"https://example.com/file/123.png"},"video":{"example":"https://example.com/file/123.mp4"}},"lang":"en","category":"test_0","code":"namespace#name_0#ru","name":"name_0","namespace":"namespace","footer":"footer_0","verificationStatus":"REJECTED","template":["Text_0",{"var":"custom"}],"buttons":[{"type":"PHONE_NUMBER","text":"your-phone-button-text","phoneNumber":"+79895553535"},{"type":"QUICK_REPLY","text":"Yes"},{"type":"URL","url":"https://example.com/file/{{1}}","text":"button","example":["https://www.website.com/dynamic-url-example"]}],"templateExample":["WIU"],"id":1,"externalId":10,"mgChannelId":110,"active":true}]`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getStoreOfferResponse() string {
|
||||||
|
return `{
|
||||||
|
"success": true,
|
||||||
|
"pagination": {
|
||||||
|
"limit": 20,
|
||||||
|
"totalCount": 1,
|
||||||
|
"currentPage": 1,
|
||||||
|
"totalPageCount": 1
|
||||||
|
},
|
||||||
|
"offers": [
|
||||||
|
{
|
||||||
|
"images": [
|
||||||
|
"https://s3-s1.retailcrm.tech/ru-central1/retailcrm/dev-vega-d32aea7f9a5bc26eba6ad986077cea03/product/65a92fa0bb737-test.jpeg"
|
||||||
|
],
|
||||||
|
"id": 76,
|
||||||
|
"site": "main",
|
||||||
|
"name": "Название\nПеревод строки",
|
||||||
|
"article": "Артикул",
|
||||||
|
"product": {
|
||||||
|
"type": "product",
|
||||||
|
"catalogId": 2,
|
||||||
|
"id": 222
|
||||||
|
},
|
||||||
|
"prices": [
|
||||||
|
{
|
||||||
|
"priceType": "base",
|
||||||
|
"price": 10000,
|
||||||
|
"ordering": 991,
|
||||||
|
"currency": "RUB"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"purchasePrice": 10,
|
||||||
|
"quantity": 5,
|
||||||
|
"active": true,
|
||||||
|
"unit": {
|
||||||
|
"code": "pc",
|
||||||
|
"name": "Штука",
|
||||||
|
"sym": "шт."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
3
types.go
3
types.go
@ -598,6 +598,7 @@ type Offer struct {
|
|||||||
Prices []OfferPrice `json:"prices,omitempty"`
|
Prices []OfferPrice `json:"prices,omitempty"`
|
||||||
Images []string `json:"images,omitempty"`
|
Images []string `json:"images,omitempty"`
|
||||||
Unit *Unit `json:"unit,omitempty"`
|
Unit *Unit `json:"unit,omitempty"`
|
||||||
|
Product *Product `json:"product,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inventory type.
|
// Inventory type.
|
||||||
@ -1255,7 +1256,7 @@ type Action struct {
|
|||||||
// MgTransport type.
|
// MgTransport type.
|
||||||
type MgTransport struct {
|
type MgTransport struct {
|
||||||
WebhookURL string `json:"webhookUrl,omitempty"`
|
WebhookURL string `json:"webhookUrl,omitempty"`
|
||||||
RefreshToken bool `json:"refreshToken,omitempty"`
|
RefreshToken bool `json:"refreshToken,omitempty"`
|
||||||
Actions *MgTransportActions `json:"actions,omitempty"`
|
Actions *MgTransportActions `json:"actions,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user