-
Notifications
You must be signed in to change notification settings - Fork 6
/
client_test.go
102 lines (95 loc) · 2.61 KB
/
client_test.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package client
import (
"context"
"github.com/dreampuf/evernote-sdk-golang/edam"
"os"
"testing"
"time"
)
var (
yes = true
EvernoteKey = os.Getenv("KEY")
EvernoteSecret = os.Getenv("SECRET")
EvernoteAuthorToken = os.Getenv("TOKEN")
)
func TestClient(t *testing.T) {
ctx, _ := context.WithTimeout(context.Background(), time.Duration(15) * time.Second)
c := NewClient(EvernoteKey, EvernoteSecret, SANDBOX)
us, err := c.GetUserStore()
if err != nil {
t.Fatal(err)
}
userUrls, err := us.GetUserUrls(ctx, EvernoteAuthorToken)
if err != nil {
t.Fatal(err)
}
ns, err := c.GetNoteStoreWithURL(userUrls.GetNoteStoreUrl())
if err != nil {
t.Fatal(err)
}
notebook, err := ns.GetDefaultNotebook(ctx, EvernoteAuthorToken)
if err != nil {
t.Fatal(err)
}
if notebook == nil {
t.Fatal("Invalid Note")
}
// optional tag filter
filterTags := []edam.GUID{}
tags, err := ns.ListTags(ctx, EvernoteAuthorToken)
if err != nil {
t.Fatal(err)
}
for _, tag := range tags {
filterTags = append(filterTags, tag.GetGUID())
}
noteMetadataList, err := ns.FindNotesMetadata(ctx, EvernoteAuthorToken, &edam.NoteFilter{
//Ascending: &yes,
//TagGuids: filterTags,
}, 0, 1000, &edam.NotesMetadataResultSpec{
IncludeTitle: &yes,
IncludeContentLength: &yes,
IncludeCreated: &yes,
IncludeUpdated: &yes,
IncludeTagGuids: &yes,
})
if err != nil {
t.Fatal(err)
}
t.Logf("total note: %d\n", noteMetadataList.GetTotalNotes())
for n, noteMate := range noteMetadataList.GetNotes() {
t.Logf("%d - %s - %s\n", n, time.Unix(int64(noteMate.GetCreated())/1000, 0), noteMate.GetTitle())
}
}
func TestRequestToken(t *testing.T) {
/*
PRODUCTION: evernote production
SANDBOX: evernote sandbox
YINXIANG: yinxiangbiji
YINXIANGSANDBOX: yinxiangbiji sandbox
*/
c := NewClient(EvernoteKey, EvernoteSecret, SANDBOX)
callBackURL := "http://YOUR_SERVER_CALL_BACK_URL"
requestToken, url, err := c.GetRequestToken(callBackURL)
if err != nil {
t.Fatal(err)
}
if requestToken == nil {
t.Fatal("Failed token request")
}
if len(url) < 1 {
t.Fatal("Invalid URL")
}
// in the call back handler
// if you are using gin-gonic https://github.com/gin-gonic/gin
oauthToken := "OAUTH_TOKEN" // c.Query("oauth_token")
oauthVerifier := "OAUTH_VERIFIER" // c.Query("oauth_verifier")
_ = oauthToken
accessToken, err := c.GetAuthorizedToken(requestToken, oauthVerifier)
if err == nil {
us, _ := c.GetUserStore()
userUrls, _ := us.GetUserUrls(context.Background(), accessToken.Token)
// ... referring the test case of TestClient
_ = userUrls
}
}