-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (38 loc) · 951 Bytes
/
main.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
package main
import (
"fmt"
"os"
)
const apiHostname = "api.monzo.com"
func main() {
if err := run(); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
}
func run() error {
client := NewClient()
if client.id == "" || client.secret == "" {
return fmt.Errorf("the Client ID and Client secret were not found in env vars")
}
if client.accessToken == "" || client.refreshToken == "" {
err := oauth(client)
if err != nil {
return err
}
os.Setenv("MONZO_ACCESS_TOKEN", client.accessToken)
os.Setenv("MONZO_REFRESH_TOKEN", client.refreshToken)
}
err := pingTest(client)
if err != nil {
return err
}
fmt.Printf("Please open your Monzo app, click \"Allow access to your data\" for your application, and follow the instructions.\nOnce approved, press [Enter] to continue:\n")
fmt.Scanln()
// Example API call after SCA authentication
err = accounts(client)
if err != nil {
return err
}
return nil
}