monday_ruby 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.env +1 -1
- data/.rubocop.yml +2 -1
- data/CHANGELOG.md +14 -0
- data/CONTRIBUTING.md +104 -0
- data/README.md +146 -142
- data/docs/.vitepress/config.mjs +255 -0
- data/docs/.vitepress/theme/index.js +4 -0
- data/docs/.vitepress/theme/style.css +43 -0
- data/docs/README.md +80 -0
- data/docs/explanation/architecture.md +507 -0
- data/docs/explanation/best-practices/errors.md +478 -0
- data/docs/explanation/best-practices/performance.md +1084 -0
- data/docs/explanation/best-practices/rate-limiting.md +630 -0
- data/docs/explanation/best-practices/testing.md +820 -0
- data/docs/explanation/column-values.md +857 -0
- data/docs/explanation/design.md +795 -0
- data/docs/explanation/graphql.md +356 -0
- data/docs/explanation/migration/v1.md +808 -0
- data/docs/explanation/pagination.md +447 -0
- data/docs/guides/advanced/batch.md +1274 -0
- data/docs/guides/advanced/complex-queries.md +1114 -0
- data/docs/guides/advanced/errors.md +818 -0
- data/docs/guides/advanced/pagination.md +934 -0
- data/docs/guides/advanced/rate-limiting.md +981 -0
- data/docs/guides/authentication.md +286 -0
- data/docs/guides/boards/create.md +386 -0
- data/docs/guides/boards/delete.md +405 -0
- data/docs/guides/boards/duplicate.md +511 -0
- data/docs/guides/boards/query.md +530 -0
- data/docs/guides/boards/update.md +453 -0
- data/docs/guides/columns/create.md +452 -0
- data/docs/guides/columns/metadata.md +492 -0
- data/docs/guides/columns/query.md +455 -0
- data/docs/guides/columns/update-multiple.md +459 -0
- data/docs/guides/columns/update-values.md +509 -0
- data/docs/guides/files/add-to-column.md +40 -0
- data/docs/guides/files/add-to-update.md +37 -0
- data/docs/guides/files/clear-column.md +33 -0
- data/docs/guides/first-request.md +285 -0
- data/docs/guides/folders/manage.md +750 -0
- data/docs/guides/groups/items.md +626 -0
- data/docs/guides/groups/manage.md +501 -0
- data/docs/guides/installation.md +169 -0
- data/docs/guides/items/create.md +493 -0
- data/docs/guides/items/delete.md +514 -0
- data/docs/guides/items/query.md +605 -0
- data/docs/guides/items/subitems.md +483 -0
- data/docs/guides/items/update.md +699 -0
- data/docs/guides/updates/manage.md +619 -0
- data/docs/guides/use-cases/dashboard.md +1421 -0
- data/docs/guides/use-cases/import.md +1962 -0
- data/docs/guides/use-cases/task-management.md +1381 -0
- data/docs/guides/workspaces/manage.md +502 -0
- data/docs/index.md +69 -0
- data/docs/package-lock.json +2468 -0
- data/docs/package.json +13 -0
- data/docs/reference/client.md +540 -0
- data/docs/reference/configuration.md +586 -0
- data/docs/reference/errors.md +693 -0
- data/docs/reference/resources/account.md +208 -0
- data/docs/reference/resources/activity-log.md +369 -0
- data/docs/reference/resources/board-view.md +359 -0
- data/docs/reference/resources/board.md +393 -0
- data/docs/reference/resources/column.md +543 -0
- data/docs/reference/resources/file.md +236 -0
- data/docs/reference/resources/folder.md +386 -0
- data/docs/reference/resources/group.md +507 -0
- data/docs/reference/resources/item.md +348 -0
- data/docs/reference/resources/subitem.md +267 -0
- data/docs/reference/resources/update.md +259 -0
- data/docs/reference/resources/workspace.md +213 -0
- data/docs/reference/response.md +560 -0
- data/docs/tutorial/first-integration.md +713 -0
- data/lib/monday/client.rb +24 -0
- data/lib/monday/configuration.rb +5 -0
- data/lib/monday/request.rb +15 -0
- data/lib/monday/resources/base.rb +4 -0
- data/lib/monday/resources/file.rb +56 -0
- data/lib/monday/util.rb +1 -0
- data/lib/monday/version.rb +1 -1
- metadata +87 -4
data/docs/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "monday-ruby-docs",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Documentation for monday_ruby gem",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "vitepress dev",
|
|
7
|
+
"build": "vitepress build",
|
|
8
|
+
"preview": "vitepress preview"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"vitepress": "^1.6.4"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
# Client
|
|
2
|
+
|
|
3
|
+
The `Monday::Client` class is the main entry point for interacting with the monday.com API. It handles authentication, request execution, error handling, and provides access to all resource classes.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Client class:
|
|
8
|
+
|
|
9
|
+
- Manages authentication and configuration
|
|
10
|
+
- Executes GraphQL queries and mutations via HTTP requests
|
|
11
|
+
- Automatically initializes all resource objects (boards, items, groups, etc.)
|
|
12
|
+
- Handles response parsing and error mapping
|
|
13
|
+
- Provides both global and instance-level configuration
|
|
14
|
+
|
|
15
|
+
## Initialization
|
|
16
|
+
|
|
17
|
+
### Basic Usage
|
|
18
|
+
|
|
19
|
+
Create a client instance with your API token:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
require "monday_ruby"
|
|
23
|
+
|
|
24
|
+
# Using instance configuration
|
|
25
|
+
client = Monday::Client.new(token: "your_api_token_here")
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Global Configuration
|
|
29
|
+
|
|
30
|
+
Set up configuration once and reuse across multiple client instances:
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
require "monday_ruby"
|
|
34
|
+
|
|
35
|
+
Monday.configure do |config|
|
|
36
|
+
config.token = "your_api_token_here"
|
|
37
|
+
config.version = "2023-07"
|
|
38
|
+
config.open_timeout = 10
|
|
39
|
+
config.read_timeout = 30
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Uses global configuration
|
|
43
|
+
client = Monday::Client.new
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Instance Configuration
|
|
47
|
+
|
|
48
|
+
Override global configuration for specific client instances:
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
# Global config
|
|
52
|
+
Monday.configure do |config|
|
|
53
|
+
config.token = "default_token"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Instance config (overrides global)
|
|
57
|
+
client = Monday::Client.new(
|
|
58
|
+
token: "different_token",
|
|
59
|
+
version: "2024-01",
|
|
60
|
+
open_timeout: 15,
|
|
61
|
+
read_timeout: 45
|
|
62
|
+
)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Configuration Options
|
|
66
|
+
|
|
67
|
+
| Option | Type | Default | Description |
|
|
68
|
+
|--------|------|---------|-------------|
|
|
69
|
+
| `token` | String | `nil` | monday.com API authentication token (required) |
|
|
70
|
+
| `host` | String | `"https://api.monday.com/v2"` | API endpoint URL |
|
|
71
|
+
| `version` | String | `"2023-07"` | API version to use |
|
|
72
|
+
| `open_timeout` | Integer | `10` | Connection timeout in seconds |
|
|
73
|
+
| `read_timeout` | Integer | `30` | Read timeout in seconds |
|
|
74
|
+
|
|
75
|
+
::: tip <span style="display: inline-flex; align-items: center; gap: 6px;"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>Getting Your API Token</span>
|
|
76
|
+
Find your API token in your monday.com account under **Admin** → **API**. See the [Authentication guide](/guides/authentication) for detailed instructions.
|
|
77
|
+
:::
|
|
78
|
+
|
|
79
|
+
## Available Resources
|
|
80
|
+
|
|
81
|
+
The client provides access to all monday.com resources through dynamically initialized resource objects. Each resource is automatically created when you initialize a client.
|
|
82
|
+
|
|
83
|
+
### Accessing Resources
|
|
84
|
+
|
|
85
|
+
```ruby
|
|
86
|
+
client = Monday::Client.new(token: "your_token")
|
|
87
|
+
|
|
88
|
+
# Access resources via client instance
|
|
89
|
+
client.account # => Monday::Resources::Account
|
|
90
|
+
client.activity_log # => Monday::Resources::ActivityLog
|
|
91
|
+
client.board # => Monday::Resources::Board
|
|
92
|
+
client.board_view # => Monday::Resources::BoardView
|
|
93
|
+
client.column # => Monday::Resources::Column
|
|
94
|
+
client.folder # => Monday::Resources::Folder
|
|
95
|
+
client.group # => Monday::Resources::Group
|
|
96
|
+
client.item # => Monday::Resources::Item
|
|
97
|
+
client.subitem # => Monday::Resources::Subitem
|
|
98
|
+
client.update # => Monday::Resources::Update
|
|
99
|
+
client.workspace # => Monday::Resources::Workspace
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Resource Summary
|
|
103
|
+
|
|
104
|
+
| Resource | Description | Documentation |
|
|
105
|
+
|----------|-------------|---------------|
|
|
106
|
+
| **account** | Query account information and users | [Account Reference](/reference/resources/account) |
|
|
107
|
+
| **activity_log** | Retrieve activity logs and audit trail | [Activity Log Reference](/reference/resources/activity-log) |
|
|
108
|
+
| **board** | Create, query, update, and manage boards | [Board Reference](/reference/resources/board) |
|
|
109
|
+
| **board_view** | Access and configure board views | [Board View Reference](/reference/resources/board-view) |
|
|
110
|
+
| **column** | Create and modify board columns | [Column Reference](/reference/resources/column) |
|
|
111
|
+
| **folder** | Organize boards into folders | [Folder Reference](/reference/resources/folder) |
|
|
112
|
+
| **group** | Manage board groups | [Group Reference](/reference/resources/group) |
|
|
113
|
+
| **item** | Create, query, and update items | [Item Reference](/reference/resources/item) |
|
|
114
|
+
| **subitem** | Work with subitems | [Subitem Reference](/reference/resources/subitem) |
|
|
115
|
+
| **update** | Post and retrieve updates | [Update Reference](/reference/resources/update) |
|
|
116
|
+
| **workspace** | Manage workspaces | [Workspace Reference](/reference/resources/workspace) |
|
|
117
|
+
|
|
118
|
+
## Public Methods
|
|
119
|
+
|
|
120
|
+
### config
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
client.config # => Monday::Configuration
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Returns the configuration object associated with this client instance.
|
|
127
|
+
|
|
128
|
+
**Returns:** `Monday::Configuration`
|
|
129
|
+
|
|
130
|
+
**Example:**
|
|
131
|
+
|
|
132
|
+
```ruby
|
|
133
|
+
client = Monday::Client.new(token: "your_token", version: "2023-07")
|
|
134
|
+
|
|
135
|
+
config = client.config
|
|
136
|
+
config.token # => "your_token"
|
|
137
|
+
config.version # => "2023-07"
|
|
138
|
+
config.host # => "https://api.monday.com/v2"
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Usage Examples
|
|
142
|
+
|
|
143
|
+
### Basic Query
|
|
144
|
+
|
|
145
|
+
Query boards using the client:
|
|
146
|
+
|
|
147
|
+
```ruby
|
|
148
|
+
require "monday_ruby"
|
|
149
|
+
|
|
150
|
+
client = Monday::Client.new(token: "your_token")
|
|
151
|
+
|
|
152
|
+
# Query boards
|
|
153
|
+
response = client.board.query(
|
|
154
|
+
args: { ids: [123, 456] },
|
|
155
|
+
select: ["id", "name", "description"]
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
if response.success?
|
|
159
|
+
boards = response.body.dig("data", "boards")
|
|
160
|
+
boards.each do |board|
|
|
161
|
+
puts "Board: #{board["name"]}"
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Creating Resources
|
|
167
|
+
|
|
168
|
+
Use mutation methods to create new resources:
|
|
169
|
+
|
|
170
|
+
```ruby
|
|
171
|
+
client = Monday::Client.new(token: "your_token")
|
|
172
|
+
|
|
173
|
+
# Create a new board
|
|
174
|
+
response = client.board.create(
|
|
175
|
+
args: {
|
|
176
|
+
board_name: "Project Board",
|
|
177
|
+
board_kind: :public
|
|
178
|
+
},
|
|
179
|
+
select: ["id", "name"]
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
board = response.body.dig("data", "create_board")
|
|
183
|
+
puts "Created board #{board["name"]} with ID: #{board["id"]}"
|
|
184
|
+
|
|
185
|
+
# Create an item on the board
|
|
186
|
+
item_response = client.item.create(
|
|
187
|
+
args: {
|
|
188
|
+
board_id: board["id"],
|
|
189
|
+
item_name: "First Task"
|
|
190
|
+
},
|
|
191
|
+
select: ["id", "name"]
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
item = item_response.body.dig("data", "create_item")
|
|
195
|
+
puts "Created item: #{item["name"]}"
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Complex Nested Queries
|
|
199
|
+
|
|
200
|
+
Query boards with nested data:
|
|
201
|
+
|
|
202
|
+
```ruby
|
|
203
|
+
client = Monday::Client.new(token: "your_token")
|
|
204
|
+
|
|
205
|
+
response = client.board.query(
|
|
206
|
+
args: { ids: [123] },
|
|
207
|
+
select: [
|
|
208
|
+
"id",
|
|
209
|
+
"name",
|
|
210
|
+
{
|
|
211
|
+
groups: [
|
|
212
|
+
"id",
|
|
213
|
+
"title",
|
|
214
|
+
{
|
|
215
|
+
items: [
|
|
216
|
+
"id",
|
|
217
|
+
"name",
|
|
218
|
+
{
|
|
219
|
+
column_values: ["id", "text", "value"]
|
|
220
|
+
}
|
|
221
|
+
]
|
|
222
|
+
}
|
|
223
|
+
]
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
if response.success?
|
|
229
|
+
board = response.body.dig("data", "boards", 0)
|
|
230
|
+
board["groups"].each do |group|
|
|
231
|
+
puts "Group: #{group["title"]}"
|
|
232
|
+
group["items"].each do |item|
|
|
233
|
+
puts " Item: #{item["name"]}"
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Using Multiple Clients
|
|
240
|
+
|
|
241
|
+
Create multiple clients for different accounts or configurations:
|
|
242
|
+
|
|
243
|
+
```ruby
|
|
244
|
+
# Production client
|
|
245
|
+
prod_client = Monday::Client.new(
|
|
246
|
+
token: ENV["MONDAY_PROD_TOKEN"],
|
|
247
|
+
read_timeout: 60
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
# Sandbox client
|
|
251
|
+
sandbox_client = Monday::Client.new(
|
|
252
|
+
token: ENV["MONDAY_SANDBOX_TOKEN"],
|
|
253
|
+
host: "https://api.sandbox.monday.com/v2"
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
# Use different clients independently
|
|
257
|
+
prod_boards = prod_client.board.query
|
|
258
|
+
sandbox_boards = sandbox_client.board.query
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Pagination Example
|
|
262
|
+
|
|
263
|
+
Use cursor-based pagination for large datasets:
|
|
264
|
+
|
|
265
|
+
```ruby
|
|
266
|
+
client = Monday::Client.new(token: "your_token")
|
|
267
|
+
|
|
268
|
+
all_items = []
|
|
269
|
+
cursor = nil
|
|
270
|
+
|
|
271
|
+
loop do
|
|
272
|
+
response = client.board.items_page(
|
|
273
|
+
board_ids: 123,
|
|
274
|
+
limit: 100,
|
|
275
|
+
cursor: cursor
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
items_page = response.body.dig("data", "boards", 0, "items_page")
|
|
279
|
+
all_items.concat(items_page["items"])
|
|
280
|
+
|
|
281
|
+
cursor = items_page["cursor"]
|
|
282
|
+
break if cursor.nil?
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
puts "Retrieved #{all_items.length} total items"
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Error Handling
|
|
289
|
+
|
|
290
|
+
The Client class automatically handles errors and raises appropriate exceptions based on HTTP status codes and GraphQL error codes.
|
|
291
|
+
|
|
292
|
+
### Exception Hierarchy
|
|
293
|
+
|
|
294
|
+
All exceptions inherit from `Monday::Error`:
|
|
295
|
+
|
|
296
|
+
```ruby
|
|
297
|
+
Monday::Error (base class)
|
|
298
|
+
├── Monday::AuthorizationError (401, 403)
|
|
299
|
+
├── Monday::InvalidRequestError (400)
|
|
300
|
+
├── Monday::ResourceNotFoundError (404)
|
|
301
|
+
├── Monday::InternalServerError (500)
|
|
302
|
+
├── Monday::RateLimitError (429)
|
|
303
|
+
└── Monday::ComplexityError (GraphQL complexity limit)
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### Basic Error Handling
|
|
307
|
+
|
|
308
|
+
```ruby
|
|
309
|
+
client = Monday::Client.new(token: "your_token")
|
|
310
|
+
|
|
311
|
+
begin
|
|
312
|
+
response = client.board.query(args: { ids: [123] })
|
|
313
|
+
boards = response.body.dig("data", "boards")
|
|
314
|
+
rescue Monday::AuthorizationError => e
|
|
315
|
+
puts "Authentication failed: #{e.message}"
|
|
316
|
+
puts "Check your API token"
|
|
317
|
+
rescue Monday::InvalidRequestError => e
|
|
318
|
+
puts "Invalid request: #{e.message}"
|
|
319
|
+
puts "Error code: #{e.code}"
|
|
320
|
+
rescue Monday::RateLimitError => e
|
|
321
|
+
puts "Rate limit exceeded: #{e.message}"
|
|
322
|
+
sleep 60
|
|
323
|
+
retry
|
|
324
|
+
rescue Monday::Error => e
|
|
325
|
+
puts "monday.com API error: #{e.message}"
|
|
326
|
+
puts "Response: #{e.response.body}"
|
|
327
|
+
end
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Checking Response Success
|
|
331
|
+
|
|
332
|
+
Alternatively, check `response.success?` before processing:
|
|
333
|
+
|
|
334
|
+
```ruby
|
|
335
|
+
response = client.item.create(
|
|
336
|
+
args: {
|
|
337
|
+
board_id: 123,
|
|
338
|
+
item_name: "New Task"
|
|
339
|
+
}
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
if response.success?
|
|
343
|
+
item = response.body.dig("data", "create_item")
|
|
344
|
+
puts "Created item: #{item["id"]}"
|
|
345
|
+
else
|
|
346
|
+
puts "Request failed"
|
|
347
|
+
puts "Status: #{response.status}"
|
|
348
|
+
puts "Error: #{response.body["error_message"]}"
|
|
349
|
+
end
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### Error Properties
|
|
353
|
+
|
|
354
|
+
All error objects provide:
|
|
355
|
+
|
|
356
|
+
```ruby
|
|
357
|
+
begin
|
|
358
|
+
client.board.query(args: { ids: [999999] })
|
|
359
|
+
rescue Monday::Error => e
|
|
360
|
+
e.message # => "ResourceNotFoundException: Board not found"
|
|
361
|
+
e.code # => "ResourceNotFoundException"
|
|
362
|
+
e.response # => Monday::Response object
|
|
363
|
+
e.error_data # => Additional error metadata (hash)
|
|
364
|
+
end
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
::: tip <span style="display: inline-flex; align-items: center; gap: 6px;"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>Learn More About Error Handling</span>
|
|
368
|
+
See the [Error Handling guide](/guides/advanced/errors) for comprehensive examples, retry strategies, and best practices.
|
|
369
|
+
:::
|
|
370
|
+
|
|
371
|
+
## Best Practices
|
|
372
|
+
|
|
373
|
+
### Use Global Configuration for Simple Applications
|
|
374
|
+
|
|
375
|
+
For most applications, global configuration is the simplest approach:
|
|
376
|
+
|
|
377
|
+
```ruby
|
|
378
|
+
# config/initializers/monday.rb (Rails)
|
|
379
|
+
Monday.configure do |config|
|
|
380
|
+
config.token = ENV["MONDAY_API_TOKEN"]
|
|
381
|
+
config.version = "2023-07"
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
# Anywhere in your app
|
|
385
|
+
client = Monday::Client.new
|
|
386
|
+
response = client.board.query
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
### Use Instance Configuration for Multi-Account Applications
|
|
390
|
+
|
|
391
|
+
When working with multiple monday.com accounts:
|
|
392
|
+
|
|
393
|
+
```ruby
|
|
394
|
+
class MondayService
|
|
395
|
+
def initialize(account_token)
|
|
396
|
+
@client = Monday::Client.new(token: account_token)
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
def fetch_boards
|
|
400
|
+
@client.board.query
|
|
401
|
+
end
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
# Use different clients
|
|
405
|
+
customer_a = MondayService.new(ENV["CUSTOMER_A_TOKEN"])
|
|
406
|
+
customer_b = MondayService.new(ENV["CUSTOMER_B_TOKEN"])
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### Implement the Singleton Pattern
|
|
410
|
+
|
|
411
|
+
Reuse a single client instance to reduce overhead:
|
|
412
|
+
|
|
413
|
+
```ruby
|
|
414
|
+
class MondayClient
|
|
415
|
+
def self.instance
|
|
416
|
+
@instance ||= Monday::Client.new(token: ENV["MONDAY_API_TOKEN"])
|
|
417
|
+
end
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
# Use throughout your application
|
|
421
|
+
response = MondayClient.instance.board.query
|
|
422
|
+
items = MondayClient.instance.item.query
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
### Configure Appropriate Timeouts
|
|
426
|
+
|
|
427
|
+
Adjust timeouts based on your use case:
|
|
428
|
+
|
|
429
|
+
```ruby
|
|
430
|
+
# For long-running operations (e.g., bulk imports)
|
|
431
|
+
client = Monday::Client.new(
|
|
432
|
+
token: "your_token",
|
|
433
|
+
open_timeout: 30,
|
|
434
|
+
read_timeout: 120
|
|
435
|
+
)
|
|
436
|
+
|
|
437
|
+
# For quick, real-time operations
|
|
438
|
+
client = Monday::Client.new(
|
|
439
|
+
token: "your_token",
|
|
440
|
+
open_timeout: 5,
|
|
441
|
+
read_timeout: 15
|
|
442
|
+
)
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
### Always Handle Errors
|
|
446
|
+
|
|
447
|
+
Wrap API calls in error handling to prevent application crashes:
|
|
448
|
+
|
|
449
|
+
```ruby
|
|
450
|
+
def create_monday_item(board_id, name)
|
|
451
|
+
client = Monday::Client.new(token: ENV["MONDAY_TOKEN"])
|
|
452
|
+
|
|
453
|
+
response = client.item.create(
|
|
454
|
+
args: { board_id: board_id, item_name: name }
|
|
455
|
+
)
|
|
456
|
+
|
|
457
|
+
response.body.dig("data", "create_item")
|
|
458
|
+
rescue Monday::RateLimitError => e
|
|
459
|
+
# Implement exponential backoff
|
|
460
|
+
sleep 60
|
|
461
|
+
retry
|
|
462
|
+
rescue Monday::Error => e
|
|
463
|
+
# Log error and notify
|
|
464
|
+
logger.error("Failed to create monday.com item: #{e.message}")
|
|
465
|
+
notify_error_tracking_service(e)
|
|
466
|
+
nil
|
|
467
|
+
end
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
### Check API Version Compatibility
|
|
471
|
+
|
|
472
|
+
Stay updated with API versions:
|
|
473
|
+
|
|
474
|
+
```ruby
|
|
475
|
+
# Use the latest stable version
|
|
476
|
+
Monday.configure do |config|
|
|
477
|
+
config.token = ENV["MONDAY_TOKEN"]
|
|
478
|
+
config.version = "2024-01" # Update as new versions release
|
|
479
|
+
end
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
## Internal Methods
|
|
483
|
+
|
|
484
|
+
These methods are private and used internally by the client:
|
|
485
|
+
|
|
486
|
+
- `make_request(body)` - Executes GraphQL requests and returns Response objects
|
|
487
|
+
- `configure(config_args)` - Sets up configuration (global or instance)
|
|
488
|
+
- `uri` - Builds the API endpoint URI
|
|
489
|
+
- `request_headers` - Constructs authentication headers
|
|
490
|
+
- `handle_response(response)` - Processes responses and raises errors
|
|
491
|
+
- `raise_errors(response)` - Maps errors to exception classes
|
|
492
|
+
|
|
493
|
+
::: warning <span style="display: inline-flex; align-items: center; gap: 6px;"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path><line x1="12" y1="9" x2="12" y2="13"></line><line x1="12" y1="17" x2="12.01" y2="17"></line></svg>Private Methods</span>
|
|
494
|
+
These methods are for internal use only. Do not call them directly. Use resource methods instead.
|
|
495
|
+
:::
|
|
496
|
+
|
|
497
|
+
## Response Objects
|
|
498
|
+
|
|
499
|
+
All client operations return a `Monday::Response` object with the following properties:
|
|
500
|
+
|
|
501
|
+
```ruby
|
|
502
|
+
response = client.board.query(args: { ids: [123] })
|
|
503
|
+
|
|
504
|
+
response.success? # => true/false
|
|
505
|
+
response.status # => 200
|
|
506
|
+
response.body # => Hash with parsed JSON response
|
|
507
|
+
response.headers # => Hash with HTTP headers
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
### Response Success Check
|
|
511
|
+
|
|
512
|
+
The `success?` method returns `true` only when:
|
|
513
|
+
1. HTTP status code is 2xx (200-299)
|
|
514
|
+
2. Response body does not contain GraphQL errors
|
|
515
|
+
|
|
516
|
+
```ruby
|
|
517
|
+
if response.success?
|
|
518
|
+
# Safe to access data
|
|
519
|
+
data = response.body["data"]
|
|
520
|
+
else
|
|
521
|
+
# Handle error
|
|
522
|
+
error = response.body["error_message"]
|
|
523
|
+
end
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
## Related Documentation
|
|
527
|
+
|
|
528
|
+
- [Configuration Reference](/reference/configuration) - Detailed configuration options
|
|
529
|
+
- [Response Reference](/reference/response) - Response object structure
|
|
530
|
+
- [Error Reference](/reference/errors) - Error classes and codes
|
|
531
|
+
- [Authentication Guide](/guides/authentication) - How to get API tokens
|
|
532
|
+
- [First Request Guide](/guides/first-request) - Step-by-step tutorial
|
|
533
|
+
- [Error Handling Guide](/guides/advanced/errors) - Error handling strategies
|
|
534
|
+
- [Rate Limiting Guide](/guides/advanced/rate-limiting) - Handling rate limits
|
|
535
|
+
|
|
536
|
+
## External References
|
|
537
|
+
|
|
538
|
+
- [monday.com API Documentation](https://developer.monday.com/api-reference/docs)
|
|
539
|
+
- [monday.com Authentication](https://developer.monday.com/api-reference/docs/authentication)
|
|
540
|
+
- [GraphQL API Overview](https://developer.monday.com/api-reference/docs/introduction-to-graphql)
|