forked from strava/go.strava
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kudos.go
88 lines (69 loc) · 1.97 KB
/
kudos.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package strava
import (
"encoding/json"
"fmt"
)
type ActivityKudosService struct {
client *Client
activityId int64
}
func NewActivityKudosService(client *Client, activityId int64) *ActivityKudosService {
return &ActivityKudosService{client: client, activityId: activityId}
}
/*********************************************************/
type ActivityKudosListCall struct {
service *ActivityKudosService
ops map[string]interface{}
}
func (s *ActivityKudosService) List() *ActivityKudosListCall {
return &ActivityKudosListCall{
service: s,
ops: make(map[string]interface{}),
}
}
func (c *ActivityKudosListCall) Page(page int) *ActivityKudosListCall {
c.ops["page"] = page
return c
}
func (c *ActivityKudosListCall) PerPage(perPage int) *ActivityKudosListCall {
c.ops["per_page"] = perPage
return c
}
func (c *ActivityKudosListCall) Do() ([]*AthleteSummary, error) {
data, err := c.service.client.run("GET", fmt.Sprintf("/activities/%d/kudos", c.service.activityId), c.ops)
if err != nil {
return nil, err
}
kudoers := make([]*AthleteSummary, 0)
err = json.Unmarshal(data, &kudoers)
if err != nil {
return nil, err
}
return kudoers, nil
}
/*********************************************************/
type ActivityKudosPostCall struct {
service *ActivityKudosService
}
func (s *ActivityKudosService) Create() *ActivityKudosPostCall {
return &ActivityKudosPostCall{
service: s,
}
}
func (c *ActivityKudosPostCall) Do() error {
_, err := c.service.client.run("POST", fmt.Sprintf("/activities/%d/kudos", c.service.activityId), nil)
return err
}
/*********************************************************/
type ActivityKudosDeleteCall struct {
service *ActivityKudosService
}
func (s *ActivityKudosService) Delete() *ActivityKudosDeleteCall {
return &ActivityKudosDeleteCall{
service: s,
}
}
func (c *ActivityKudosDeleteCall) Do() error {
_, err := c.service.client.run("DELETE", fmt.Sprintf("/activities/%d/kudos", c.service.activityId), nil)
return err
}