forked from Teamwork/nylas-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
label.go
61 lines (50 loc) · 1.52 KB
/
label.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"
)
// Label represents a label in the Nylas system.
type Label struct {
ID string `json:"id"`
Object string `json:"object"`
AccountID string `json:"account_id"`
// Localized name of the label
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"`
}
// LabelsOptions provides optional parameters to the Labels method.
type LabelsOptions struct {
Limit int `url:"limit,omitempty"`
Offset int `url:"offset,omitempty"`
}
// Labels returns labels which match the filter specified by parameters.
// See: https://docs.nylas.com/reference#get-labels
func (c *Client) Labels(ctx context.Context, opts *LabelsOptions) ([]Label, error) {
req, err := c.newUserRequest(ctx, http.MethodGet, "/labels", 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 []Label
return resp, c.do(req, &resp)
}
// LabelsCount returns the count of labels.
// See: https://docs.nylas.com/reference#get-labels
func (c *Client) LabelsCount(ctx context.Context) (int, error) {
req, err := c.newUserRequest(ctx, http.MethodGet, "/labels?view=count", nil)
if err != nil {
return 0, err
}
var resp countResponse
return resp.Count, c.do(req, &resp)
}