Skip to content

Commit

Permalink
feat: add MarketSearchItems method
Browse files Browse the repository at this point in the history
  • Loading branch information
SevereCloud committed Dec 10, 2021
1 parent d5e8995 commit dbfcef5
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
16 changes: 16 additions & 0 deletions api/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
14 changes: 14 additions & 0 deletions api/market_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
60 changes: 60 additions & 0 deletions api/params/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
24 changes: 24 additions & 0 deletions api/params/market_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit dbfcef5

Please sign in to comment.