-
Notifications
You must be signed in to change notification settings - Fork 1
/
offers.go
45 lines (35 loc) Β· 968 Bytes
/
offers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package api
import (
"fmt"
"net/url"
"github.com/botscommunity/vkgo/internal/pkg/responses"
"github.com/botscommunity/vkgo/types"
)
func (bot *Bot) GetOffers(properties ...any) (count int, offers []int, err *responses.Error) {
query, offset := make(url.Values), false
for _, property := range properties {
switch property := property.(type) {
case types.Offers:
if property.Offset != 0 {
query.Set("offset", fmt.Sprint(property.Offset))
offset = true
}
if property.Count != 0 {
query.Set("count", fmt.Sprint(property.Count))
}
case int:
if !offset {
query.Set("offset", fmt.Sprint(property))
offset = true
} else {
query.Set("count", fmt.Sprint(property))
}
}
}
reply := responses.OffersReply{}
err = responses.NewInternalError(bot.Call("account.getActiveOffers", query.Encode(), &reply))
if reply.Error != nil {
err = reply.Error
}
return reply.Response.Count, reply.Response.Offers, err
}