/
api.go
74 lines (68 loc) · 1.76 KB
/
api.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
package main
import (
"encoding/json"
"net/http"
"strings"
"github.com/0xAX/notificator"
)
type fipAPIType struct {
Current struct {
Emission struct {
Starttime int `json:"startTime"`
Endtime int `json:"endTime"`
ID string `json:"id"`
Titre string `json:"titre"`
Visuel struct {
Small string `json:"small"`
} `json:"visuel"`
Lien string `json:"lien"`
} `json:"emission"`
songAPIType `json:"song"`
} `json:"current"`
Previous2 struct {
songAPIType `json:"song"`
} `json:"previous2"`
Previous1 struct {
songAPIType `json:"song"`
} `json:"previous1"`
Next1 struct {
songAPIType `json:"song"`
} `json:"next1"`
Next2 struct {
songAPIType `json:"song"`
} `json:"next2"`
}
type songAPIType struct {
Starttime int `json:"startTime"`
Endtime int `json:"endTime"`
ID string `json:"id"`
Titre string `json:"titre"`
Titrealbum string `json:"titreAlbum"`
Interpretemorceau string `json:"interpreteMorceau"`
Anneeeditionmusique string `json:"anneeEditionMusique"`
Label string `json:"label"`
Visuel struct {
Small string `json:"small"`
Medium string `json:"medium"`
} `json:"visuel"`
Lien string `json:"lien"`
}
func (s *songAPIType) push(nt *notificator.Notificator) {
title := strings.Title(strings.ToLower(s.Titre))
artist := strings.Title(strings.ToLower(s.Interpretemorceau))
album := strings.Title(strings.ToLower(s.Titrealbum))
nt.Push(title, artist+" ("+album+")", "")
}
func fetchLatest() (current fipAPIType, err error) {
res, err := http.Get(fipURL)
if err != nil {
return
}
defer res.Body.Close()
dec := json.NewDecoder(res.Body)
err = dec.Decode(¤t)
if err != nil {
return
}
return
}