-
Notifications
You must be signed in to change notification settings - Fork 2
/
register.go
58 lines (50 loc) · 1.37 KB
/
register.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
package main
import (
"fmt"
"net"
"os"
"github.com/dstotijn/go-bunq"
)
func main() {
client := bunq.NewClient()
client.APIKey = os.Getenv("BUNQ_API_KEY")
client.BaseURL = "https://sandbox.public.api.bunq.com"
file, err := os.Open("/Users/david/.keys/bunq.key")
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
if err := client.SetPrivateKey(file); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("* Creating installation...\n\n")
installation, err := client.CreateInstallation()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("Created installation: %#v\n", installation)
fmt.Printf("\n* Creating DeviceServer...\n\n")
client.Token = installation.Token.Token
deviceServer, err := client.CreateDeviceServer("Foobar", []net.IP{})
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("Created DeviceServer: %#v\n", deviceServer)
fmt.Printf("\n* Getting DeviceServer...\n\n")
deviceServer, err = client.GetDeviceServer(deviceServer.ID)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("Retrieved DeviceServer: %#v\n", deviceServer)
fmt.Printf("\n* Creating Session...\n\n")
session, err := client.CreateSession()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("Created Session: %#v\n", session)
}