-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTrelloAPI
More file actions
1194 lines (1171 loc) · 27.9 KB
/
TrelloAPI
File metadata and controls
1194 lines (1171 loc) · 27.9 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// I DID NOT CREATE THIS SCRIPT AS I SIMPLY MODIFIED IT IN ORDER TO BE COMPATIBLE WITH THE ADMIN SYSTEM
local key = require(script.Parent.Parent.Parent:WaitForChild("SR_Loader").Config)["Trello Stuff"]["TrelloAPIKey"];
local suc,err=pcall(function()
if game.Players.LocalPlayer~=nil then
warn("It is unsafe to have the api in a local enviorment pleasae move it to ServerScriptService and ONLY use it from Server Scripts!")
end
end)
if not script:IsDescendantOf(game.ServerScriptService) then
warn("It is unsafe to have the api in a local enviorment pleasae move it to ServerScriptService and ONLY use it from Server Scripts!")
end
local Private=true
local addon
local HS={}
function UrlEncode_Not_Like_Roblox(tab)
local ret=""
local c=0
for i,v in next,tab do
ret=ret.."&"..(tostring(i)).."="..(tostring(v));
end
return ret
end
function HS:PostAsync(url,jsonData)
local rhs=game:GetService("HttpService");
local data
local thread=coroutine.create(function(u,j)
local suc,msg=false,"";
repeat
suc,msg=pcall(function()
data=rhs:PostAsync(u,j)
end)
--print(err)
wait(3)
until suc
coroutine.yield(data)
end)
local status,d=coroutine.resume(thread,url,jsonData);
while data==nil do
wait()
end
return data
end
function HS:GetAsync(url,cache)
local rhs=game:GetService("HttpService");
local data
local thread=coroutine.create(function(u,j)
local suc,msg=false,"";
repeat
suc,msg=pcall(function()
data=rhs:GetAsync(u,j)
end)
--print(data)
wait(3)
until suc
coroutine.yield(data)
end)
local status,d=coroutine.resume(thread,url,cache);
while data==nil do
wait()
end
return data
end
function HS:JSONEncode(tab)
local rhs=game:GetService("HttpService");
return rhs:JSONEncode(tab)
end
function HS:JSONDecode(tab)
local rhs=game:GetService("HttpService");
return rhs:JSONDecode(tab)
end
local IS=game:GetService("InsertService")
local T = {}
if script:FindFirstChild("Token")==nil and key=="Here!" and getfenv(0).token==nil then
error("No token or API-KEY available please set one using this link and putting the random numbers and letters into "..script:GetFullName().." or put it in a global variable in the script calling the TrelloAPI named 'token' (ignore the warning you get when creating a script if you do this) \nhttps://trello.com/1/authorize?key=[Your api key is at https://trello.com/app-key]&name=Roblox+Api&expiration=never&response_type=token&scope=read,write")
end --Thanks to iRexBot for Pointing out my Typo!
while script:FindFirstChild("Token")==nil and getfenv(0).token==nil do
wait()
end
local token= require(script.Parent.Parent.Parent["SR_Loader"].Config).TrelloToken
script.Token:Destroy()
function getAddon()
if token~="" then
addon="?key="..key.."&token="..token
elseif getfenv(0).token~=nil then
local val=getfenv(0).token
addon="?key="..key.."&token="..val
else
error([[-Instructions.
1. Go to this link and click allow: https://trello.com/1/authorize?key=[Your api key is at https://trello.com/app-key]&name=Roblox+Api&expiration=never&response_type=token&scope=read,write
2. Copy the token in the page sent to you
3. Paste the token in the Value of Token]])
end
return "&key="..key.."&token="..token
end
--[[
POST /1/cards/[card id or shortlink]/actions/comments
Required permissions: comments
Arguments
text (required)
Valid Values: a string with a length from 1 to 16384
--]]--]]
function T:PostComment(cid,t)
local url
if Private then
getAddon()
url="https://api.trello.com/1/cards/"..tostring(cid).."/actions/comments"..addon
else
url="https://api.trello.com/1/cards/"..tostring(cid).."/actions/comments"..addon
end
local dat={
text=t
}
local data=HS:JSONEncode(dat)
local re=HS:PostAsync(url,data)
local red=HS:JSONDecode(re)
return red
end
--/1/lists/[idList]/cards
--[[
[{
"id": "4eea503791e31d1746000080",
"checkItemStates": [],
"closed": false,
"dateLastActivity": "2011-12-15T19:53:27.228Z",
"desc": "",
"descData": null,
"email": null,
"idAttachmentCover": null,
"idBoard": "",
"idLabels": [],
"idList": "",
"idMembersVoted": [],
"idShort": 3,
"manualCoverAttachment": false,
"name": "Finish my awesome application",
"pos": 65536,
"shortLink": "XlG8S7ll",
"badges": {
"votes": 0,
"viewingMemberVoted": false,
"subscribed": false,
"fogbugz": "",
"checkItems": 0,
"checkItemsChecked": 0,
"comments": 0,
"attachments": 0,
"description": false,
"due": null
},
"due": null,
"idChecklists": [],
"idMembers": [],
"labels": [],
"shortUrl": "",
"subscribed": false,
"url": ""
}
]]--]]--]]--]]
function T:GetCardsInList(lid)
local url
if Private then
getAddon()
url="https://api.trello.com/1/lists/"..tostring(lid).."/cards"..addon
else
getAddon()
url="https://api.trello.com/1/lists/"..tostring(lid).."/cards"..addon
end
local re=HS:GetAsync(url,true)
local dat=HS:JSONDecode(re)
return dat
end
--[[
POST /1/labels
Required permissions: write
Arguments
name (required)
Valid Values: a string with a length from 0 to 16384
color (required)
Valid Values: A valid label color or null
idBoard (required)
Valid Values: An id
--]]--]]
function T:AddLabel(nae,col,boardid)
local url
if Private then
getAddon()
url="https://api.trello.com/1/labels"..addon
else
url="https://api.trello.com/1/labels"..addon
end
local dat={
name=nae,
color=col,
idBoard=boardid
}
local data=HS:JSONEncode(dat)
local re=HS:PostAsync(url,data)
--print(re)
return (HS:JSONDecode(re)).id
end
--[[
GET /1/boards/[board_id]
Required permissions: read
Arguments Show
Examples
https://api.trello.com/1/boards/4eea4ffc91e31d1746000046?lists=open&list_fields=name&fields=name,desc&key=[application_key]&token=[optional_auth_token]
{
"id": "4eea4ffc91e31d1746000046",
"name": "Example Board",
"desc": "This board is used in the API examples",
"lists": [{
"id": "4eea4ffc91e31d174600004a",
"name": "To Do Soon"
}, {
"id": "4eea4ffc91e31d174600004b",
"name": "Doing"
}, {
"id": "4eea4ffc91e31d174600004c",
"name": "Done"
}]
}
--]]--]]
function T:GetBoardNameFromId(id)
getAddon()
local ret=HS:GetAsync("https://api.trello.com/1/boards/"..id..addon,true)
local data=HS:JSONDecode(ret)
return data["name"]
end
--[[
GET /1/tokens/[token]/member
Required permissions: read
Arguments Show]]--]]--
function T:GetAllBoards()
getAddon()
local dat=HS:GetAsync("https://api.trello.com/1/tokens/"..token.."/member"..addon,true)
local data=HS:JSONDecode(dat)
return data["idBoards"]
end
--[[
POST /1/cards/[card id or shortlink]/idLabels
Required permissions: write
Arguments
value (required)
Valid Values: The id of the label to add
--]]--]]
function T:AddCardLabel(card,lid)
local url
local cardi=tostring(card)
if Private then
getAddon()
url="https://api.trello.com/1/cards/"..cardi.."/idLabels"..addon
else
url="https://api.trello.com/1/cards/"..cardi.."/idLabels"..addon
end
--print(card,"IS THE CARD ID \n",lid,"IS THE LABEL ID")
local da={
value=lid
}
local dat=HS:JSONEncode(da)
local data=HS:PostAsync(url,dat)
--print(data)
return HS:JSONDecode(data)
end
--[[
POST /1/boards
Required permissions: write
Arguments
name (required)
Valid Values: a string with a length from 1 to 16384
desc (optional)
Valid Values: a string with a length from 0 to 16384
idOrganization (optional)
Valid Values: The id or name of the organization to add the board to.
idBoardSource (optional)
Valid Values: The id of the board to copy into the new board
keepFromSource (optional)
Default: all
Valid Values: Components of the source board to copy.
powerUps (optional)
Valid Values: all or a comma-separated list of:
calendar
cardAging
recap
voting
prefs_permissionLevel (optional)
Default: private
Valid Values: One of:
org
private
public
prefs_voting (optional)
Default: disabled
Valid Values: One of:
disabled
members
observers
org
public
prefs_comments (optional)
Default: members
Valid Values: One of:
disabled
members
observers
org
public
prefs_invitations (optional)
Default: members
Valid Values: One of:
admins
members
prefs_selfJoin (optional)
Default: true
Valid Values:
true
false
prefs_cardCovers (optional)
Default: true
Valid Values:
true
false
prefs_background (optional)
Default: blue
Valid Values: a string with a length from 0 to 16384
prefs_cardAging (optional)
Default: regular
Valid Values: One of:
pirate
regular
--]]--]]
function T:AddBoard(nae,dec)
local url
if Private then
getAddon()
url="https://api.trello.com/1/boards"..addon
else
getAddon()
url="https://api.trello.com/1/boards"..addon
end
local dat={
name=nae,
desc=dec
}
local data=HS:JSONEncode(dat)
local re=HS:PostAsync(url,data)
local red=HS:JSONDecode(re)
return red
end
function T:GetCardID(name,boardid)
local url
if Private then
getAddon()
url="https://api.trello.com/1/boards/"..boardid.."/cards"..addon
else
getAddon()
url="https://api.trello.com/1/boards/"..boardid.."/cards"..addon
end
local tab=HS:GetAsync(url,true)
local tabl=HS:JSONDecode(tab)
for k,ta in pairs(tabl) do
for p,t in pairs(ta) do
if p=="name" and t==name then
return ta.id
end
end
end
end
function T:GetCardInfo(cardid)
--/1/boards/[board_id]/cards/[idCard]
local url
if Private then
getAddon()
url="https://api.trello.com/1/cards/"..cardid..""..addon
else
getAddon()
url="https://api.trello.com/1/cards/"..cardid..""..addon
end
local re=HS:GetAsync(url,true)
local tab=HS:JSONDecode(re)
return tab
end
function T:GetBoardInfo(boardid)
local url
if Private then
getAddon()
url="https://api.trello.com/1/boards/"..boardid.."?lists=all&cards=all&card_checklists=all&labels=all&memberships=all&members=all&membersInvited=all&checklists=all&organization_memberships=all&fields=all"..getAddon()
else
getAddon()
url="https://api.trello.com/1/boards/"..boardid.."?lists=all&cards=all&card_checklists=all&labels=all&memberships=all&members=all&membersInvited=all&checklists=all&organization_memberships=all&fields=all"..getAddon()
end
local re=HS:GetAsync(url,true)
local data=HS:JSONDecode(re)
return data
end
function T:GetLists(boardid)
local url
if Private then
getAddon()
url="https://api.trello.com/1/boards/"..boardid.."/lists"..addon
else
getAddon()
url="https://api.trello.com/1/boards/"..boardid.."/lists"..addon
end
local re=HS:GetAsync(url,true)
local data=HS:JSONDecode(re)
return data
end
function T:GetMemberBoards(name)
local url
if Private then
getAddon()
url="https://api.trello.com/1/members/"..name.."/boards"..addon
else
getAddon()
url="https://api.trello.com/1/members/"..name.."/boards"..addon
end
local re=HS:GetAsync(url,true)
local data=HS:JSONDecode(re)
return data
end
function T:GetBoardMembers(boardid)
local url
if Private then
getAddon()
url="https://api.trello.com/1/boards/"..boardid.."/members"..addon
else
getAddon()
url="https://api.trello.com/1/boards/"..boardid.."/members"..addon
end
local re=HS:GetAsync(url,true)
local data=HS:JSONDecode(re)
return data
end
--[[
POST /1/boards
Required permissions: write
Arguments Hide
name (required)
Valid Values: a string with a length from 1 to 16384
desc (optional)
Valid Values: a string with a length from 0 to 16384
idOrganization (optional)
Valid Values: The id or name of the organization to add the board to.
idBoardSource (optional)
Valid Values: The id of the board to copy into the new board
keepFromSource (optional)
Default: all
Valid Values: Components of the source board to copy.
powerUps (optional)
Valid Values: all or a comma-separated list of:
calendar
cardAging
recap
voting
prefs_permissionLevel (optional)
Default: private
Valid Values: One of:
org
private
public
prefs_voting (optional)
Default: disabled
Valid Values: One of:
disabled
members
observers
org
public
prefs_comments (optional)
Default: members
Valid Values: One of:
disabled
members
observers
org
public
prefs_invitations (optional)
Default: members
Valid Values: One of:
admins
members
prefs_selfJoin (optional)
Default: true
Valid Values:
true
false
prefs_cardCovers (optional)
Default: true
Valid Values:
true
false
prefs_background (optional)
Default: blue
Valid Values: a string with a length from 0 to 16384
prefs_cardAging (optional)
Default: regular
Valid Values: One of:
pirate
regular
]]--]]
function T:CreateBoard(nam,...)
local opt={...}
local tab={
name=nam
}
for i,v in next,opt do
local arg="none"
if i==1 then
tab["desc"]=v
elseif i==2 then
tab["prefs_permissionLevel"]=v
end
end
local tabl=HS:JSONEncode(tab)
local ret=HS:PostAsync("https://api.trello.com/1/boards",tabl)
return HS:JSONDecode(ret)
end
function T:GetBoardID(name)
local url
if Private then
getAddon()
url="https://api.trello.com/1/members/me/boards"..addon
else
getAddon()
url="https://api.trello.com/1/members/me/boards"..addon
end
local tball=HS:GetAsync(url,true)
local dt=HS:JSONDecode(tball)
for _,tab in pairs(dt) do
for p,it in pairs(tab) do
if p=="name" and it==name then
return tab.id
end
end
end
error(name.." not found!")
return nil
end
--[[
POST /1/cards
Required permissions: write
Arguments
name (optional)
Valid Values: The name of the new card. It isn't required if the name is being copied from provided by a URL, file or card that is being copied.
desc (optional)
Valid Values: a string with a length from 0 to 16384
pos (optional)
Default: bottom
Valid Values: A position. top, bottom, or a positive number.
due (required)
Valid Values: A date, or null
labels (optional)
Valid Values: all or a comma-separated list of:
blue
green
orange
purple
red
yellow
idList (required)
Valid Values: id of the list that the card should be added to
idMembers (optional)
Valid Values: A comma-separated list of objectIds, 24-character hex strings
idLabels (optional)
Valid Values: A comma-separated list of objectIds, 24-character hex strings
urlSource (required)
Valid Values: A URL starting with http:// or https:// or null
fileSource (optional)
Valid Values: A file
idCardSource (optional)
Valid Values: The id of the card to copy into a new card.
keepFromSource (optional)
Default: all
Valid Values: Properties of the card to copy over from the source.
--]]--]]
function T:AddCard(...)
local url
local args={...}
local dat=nil
if #args==3 then
local nam,des,lid=args[1],args[2],args[3]
dat={
name=nam,
desc=des.."",
idList=lid,
urlSource=nil,
due=nil
}
elseif #args==4 then
local nam,des,lid,url=args[1],args[2],args[3],args[4]
dat={
name=nam,
desc=""..des,
idList=lid,
urlSource=url,
due=nil
}
elseif #args==5 then
local nam,des,lid,url,po=args[1],args[2],args[3],args[4],args[5]
dat={
name=nam,
desc=""..des,
idList=lid,
urlSource=url,
pos=po,
due=nil
}
elseif #args==6 then
local nam,des,lid,url,po,de=args[1],args[2],args[3],args[4],args[5],args[6]
dat={
name=nam,
desc=""..des,
idList=lid,
urlSource=url,
pos=po,
due=de
}
elseif #args==7 then
local nam,des,lid,url,po,de,label=args[1],args[2],args[3],args[4],args[5],args[6],args[7]
dat={
name=nam,
desc=""..des,
idList=lid,
urlSource=url,
pos=po,
due=de,
labels=label
}
elseif #args==8 then
local nam,des,lid,url,po,de,label,cc=args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8]
dat={
name=nam,
desc=""..des,
idList=lid,
urlSource=url,
pos=po,
due=de,
labels=label,
idCardSource=cc
}
end
local data
if dat~= nil then
data=HS:JSONEncode(dat)
else
error("No Parameters Found!")
return false
end
if Private then
getAddon()
url="https://api.trello.com/1/cards"..addon
else
getAddon()
url="https://api.trello.com/1/cards"..addon
end
local re=HS:PostAsync(url,data)
return HS:JSONDecode(re)
end
--[[
POST /1/cards
Required permissions: write
Arguments
name (optional)
Valid Values: The name of the new card. It isn't required if the name is being copied from provided by a URL, file or card that is being copied.
desc (optional)
Valid Values: a string with a length from 0 to 16384
pos (optional)
Default: bottom
Valid Values: A position. top, bottom, or a positive number.
due (required)
Valid Values: A date, or null
labels (optional)
Valid Values: all or a comma-separated list of:
blue
green
orange
purple
red
yellow
idList (required)
Valid Values: id of the list that the card should be added to
idMembers (optional)
Valid Values: A comma-separated list of objectIds, 24-character hex strings
idLabels (optional)
Valid Values: A comma-separated list of objectIds, 24-character hex strings
urlSource (required)
Valid Values: A URL starting with http:// or https:// or null
fileSource (optional)
Valid Values: A file
idCardSource (optional)
Valid Values: The id of the card to copy into a new card.
keepFromSource (optional)
Default: all
Valid Values: Properties of the card to copy over from the source.
--]]--]]
function AddCustomCard(array, ListID)
if array["due"]==nil then
array["due"]=nil
end
if array["urlSource"]==nil then
array["urlSource"]=nil
end
array["idList"]=ListID
getAddon()
local ret=HS:PostAsync("https://api.trello.com/1/cards"..addon, HS:JSONEncode(array))
local data=HS:JSONDecode(ret)
return data
end
--[[
POST /1/cards/[card id or shortlink]/attachments
Required permissions: write
Arguments
file (optional)
Valid Values: A file
url (optional)
Valid Values: A URL starting with http:// or https:// or null
name (optional)
Valid Values: a string with a length from 0 to 256
mimeType (optional)
Valid Values: a string with a length from 0 to 256
--]]--]]
function T:AddCardAtt(cardid,nae,type,value)
local url
local dat
if string.lower(type)=="file" then
dat={
name=nae,
file=value
}
elseif string.lower(type)=="url" then
dat={
name=nae,
url=value
}
elseif string.lower(type)=="mime" then
dat={
name=nae,
mimeType=value
}
end
local cardi=tostring(cardid)
if Private then
getAddon()
url="https://api.trello.com/1/cards/"..cardi.."/attachments"..addon
else
getAddon()
url="https://api.trello.com/1/cards/"..cardi.."/attachments"..addon
end
local data=HS:JSONEncode(dat)
local re=HS:PostAsync(url,data)
return re
end
--[[
GET /1/boards/[board_id]/labels
Required permissions: read
Arguments
fields (optional)
Default: all
Valid Values: all or a comma-separated list of:
color
idBoard
name
uses
limit (optional)
Default: 50
Valid Values: a number from 0 to 1000
--]]--]]
function T:GetLabels(boardid)
local url
local dat
if Private then
getAddon()
url="https://api.trello.com/1/boards/"..boardid.."/labels"..addon
else
getAddon()
url="https://api.trello.com/1/boards/"..boardid.."/labels"..addon
end
local re=HS:GetAsync(url,true)
--print(re)
local dat=HS:JSONDecode(re)
return dat
end
--[[
GET /1/boards/[board_id]/labels
Required permissions: read
Arguments
fields (optional)
Default: all
Valid Values: all or a comma-separated list of:
color
idBoard
name
uses
limit (optional)
Default: 50
Valid Values: a number from 0 to 1000
--]]--]]
function T:GetLabelID(LabelName,boardid)
local url
local dat
if Private then
getAddon()
url="https://api.trello.com/1/boards/"..boardid.."/labels"..addon
else
getAddon()
url="https://api.trello.com/1/boards/"..boardid.."/labels"..addon
end
local re=HS:GetAsync(url,true)
--print(re)
local dat=HS:JSONDecode(re)
local id
for i,v in next,dat do
if v.name==LabelName then
id=v.id
break
end
end
return id
end
--[[
GET /1/boards/[board_id]/lists
Required permissions: read
Arguments
cards (optional)
Default: none
Valid Values: One of:
all
closed
none
open
visible
card_fields (optional)
Default: all
Valid Values: all or a comma-separated list of:
badges
checkItemStates
closed
dateLastActivity
desc
descData
due
email
idAttachmentCover
idBoard
idChecklists
idLabels
idList
idMembers
idMembersVoted
idShort
labels
manualCoverAttachment
name
pos
shortLink
shortUrl
subscribed
url
filter (optional)
Default: open
Valid Values: One of:
all
closed
none
open
fields (optional)
Default: all
Valid Values: all or a comma-separated list of:
closed
idBoard
name
pos
subscribed
--]]--]]
function T:GetListID(name,boardid)
local url
if Private then
getAddon()
url="https://api.trello.com/1/boards/"..boardid.."/lists"..addon
else
getAddon()
url="https://api.trello.com/1/boards/"..boardid.."/lists"..addon
end
local tab=HS:GetAsync(url,true)
local tabl=HS:JSONDecode(tab)
for k,ta in pairs(tabl) do
for p,t in pairs(ta) do
if p=="name" and t==name then
return ta.id
end
end
end
end
--[[
POST /1/lists
Required permissions: write
Arguments
name (required)
Valid Values: a string with a length from 1 to 16384
idBoard (required)
Valid Values: id of the board that the list should be added to
idListSource (optional)
Valid Values: The id of the list to copy into a new list.
pos (optional)
Default: top
Valid Values: A position. top, bottom, or a positive number.
--]]--]]
function T:AddList(...)
local args={...}
local nam,boid,idsource,po
local url
local dat
if #args==2 then
nam,boid=args[1],args[2]
dat={name=nam,idBoard=boid}
elseif #args==3 then
nam,boid,idsource=args[1],args[2],args[3]
dat={name=nam,idBoard=boid,idListSource=idsource}
elseif #args==4 then
nam,boid,idsource,po=args[1],args[2],args[3],args[4]
dat={name=nam,idBoard=boid,idListSource=idsource,pos=po}
else
error("Invalid arguments: "..table.concat(args,","))
end
--
if Private then
getAddon()
url="https://api.trello.com/1/lists"..addon
else
getAddon()
url="https://api.trello.com/1/lists"..addon
end
local data=HS:JSONEncode(dat)
local re=HS:PostAsync(url,data)
return re.id
end
--[[
EXAMPLE:
function cardAdded(card)
print(card.name)
end
local api=require(script.Parent.TrelloAPI)
local boardid=api:GetBoardID("TestBoard")--The board id is different from the link you see when you go to a board
local listid=api:GetListID("Testing",boardid)
api.CardAdded(listid):connect(cardAdded)
--]]
function T.CardAdded(ListID,RefreshTimeInSecs,initialIteration)
if RefreshTimeInSecs==nil or RefreshTimeInSecs<30 then
RefreshTimeInSecs=30
end
if initialIteration==nil then
initialIteration=false
end
local Hook={}
local callbackEnded=false
local previousTable={}
if not initialIteration then
previousTable=T:GetCardsInList(ListID)
end
local function refreshCallback(callback)
local newTable=T:GetCardsInList(ListID)
if (#newTable>#previousTable) then
for _,i in next,newTable do
local found=false
for _,v in next,previousTable do
if (v.id==i.id) then
found=true
end
end
if (not found) then
callback(i,ListID)
end
end
end
previousTable=newTable
end
local thread=nil
function Hook:connect(callback)
thread=coroutine.wrap(function(callbackEndedNested,callbackNested)
while ((not callbackEndedNested)) do
local suc,msg = false,""
repeat
suc,msg=pcall(refreshCallback,callbackNested)