-
Notifications
You must be signed in to change notification settings - Fork 8
/
folder.go
61 lines (50 loc) · 1.54 KB
/
folder.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
package nylas
import (
"context"
"net/http"
"github.com/google/go-querystring/query"
)
// Folder represents a folder in the Nylas system.
type Folder struct {
ID string `json:"id"`
Object string `json:"object"`
AccountID string `json:"account_id"`
// Localized name of the folder
DisplayName string `json:"display_name"`
// Standard categories type, based on RFC-6154, can be one of the
// Mailbox* constants, e.g MailboxInbox or empty if user created.
// See: https://tools.ietf.org/html/rfc6154
Name string `json:"name"`
}
// FoldersOptions provides optional parameters to the Folders method.
type FoldersOptions struct {
Limit int `url:"limit,omitempty"`
Offset int `url:"offset,omitempty"`
}
// Folders returns folders which match the filter specified by parameters.
// See: https://docs.nylas.com/reference#get-folders
func (c *Client) Folders(ctx context.Context, opts *FoldersOptions) ([]Folder, error) {
req, err := c.newUserRequest(ctx, http.MethodGet, "/folders", nil)
if err != nil {
return nil, err
}
if opts != nil {
vs, err := query.Values(opts)
if err != nil {
return nil, err
}
appendQueryValues(req, vs)
}
var resp []Folder
return resp, c.do(req, &resp)
}
// FoldersCount returns the count of folders.
// See: https://docs.nylas.com/reference#get-folders
func (c *Client) FoldersCount(ctx context.Context) (int, error) {
req, err := c.newUserRequest(ctx, http.MethodGet, "/folders?view=count", nil)
if err != nil {
return 0, err
}
var resp countResponse
return resp.Count, c.do(req, &resp)
}