-
Notifications
You must be signed in to change notification settings - Fork 1
/
tb.go
54 lines (41 loc) · 908 Bytes
/
tb.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
package main
import (
"log"
"net/http"
"net/url"
"time"
)
func (app *Application) getTBs(language string) []TB {
tbURL := app.BaseURL + "tbs?"
params := url.Values{}
params.Add("authToken", app.AccessToken)
if language != "" {
params.Add("lang", language)
}
tbURL += params.Encode()
var results []TB
resp, err := getQuery(tbURL)
if err != nil {
log.Println(err)
return results
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusUnauthorized {
time.Sleep(app.Delay)
status, err := app.login()
if !status || err != nil {
log.Printf("Couldn't log in: %s", err)
return results
}
return app.getTBs(language)
}
if resp.StatusCode != http.StatusOK {
log.Printf("Problem getting TBs (%s)!", resp.Status)
return results
}
err = jsonDecoder(resp.Body, &results)
if err != nil {
log.Printf("Error decoding TB results: %s", err)
}
return results
}