-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
78 lines (67 loc) · 1.94 KB
/
example_test.go
File metadata and controls
78 lines (67 loc) · 1.94 KB
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
75
76
77
78
package jmap_test
import (
"encoding/json"
"fmt"
jmap "github.com/rhyselsmore/go-jmap"
)
func ExampleNewBearerTokenAuthenticator() {
authn, err := jmap.NewBearerTokenAuthenticator("my-token")
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println(authn != nil)
// Output: true
}
func ExampleGetCapabilities() {
sess := jmap.Session{
Capabilities: map[jmap.Capability]json.RawMessage{
"urn:ietf:params:jmap:core": json.RawMessage(`{"maxSizeUpload":50000000}`),
},
}
type CoreCapability struct {
MaxSizeUpload int `json:"maxSizeUpload"`
}
cap, err := jmap.GetCapabilities[CoreCapability](sess, "urn:ietf:params:jmap:core")
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println(cap.MaxSizeUpload)
// Output: 50000000
}
func ExampleNewStaticResolver() {
r, err := jmap.NewStaticResolver("https://api.fastmail.com")
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println(r != nil)
// Output: true
}
func ExampleNewRequest() {
req := jmap.NewRequest("urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail")
data, err := json.Marshal(req)
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println(string(data))
// Output: {"using":["urn:ietf:params:jmap:core","urn:ietf:params:jmap:mail"],"methodCalls":[]}
}
func ExampleRef() {
// Ref creates a back-reference to use the output of one method call
// as input to another within the same request.
inv := &exampleInvocation{name: "Mailbox/query", id: "c1"}
ref := jmap.Ref(inv, "/ids/*")
fmt.Println(ref.ResultOf, ref.Name, ref.Path)
// Output: c1 Mailbox/query /ids/*
}
// exampleInvocation implements jmap.Invocation for examples.
type exampleInvocation struct {
name string
id string
}
func (e *exampleInvocation) Name() string { return e.name }
func (e *exampleInvocation) ID() string { return e.id }
func (e *exampleInvocation) DecodeResponse(_ json.RawMessage) error { return nil }