This repository was archived by the owner on Dec 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmonday.go
More file actions
93 lines (83 loc) · 1.88 KB
/
monday.go
File metadata and controls
93 lines (83 loc) · 1.88 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package monday
import (
"context"
"fmt"
"net/http"
"net/url"
"strings"
)
const baseURL = "https://api.monday.com/v2/"
type Client struct {
client *http.Client
token string
}
var (
Account *AccountService
Boards *BoardsService
Columns *ColumnsService
Groups *GroupsService
Items *ItemsService
ItemsByColumnValues *ItemsByColumnValuesService
Notifications *NotificationsService
Tags *TagsService
Teams *TeamsService
Updates *UpdateService
Users *UsersService
Webhooks *WebhooksService
)
type service struct{}
func NewClient(accessToken string, client *http.Client) *Client {
if client == nil {
client = http.DefaultClient
}
return &Client{
token: accessToken,
client: client,
}
}
func (c *Client) Exec(ctx context.Context, payload Payload) (*http.Response, error) {
select {
case <-ctx.Done():
return nil, ctx.Err()
default:
}
var queries []string
for _, query := range payload.queries {
str := query.stringify()
if str == "" {
continue
}
queries = append(queries, str)
}
var mutations []string
for _, mutation := range payload.mutations {
str := mutation.stringify()
if str == "" {
continue
}
mutations = append(mutations, str)
}
var query []string
if len(queries) != 0 {
query = append(query, fmt.Sprintf("{%s}", strings.Join(queries, "")))
}
if len(mutations) != 0 {
query = append(query, fmt.Sprintf("mutation{%s}", strings.Join(mutations, "")))
}
req, err := http.NewRequest(http.MethodPost, baseURL, strings.NewReader(
(url.Values{"query": query,}).Encode(),
))
if err != nil {
return nil, err
}
req.Header.Set("Authorization", c.token)
resp, err := c.client.Do(req)
if err != nil {
return nil, err
}
return resp, nil
}
type Payload struct {
queries []Query
mutations []Mutation
}