From 049a5c68c75ee6f72015409a7b54a56bd1af679d Mon Sep 17 00:00:00 2001 From: Suvorov Daniil Date: Sun, 23 Aug 2020 22:33:28 +0300 Subject: [PATCH 1/7] feat: add store.getProducts method --- api/store.go | 36 +++++++++++++++++++++++++++++++++++ api/store_test.go | 48 +++++++++++++++++++++++++++++++++++++++++++++++ object/object.go | 6 +++--- object/store.go | 28 +++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 object/store.go diff --git a/api/store.go b/api/store.go index a2df4ca0..da6abc52 100644 --- a/api/store.go +++ b/api/store.go @@ -33,3 +33,39 @@ func (vk *VK) StoreRemoveStickersFromFavorite(params Params) (response int, err err = vk.RequestUnmarshal("store.removeStickersFromFavorite", &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 +} diff --git a/api/store_test.go b/api/store_test.go index e6a70c4e..293226a8 100644 --- a/api/store_test.go +++ b/api/store_test.go @@ -28,3 +28,51 @@ 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_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..e720e6a9 --- /dev/null +++ b/object/store.go @@ -0,0 +1,28 @@ +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"` +} From b17f961ca67f21e3a6068e62332521eb8b11fbba Mon Sep 17 00:00:00 2001 From: Suvorov Daniil Date: Sun, 23 Aug 2020 23:02:40 +0300 Subject: [PATCH 2/7] feat: add store.activateProduct method --- api/store.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/store.go b/api/store.go index da6abc52..f48c1707 100644 --- a/api/store.go +++ b/api/store.go @@ -34,6 +34,14 @@ func (vk *VK) StoreRemoveStickersFromFavorite(params Params) (response int, err 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 +} + // StoreGetProductsResponse struct. type StoreGetProductsResponse struct { Count int `json:"count"` From bd3b89a2426df9bb56f41d118a139b98c075163e Mon Sep 17 00:00:00 2001 From: Suvorov Daniil Date: Sun, 23 Aug 2020 23:03:34 +0300 Subject: [PATCH 3/7] feat: add store.deactivateProduct method --- api/store.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/store.go b/api/store.go index f48c1707..7c14741d 100644 --- a/api/store.go +++ b/api/store.go @@ -42,6 +42,14 @@ func (vk *VK) StoreActivateProduct(params Params) (response int, err error) { 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"` From 50330828c2e377f19ac38ae14b1c9433dedb0695 Mon Sep 17 00:00:00 2001 From: Suvorov Daniil Date: Sun, 23 Aug 2020 23:03:56 +0300 Subject: [PATCH 4/7] feat: add store.markAsViewed method --- api/store.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/store.go b/api/store.go index 7c14741d..3219b038 100644 --- a/api/store.go +++ b/api/store.go @@ -85,3 +85,11 @@ func (vk *VK) StoreGetProductsExtended(params Params) (response StoreGetProducts 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 +} From 04fa4678791616f85dbba8c14b3bd16f012b95f7 Mon Sep 17 00:00:00 2001 From: Suvorov Daniil Date: Sun, 23 Aug 2020 23:04:36 +0300 Subject: [PATCH 5/7] feat: add store.reorderProducts method --- api/store.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/store.go b/api/store.go index 3219b038..341c7fee 100644 --- a/api/store.go +++ b/api/store.go @@ -93,3 +93,11 @@ 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 +} From 773188ed63b285073e20b7f4dc503df4552e89ba Mon Sep 17 00:00:00 2001 From: Suvorov Daniil Date: Mon, 24 Aug 2020 00:04:29 +0300 Subject: [PATCH 6/7] feat: add store.getStickers method --- api/store.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/api/store.go b/api/store.go index 341c7fee..7c4eacd5 100644 --- a/api/store.go +++ b/api/store.go @@ -86,6 +86,17 @@ func (vk *VK) StoreGetProductsExtended(params Params) (response StoreGetProducts 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 +} + // StoreMarkAsViewed method. // // https://vk.com/dev/store.markAsViewed From ecaf61447b821945acff08407ae7d7a18dc60f06 Mon Sep 17 00:00:00 2001 From: Suvorov Daniil Date: Wed, 12 Jan 2022 02:26:35 +0300 Subject: [PATCH 7/7] feat: add store.getStickersKeywords method --- api/store.go | 14 ++++++++++++++ api/store_test.go | 25 +++++++++++++++++++++++++ object/store.go | 14 ++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/api/store.go b/api/store.go index 7c4eacd5..bdcaeaad 100644 --- a/api/store.go +++ b/api/store.go @@ -97,6 +97,20 @@ func (vk *VK) StoreGetStickers(params Params) (response StoreGetStickersResponse 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 diff --git a/api/store_test.go b/api/store_test.go index 293226a8..e883fb0d 100644 --- a/api/store_test.go +++ b/api/store_test.go @@ -51,6 +51,31 @@ func TestVK_StoreGetProducts(t *testing.T) { } } +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() diff --git a/object/store.go b/object/store.go index e720e6a9..5786505e 100644 --- a/object/store.go +++ b/object/store.go @@ -26,3 +26,17 @@ type StoreProductExtended struct { 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"` +}