evernote-sdk-golang

module
v0.0.0-...-d2ad936 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2020 License: MIT

README

Evernote SDK Golang

Unofficial SDK for Evernote. According official Evernote-thrift 1.29

Installation

go get -u github.com/dreampuf/evernote-sdk-golang/...

Example

  1. Apply your evernote developer key and developer token (an oauth access token for simply testing). More information: https://dev.evernote.com/doc/
  2. Clone the library
    $ git clone https://github.com/dreampuf/evernote-sdk-golang.git
    
  3. Run the test cases with your credentials
$ cd evernote-sdk-golang
$ KEY=YOUR_KEY SECRET=YOUR_SECRET TOKEN="YOUR_DEVERLOPER_TOKEN" go test ./...
ok  	github.com/dreampuf/evernote-sdk-golang/client	1.556s
?   	github.com/dreampuf/evernote-sdk-golang/edam	[no test files]
?   	github.com/dreampuf/evernote-sdk-golang/edam/note_store-remote	[no test files]
?   	github.com/dreampuf/evernote-sdk-golang/edam/user_store-remote	[no test files]

As a library

Referring to client_test.go

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())
}

How to generate code step by step

  1. Install the latest Thrift. (brew install thrift if you are using MacOS)

  2. Clone evernote-thrift repo https://github.com/evernote/evernote-thrift

  3. Generate golang version specs through this command:

    thrift -strict -nowarn \
      --allow-64bit-consts \
      --allow-neg-keys \
      --gen go:package_prefix=github.com/dreampuf/evernote-sdk-golang/,thrift_import=github.com/apache/thrift/lib/thrift \
      -strict -nowarn --allow-64bit-consts \
      --allow-neg-keys \
      --gen go:package_prefix=github.com/dreampuf/evernote-sdk-golang/,thrift_import=github.com/apache/thrift/lib/go/thrift \
      -I src/ -r \
      --out github.com/dreampuf/evernote-sdk-golang src/UserStore.thrift
    
  4. There are some minor type convert issues you need to do a manually fix. I found Evernote internally has a Golang version SDK and here is what their suggestion.

License

MIT

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL