diff --git a/api/store.go b/api/store.go index a2df4ca0..bdcaeaad 100644 --- a/api/store.go +++ b/api/store.go @@ -33,3 +33,96 @@ func (vk *VK) StoreRemoveStickersFromFavorite(params Params) (response int, err err = vk.RequestUnmarshal("store.removeStickersFromFavorite", &response, params) return } + +// StoreActivateProduct method. +// +// https://vk.com/dev/store.activateProduct +func (vk *VK) StoreActivateProduct(params Params) (response int, err error) { + err = vk.RequestUnmarshal("store.activateProduct", &response, params) + return +} + +// StoreDeactivateProduct method. +// +// https://vk.com/dev/store.deactivateProduct +func (vk *VK) StoreDeactivateProduct(params Params) (response int, err error) { + err = vk.RequestUnmarshal("store.deactivateProduct", &response, params) + return +} + +// StoreGetProductsResponse struct. +type StoreGetProductsResponse struct { + Count int `json:"count"` + Items []object.StoreProduct `json:"items"` +} + +// StoreGetProducts method. +// +// extended=0 +// +// https://vk.com/dev/store.getProducts +func (vk *VK) StoreGetProducts(params Params) (response StoreGetProductsResponse, err error) { + params["extended"] = false + err = vk.RequestUnmarshal("store.getProducts", &response, params) + + return +} + +// StoreGetProductsExtendedResponse struct. +type StoreGetProductsExtendedResponse struct { + Count int `json:"count"` + Items []object.StoreProductExtended `json:"items"` +} + +// StoreGetProductsExtended method. +// +// extended=1 +// +// https://vk.com/dev/store.getProducts +func (vk *VK) StoreGetProductsExtended(params Params) (response StoreGetProductsExtendedResponse, err error) { + params["extended"] = true + err = vk.RequestUnmarshal("store.getProducts", &response, params) + + return +} + +// StoreGetStickersResponse struct. +type StoreGetStickersResponse []object.BaseSticker + +// StoreGetStickers method. +// +// https://vk.com/dev/store.getStickers +func (vk *VK) StoreGetStickers(params Params) (response StoreGetStickersResponse, err error) { + err = vk.RequestUnmarshal("store.getStickers", &response, params) + return +} + +// StoreGetStickersKeywordsResponse struct. +type StoreGetStickersKeywordsResponse struct { + Count int `json:"count"` + Dictionary []object.StoreStickersDictionary `json:"dictionary"` +} + +// StoreGetStickersKeywords method. +// +// https://vk.com/dev/store.getStickersKeywords +func (vk *VK) StoreGetStickersKeywords(params Params) (response StoreGetStickersKeywordsResponse, err error) { + err = vk.RequestUnmarshal("store.getStickersKeywords", &response, params) + return +} + +// StoreMarkAsViewed method. +// +// https://vk.com/dev/store.markAsViewed +func (vk *VK) StoreMarkAsViewed(params Params) (response int, err error) { + err = vk.RequestUnmarshal("store.markAsViewed", &response, params) + return +} + +// StoreReorderProducts method. +// +// https://vk.com/dev/store.reorderProducts +func (vk *VK) StoreReorderProducts(params Params) (response int, err error) { + err = vk.RequestUnmarshal("store.reorderProducts", &response, params) + return +} diff --git a/api/store_test.go b/api/store_test.go index e6a70c4e..e883fb0d 100644 --- a/api/store_test.go +++ b/api/store_test.go @@ -28,3 +28,76 @@ func TestVK_StoreGetFavoriteStickers(t *testing.T) { }) noError(t, err) } + +func TestVK_StoreGetProducts(t *testing.T) { + t.Parallel() + + needUserToken(t) + + products, err := vkUser.StoreGetProducts(api.Params{ + "type": "stickers", + "filters": "active", + }) + noError(t, err) + + assert.NotEmpty(t, products.Count) + + if assert.NotEmpty(t, products.Items) { + assert.NotEmpty(t, products.Items[0].ID) + assert.NotEmpty(t, products.Items[0].Type) + assert.NotEmpty(t, products.Items[0].Purchased) + assert.NotEmpty(t, products.Items[0].Active) + assert.NotEmpty(t, products.Items[0].PurchaseDate) + } +} + +func TestVK_StoreStoreGetStickersKeywords(t *testing.T) { + t.Parallel() + + needUserToken(t) + + f := func(p api.Params) { + t.Helper() + + products, err := vkUser.StoreGetStickersKeywords(p) + noError(t, err) + + assert.NotEmpty(t, products.Count) + assert.NotEmpty(t, products.Dictionary) + } + + f(api.Params{ + "all_products": true, + "need_stickers": true, + }) + f(api.Params{ + "all_products": true, + "need_stickers": false, + }) +} + +func TestVK_StoreGetProductsExtended(t *testing.T) { + t.Parallel() + + needUserToken(t) + + products, err := vkUser.StoreGetProductsExtended(api.Params{ + "type": "stickers", + "filters": "active", + }) + noError(t, err) + + assert.NotEmpty(t, products.Count) + + if assert.NotEmpty(t, products.Items) { + assert.NotEmpty(t, products.Items[0].ID) + assert.NotEmpty(t, products.Items[0].Type) + assert.NotEmpty(t, products.Items[0].Purchased) + assert.NotEmpty(t, products.Items[0].Active) + assert.NotEmpty(t, products.Items[0].PurchaseDate) + assert.NotEmpty(t, products.Items[0].Title) + assert.NotEmpty(t, products.Items[0].Stickers) + assert.NotEmpty(t, products.Items[0].Icon) + assert.NotEmpty(t, products.Items[0].Previews) + } +} diff --git a/object/object.go b/object/object.go index e6c89efd..c1846bce 100644 --- a/object/object.go +++ b/object/object.go @@ -260,10 +260,10 @@ type BaseRepostsInfo struct { type BaseSticker struct { Images []BaseImage `json:"images"` ImagesWithBackground []BaseImage `json:"images_with_background"` - ProductID int `json:"product_id"` + ProductID int `json:"product_id,omitempty"` StickerID int `json:"sticker_id"` - IsAllowed bool `json:"is_allowed"` - AnimationURL string `json:"animation_url"` + IsAllowed BaseBoolInt `json:"is_allowed,omitempty"` + AnimationURL string `json:"animation_url,omitempty"` } // MaxSize return the largest BaseSticker. diff --git a/object/store.go b/object/store.go new file mode 100644 index 00000000..5786505e --- /dev/null +++ b/object/store.go @@ -0,0 +1,42 @@ +package object + +// StoreProductType type. +type StoreProductType string + +// Possible values. +const ( + StoreProductStickers StoreProductType = "stickers" +) + +// StoreProduct struct. +type StoreProduct struct { + ID int `json:"id"` + Type string `json:"type"` + Purchased BaseBoolInt `json:"purchased"` + Active BaseBoolInt `json:"active"` + PurchaseDate int `json:"purchase_date,omitempty"` +} + +// StoreProductExtended struct. +type StoreProductExtended struct { + StoreProduct + Title string `json:"title"` + Stickers []BaseSticker `json:"stickers"` + Icon []BaseImage `json:"icon"` + Previews []BaseImage `json:"previews"` + HasAnimation BaseBoolInt `json:"has_animation"` +} + +// StoreStickersDictionary struct. +type StoreStickersDictionary struct { + Words []string `json:"words"` + UserStickers []BaseSticker `json:"user_stickers,omitempty"` + PromotedStickers []BaseSticker `json:"promoted_stickers,omitempty"` // all_products=1 + Stickers []StoreSticker `json:"sticker,omitempty"` // need_stickers=0 +} + +// StoreSticker struct. +type StoreSticker struct { + PackID int `json:"pack_id"` + StickerID int `json:"sticker_id"` +}