-
Notifications
You must be signed in to change notification settings - Fork 0
/
number.go
66 lines (52 loc) · 1.28 KB
/
number.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 soumuradio
import (
"context"
"strconv"
"time"
"github.com/tomato3713/soumuradio/internal"
)
// getNumberAPI is Method for Number API
func (c *Client) getNumberAPI(ctx context.Context, opt NumOpts) (*internal.Num, error) {
spath := "/musen/num"
req, err := c.newRequest(ctx, "GET", spath, opt, nil)
if err != nil {
logf("try URL: %v", req.URL)
return nil, err
}
res, err := c.HTTPClient.Do(req)
if err != nil {
return nil, err
}
if err = checkStatusCode(res); err != nil {
return nil, err
}
var num internal.Num
if err := decodeBody(res, &num, nil); err != nil {
return nil, err
}
return &num, nil
}
// GetTotalCount is Method for getting number of radio
func (c *Client) GetTotalCount(ctx context.Context, opt NumOpts) (int, error) {
ret, err := c.getNumberAPI(ctx, opt)
if err != nil {
return 0, err
}
count, err := strconv.Atoi(ret.MusenInformation.TotalCount)
if err != nil {
return 0, err
}
return count, nil
}
func (c *Client) GetLastUpdateDate(ctx context.Context, opt NumOpts) (time.Time, error) {
ret, err := c.getNumberAPI(ctx, opt)
if err != nil {
return time.Time{}, err
}
layout := "2006-01-02"
date, err := time.Parse(layout, ret.MusenInformation.LastUpdateDate)
if err != nil {
return time.Time{}, err
}
return date, nil
}