diff --git a/api/market.go b/api/market.go index f78a068d..0bb35687 100644 --- a/api/market.go +++ b/api/market.go @@ -318,3 +318,19 @@ func (vk *VK) MarketSearch(params Params) (response MarketSearchResponse, err er err = vk.RequestUnmarshal("market.search", &response, params) return } + +// MarketSearchItemsResponse struct. +type MarketSearchItemsResponse struct { + Count int `json:"count"` + ViewType int `json:"view_type"` + Items []object.MarketMarketItem `json:"items"` + Groups []object.GroupsGroup `json:"groups,omitempty"` +} + +// MarketSearchItems method. +// +// https://vk.com/dev/market.searchItems +func (vk *VK) MarketSearchItems(params Params) (response MarketSearchItemsResponse, err error) { + err = vk.RequestUnmarshal("market.searchItems", &response, params) + return +} diff --git a/api/market_test.go b/api/market_test.go index f88f8e81..cab8960e 100644 --- a/api/market_test.go +++ b/api/market_test.go @@ -415,3 +415,17 @@ func TestVK_MarketSearch(t *testing.T) { assert.NotEmpty(t, res.Items[0].Reposts) } } + +func TestVK_MarketSearchItems(t *testing.T) { + t.Parallel() + + needUserToken(t) + + res, err := vkUser.MarketSearchItems(api.Params{ + "q": "test", + }) + + noError(t, err) + assert.NotEmpty(t, res.Count) + assert.NotEmpty(t, res.ViewType) +} diff --git a/api/params/market.go b/api/params/market.go index 59ff97a3..80615d8e 100644 --- a/api/params/market.go +++ b/api/params/market.go @@ -1261,3 +1261,63 @@ func (b *MarketSearchBuilder) NeedVariants(v bool) *MarketSearchBuilder { b.Params["need_variants"] = v return b } + +// MarketSearchItemsBuilder builder. +// +// https://vk.com/dev/market.searchItems +type MarketSearchItemsBuilder struct { + api.Params +} + +// NewMarketSearchItemsBuilder func. +func NewMarketSearchItemsBuilder() *MarketSearchItemsBuilder { + return &MarketSearchItemsBuilder{api.Params{}} +} + +// Q parameter. +func (b *MarketSearchItemsBuilder) Q(v string) *MarketSearchItemsBuilder { + b.Params["q"] = v + return b +} + +// Offset parameter. +func (b *MarketSearchItemsBuilder) Offset(v int) *MarketSearchItemsBuilder { + b.Params["offset"] = v + return b +} + +// Count parameter. +func (b *MarketSearchItemsBuilder) Count(v int) *MarketSearchItemsBuilder { + b.Params["count"] = v + return b +} + +// CategoryID parameter. +func (b *MarketSearchItemsBuilder) CategoryID(v int) *MarketSearchItemsBuilder { + b.Params["category_id"] = v + return b +} + +// PriceFrom parameter. +func (b *MarketSearchItemsBuilder) PriceFrom(v int) *MarketSearchItemsBuilder { + b.Params["price_from"] = v + return b +} + +// PriceTo parameter. +func (b *MarketSearchItemsBuilder) PriceTo(v int) *MarketSearchItemsBuilder { + b.Params["price_to"] = v + return b +} + +// SortBy parameter. +func (b *MarketSearchItemsBuilder) SortBy(v int) *MarketSearchItemsBuilder { + b.Params["sort_by"] = v + return b +} + +// SortDirection parameter. +func (b *MarketSearchItemsBuilder) SortDirection(v int) *MarketSearchItemsBuilder { + b.Params["sort_direction"] = v + return b +} diff --git a/api/params/market_test.go b/api/params/market_test.go index 40b0f987..4b6f660e 100644 --- a/api/params/market_test.go +++ b/api/params/market_test.go @@ -502,3 +502,27 @@ func TestMarketSearchBuilder(t *testing.T) { assert.Equal(t, b.Params["status"], 1) assert.Equal(t, b.Params["need_variants"], true) } + +func TestMarketSearchItemsBuilder(t *testing.T) { + t.Parallel() + + b := params.NewMarketSearchItemsBuilder() + + b.Q("text") + b.Offset(1) + b.Count(1) + b.CategoryID(1) + b.PriceFrom(1) + b.PriceTo(1) + b.SortBy(1) + b.SortDirection(1) + + assert.Equal(t, b.Params["q"], "text") + assert.Equal(t, b.Params["offset"], 1) + assert.Equal(t, b.Params["count"], 1) + assert.Equal(t, b.Params["category_id"], 1) + assert.Equal(t, b.Params["price_from"], 1) + assert.Equal(t, b.Params["price_to"], 1) + assert.Equal(t, b.Params["sort_by"], 1) + assert.Equal(t, b.Params["sort_direction"], 1) +}