-
Notifications
You must be signed in to change notification settings - Fork 4
/
recentaction.go
49 lines (42 loc) · 1.07 KB
/
recentaction.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
package goforces
import (
"context"
"fmt"
"net/url"
"strconv"
)
//RecentAction represents Codeforces RecentAction
type RecentAction struct {
TimeSeconds int `json:"timeSeconds"`
BlogEntry BlogEntry `json:"blogEntry"`
Comment Comment `json:"comment,omitempty"`
}
//GetRecentActions implements /recentActions
func (c *Client) GetRecentActions(ctx context.Context, maxCount int) ([]RecentAction, error) {
c.Logger.Println("GetRecentActions :", maxCount)
v := url.Values{}
//check options
v.Add("maxCount", strconv.Itoa(maxCount))
spath := "/recentActions" + "?" + v.Encode()
req, err := c.newRequest(ctx, "GET", spath, nil, nil)
if err != nil {
return nil, err
}
res, err := c.HTTPClient.Do(req)
if err != nil {
return nil, err
}
type Response struct {
Status string `json:"status"`
Result []RecentAction `json:"result"`
}
var resp Response
if err := decodeBody(res, &resp); err != nil {
return nil, err
}
//check status
if resp.Status != "OK" {
return nil, fmt.Errorf("Status Error : %s", resp.Status)
}
return resp.Result, nil
}