-
Notifications
You must be signed in to change notification settings - Fork 0
/
tips.go
66 lines (57 loc) · 1.59 KB
/
tips.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package gaudius
import (
"fmt"
"github.com/alecsavvy/gaudius/gen/discovery/models"
)
type GetTipsParams struct {
offset *bool
limit *uint64
user_id *string
receiver_min_followers *uint64
receiver_is_verified *bool
current_user_follows *string
unique_by *string
}
func (g *GetTipsParams) IntoQueryString() string {
var queryString string
if g.offset != nil {
queryString += fmt.Sprintf("offset=%t&", *g.offset)
}
if g.limit != nil {
queryString += fmt.Sprintf("limit=%d&", *g.limit)
}
if g.user_id != nil {
queryString += fmt.Sprintf("user_id=%s&", *g.user_id)
}
if g.receiver_min_followers != nil {
queryString += fmt.Sprintf("receiver_min_followers=%d&", *g.receiver_min_followers)
}
if g.receiver_is_verified != nil {
queryString += fmt.Sprintf("receiver_is_verified=%t&", *g.receiver_is_verified)
}
if g.current_user_follows != nil {
queryString += fmt.Sprintf("current_user_follows=%s&", *g.current_user_follows)
}
if g.unique_by != nil {
queryString += fmt.Sprintf("unique_by=%s&", *g.unique_by)
}
// Remove the trailing '&' if it exists
if len(queryString) > 0 {
queryString = queryString[:len(queryString)-1]
}
return queryString
}
func (sdk *AudiusSdk) GetTips(params GetTipsParams) ([]*models.Tip, error) {
dn := sdk.Discovery
qs := params.IntoQueryString()
res, err := dn.discoveryClient.R().Get(fmt.Sprintf("/tips?%s", qs))
if err != nil {
return nil, err
}
var resp models.GetTipsResponse
err = resp.UnmarshalBinary(res.Body())
if err != nil {
return nil, err
}
return resp.Data, nil
}