Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store методы #131

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions api/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
73 changes: 73 additions & 0 deletions api/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
6 changes: 3 additions & 3 deletions object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
42 changes: 42 additions & 0 deletions object/store.go
Original file line number Diff line number Diff line change
@@ -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"`
}