forked from Shinmera/tooter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueries.lisp
754 lines (591 loc) · 30.5 KB
/
queries.lisp
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
#|
This file is a part of Tooter
(c) 2018 Shirakumo http://tymoon.eu ([email protected])
Author: Nicolas Hafner <[email protected]>
|#
(in-package #:org.shirakumo.tooter)
;; application
(defmethod verify-app-credentials ((client client))
(decode-application (query client "/api/v1/apps/verify_credentials")))
;;; Accounts
(defmethod find-account ((client client) (id string))
(decode-account (query client (format NIL "/api/v1/accounts/~a" id))))
(defmethod verify-credentials ((client client))
(setf (account client)
(decode-account (query client "/api/v1/accounts/verify_credentials"))))
(defmethod update-credentials ((client client) &key display-name note avatar header (locked NIL l-p) fields)
(check-type display-name (or null string))
(check-type note (or null string))
(check-type avatar (or null pathname))
(check-type header (or null pathname))
(check-type fields list)
(setf (account client)
(decode-account (apply #'submit client "/api/v1/accounts/update_credentials"
:display-name display-name
:note note
:avatar avatar
:header header
:locked (coerce-boolean locked l-p)
(loop for i from 0
for (key . val) in fields
collect (format NIL "fields_attributes[~a][name]" i)
collect key
collect (format NIL "fields_attributes[~a][value]" i)
collect val)))))
(defmethod get-followers ((client client) (id string) &key max-id since-id limit)
(check-type max-id (or null string))
(check-type since-id (or null string))
(check-type limit (or null (integer 0)))
(decode-account (query client (format NIL "/api/v1/accounts/~a/followers" id)
:max-id max-id
:since-id since-id
:limit limit)))
(defmethod get-followers ((client client) (account account) &rest args)
(apply #'get-followers client (id account) args))
(defmethod get-followers ((client client) (self (eql T)) &rest args)
(apply #'get-followers client (id (account client)) args))
(defmethod get-following ((client client) (id string) &key max-id since-id limit)
(check-type max-id (or null string))
(check-type since-id (or null string))
(check-type limit (or null (integer 0)))
(decode-account (query client (format NIL "/api/v1/accounts/~a/following" id)
:max-id max-id
:since-id since-id
:limit limit)))
(defmethod get-following ((client client) (account account) &rest args)
(apply #'get-following client (id account) args))
(defmethod get-following ((client client) (self (eql T)) &rest args)
(apply #'get-following client (id (account client)) args))
(defmethod get-statuses ((client client) (id string) &key (only-media NIL o-p) (pinned NIL p-p) (exclude-replies NIL e-p) max-id since-id limit)
(check-type max-id (or null string))
(check-type since-id (or null string))
(check-type limit (or null (integer 0)))
(decode-status (query client (format NIL "/api/v1/accounts/~a/statuses" id)
:only-media (coerce-boolean only-media o-p)
:pinned (coerce-boolean pinned p-p)
:exclude-replies (coerce-boolean exclude-replies e-p)
:max-id max-id
:since-id since-id
:limit limit)))
(defmethod get-statuses ((client client) (account account) &rest args)
(apply #'get-statuses client (id account) args))
(defmethod get-statuses ((client client) (self (eql T)) &rest args)
(apply #'get-statuses client (id (account client)) args))
;;; Bookmarks
(defmethod bookmarks ((client client) &key max-id since-id min-id (limit 20))
(check-type max-id (or null string))
(check-type since-id (or null string))
(check-type min-id (or null string))
(check-type limit (or null (integer 0)))
(decode-status (query client "/api/v1/bookmarks"
:max-id max-id
:since-id since-id
:min-id min-id
:limit limit)))
(defmethod bookmark ((client client) (id string))
(check-type id string)
(decode-status (submit client (format NIL "/api/v1/statuses/~a/bookmark" id))))
(defmethod bookmark ((client client) (status status))
(bookmark (id status)))
(defmethod unbookmark ((client client) (id string))
(check-type id string)
(decode-status (submit client (format NIL "/api/v1/statuses/~a/unbookmark" id))))
(defmethod unbookmark ((client client) (status status))
(unbookmark (id status)))
;;; Filters
(defmethod filters ((client client))
(decode-filter (query client "/api/v1/filters")))
(defmethod filter ((client client) (id string))
(decode-filter (query client (format NIL "/api/v1/filters/~a" id))))
(defmethod filter ((client client) (filter filter))
(filter client (id filter)))
(defmethod create-filter ((client client) phrase context &key (irreversible NIL i-p) (whole-word NIL w-p) expires-in)
(assert (stringp phrase))
(assert (consp context))
(decode-filter (submit client "/api/v1/filters"
:phrase phrase
:context context
:irreversible (coerce-boolean irreversible i-p)
:whole-word (coerce-boolean whole-word w-p)
:expires-in expires-in)))
(defmethod update-filter ((client client) id phrase context &key (irreversible NIL i-p) (whole-word NIL w-p) expires-in)
(assert (stringp id))
(assert (stringp phrase))
(decode-filter (submit client (format NIL "/api/v1/filters/~a" id)
:http-method :put
:phrase phrase
:context context
:irreversible (coerce-boolean irreversible i-p)
:whole-word (coerce-boolean whole-word w-p)
:expires-in expires-in)))
(defmethod delete-filter ((client client) id)
(assert (stringp id))
(decode-filter (submit client (format NIL "/api/v1/filters/~a" id)
:http-method :delete)))
;;; Follows
(defmethod follow ((client client) (id string))
(decode-relationship (submit client (format NIL "/api/v1/accounts/~a/follow" id))))
(defmethod follow ((client client) (account account))
(follow client (id account)))
(defmethod unfollow ((client client) (id string))
(decode-relationship (submit client (format NIL "/api/v1/accounts/~a/unfollow" id))))
(defmethod unfollow ((client client) (account account))
(unfollow client (id account)))
(defmethod block ((client client) (id string))
(decode-relationship (submit client (format NIL "/api/v1/accounts/~a/block" id))))
(defmethod block ((client client) (account account))
(block client (id account)))
(defmethod unblock ((client client) (id string))
(decode-relationship (submit client (format NIL "/api/v1/accounts/~a/unblock" id))))
(defmethod unblock ((client client) (account account))
(unblock client (id account)))
(defmethod mute ((client client) (id string) &key (notifications T n-p))
(decode-relationship (submit client (format NIL "/api/v1/accounts/~a/mute" id)
:notifications (coerce-boolean notifications n-p))))
(defmethod mute ((client client) (account account) &rest args)
(apply #'mute client (id account) args))
(defmethod unmute ((client client) (id string))
(decode-relationship (submit client (format NIL "/api/v1/accounts/~a/unmute" id))))
(defmethod unmute ((client client) (account account))
(unblock client (id account)))
(defmethod get-activity ((client client))
(decode-activity (query client "/api/v1/instance/activity")))
(defmethod relationships ((client client) (ids cons))
(decode-relationship (query client "/api/v1/accounts/relationships"
:id (loop for id in ids
collect (etypecase id
(account (id id))
(string id))))))
(defmethod relationships ((client client) (account account))
(relationships client (list (id account))))
(defmethod search-accounts ((client client) query &key (limit 40) (following NIL f-p))
(check-type query string)
(check-type limit (or null (integer 0)))
(decode-account (query client "/api/v1/accounts/search"
:q query
:limit limit
:following (coerce-boolean following f-p))))
;;; Blocks
(defmethod blocks ((client client) &key max-id since-id (limit 40))
(check-type max-id (or null string))
(check-type since-id (or null string))
(check-type limit (or null (integer 0)))
(decode-account (query client "/api/v1/blocks"
:max-id max-id
:since-id since-id
:limit limit)))
(defmethod blocked-domains ((client client) &key max-id since-id (limit 40))
(check-type max-id (or null string))
(check-type since-id (or null string))
(check-type limit (or null (integer 0)))
(query client "/api/v1/domain_blocks"
:max-id max-id
:since-id since-id
:limit limit))
(defmethod block ((client client) (domain string))
(submit client "/api/v1/domain_blocks"
:domain domain)
T)
(defmethod unblock ((client client) (domain string))
(submit client "/api/v1/domain_blocks"
:http-method :delete
:domain domain)
T)
;;; Favourites
(defmethod favourites ((client client) &key min-id max-id (limit 20))
(check-type max-id (or null string))
(check-type min-id (or null string))
(check-type limit (or null (integer 0)))
(decode-status (query client "/api/v1/favourites"
:min-id min-id
:max-id max-id
:limit limit)))
;;; Follow Requests
(defmethod follow-requests ((client client) &key max-id since-id (limit 40))
(check-type max-id (or null string))
(check-type since-id (or null string))
(check-type limit (or null (integer 0)))
(decode-account (query client "/api/v1/follow_requests"
:max-id max-id
:since-id since-id
:limit limit)))
(defmethod accept-request ((client client) (id string))
(decode-relationship (submit client (format NIL "/api/v1/follow_requests/~a/authorize" id))))
(defmethod accept-request ((client client) (account account))
(accept-request client (id account)))
(defmethod reject-request ((client client) (id string))
(decode-relationship (submit client (format NIL "/api/v1/follow_requests/~a/reject" id))))
(defmethod reject-request ((client client) (account account))
(reject-request client (id account)))
;;; Instances
(defmethod instance ((client client))
(decode-instance (query client "/api/v1/instance")))
(defmethod peers ((client client))
(query client "/api/v1/instance/peers"))
(defmethod weekly-activity ((client client))
(decode-activity (query client "/api/v1/instance/activity")))
(defmethod emojis ((client client))
(decode-emoji (query client "/api/v1/custom_emojis")))
;;; Lists
(defmethod user-lists ((client client) (id string))
(decode-user-list (query client (format NIL "/api/v1/accounts/~a/lists" id))))
(defmethod user-lists ((client client) (account account))
(user-lists client (id account)))
(defmethod user-lists ((client client) (id (eql T)))
(decode-user-list (query client "/api/v1/lists")))
(defmethod user-list-accounts ((client client) (id string) &key max-id since-id limit)
(check-type max-id (or null string))
(check-type since-id (or null string))
(check-type limit (or null (integer 0)))
(decode-account (query client (format NIL "/api/v1/lists/~a/accounts" id)
:max-id max-id
:since-id since-id
:limit (or limit 0))))
(defmethod user-list-accounts ((client client) (user-list user-list) &rest args)
(apply #'user-list-accounts client (id user-list) args))
;; Convenience.
(defmethod (setf user-list-accounts) (accounts (client client) (id string))
(let* ((accounts (loop for account in accounts
collect (etypecase account
(string account)
(account (id account)))))
(existing (mapcar #'id (user-list-accounts client id)))
(to-remove (set-difference existing accounts))
(to-add (set-difference accounts existing)))
(when to-remove (remove-user-list-accounts client id to-remove))
(when to-add (add-user-list-accounts client id to-add))
accounts))
(defmethod find-list ((client client) (id string))
(decode-user-list (query client (format NIL "/api/v1/lists/~a" id))))
(defmethod make-user-list ((client client) title)
(decode-user-list (submit client "/api/v1/lists"
:title title)))
(defmethod update-user-list ((client client) (id string) &key title)
(check-type title string)
(decode-user-list (submit client (format NIL "/api/v1/lists/~a" id)
:http-method :put
:title title)))
(defmethod update-user-list ((client client) (user-list user-list) &rest args)
(apply #'update-user-list client (id user-list) args))
(defmethod delete-user-list ((client client) (id string))
(submit client (format NIL "/api/v1/lists/~a" id)
:http-method :delete)
T)
(defmethod add-user-list-accounts ((client client) (id string) accounts)
(submit client (format NIL "/api/v1/lists/~a/accounts" id)
:account-ids (loop for account in accounts
collect (etypecase account
(string account)
(account (id account)))))
T)
(defmethod add-user-list-accounts ((client client) (user-list user-list) accounts)
(add-user-list-accounts client (id user-list) accounts))
(defmethod remove-user-list-accounts ((client client) (id string) accounts)
(submit client (format NIL "/api/v1/lists/~a/accounts" id)
:http-method :delete
:account-ids (loop for account in accounts
collect (etypecase account
(string account)
(account (id account)))))
T)
(defmethod remove-user-list-accounts ((client client) (user-list user-list) accounts)
(remove-user-list-accounts client (id user-list) accounts))
;;; Media
(defmethod make-media ((client client) file &key description focus)
(check-type file pathname)
(check-type description (or null string))
(check-type focus (or null cons))
(decode-attachment (submit client "/api/v1/media"
:file file
:description description
:focus (when focus (format NIL "~f,~f" (car focus) (cdr focus))))))
(defmethod update-media ((client client) id &key description focus)
(check-type description (or null string))
(check-type focus (or null cons))
(decode-attachment (submit client (format NIL "/api/v1/media/~a" id)
:description description
:focus (when focus (format NIL "~f,~f" (car focus) (cdr focus))))))
(defmethod update-media ((client client) (attachment attachment) &rest args)
(apply #'update-media client (id attachment) args))
;;; Mutes
(defmethod mutes ((client client) &key max-id since-id (limit 40))
(check-type max-id (or null string))
(check-type since-id (or null string))
(check-type limit (or null (integer 0)))
;; FIXME Link headers
(decode-account (query client "/api/v1/mutes"
:max-id max-id
:since-id since-id
:limit limit)))
;;; Notifications
(defmethod notifications ((client client) &key max-id min-id since-id (limit 15) exclude-types account-id)
(check-type max-id (or null string))
(check-type since-id (or null string))
(check-type limit (or null (integer 0)))
(check-type exclude-types list)
(decode-notification (query client "/api/v1/notifications"
:max-id max-id
:min-id min-id
:since-id since-id
:limit limit
:exclude-types (loop for type in exclude-types
collect (ecase type
(:follow "follow")
(:favourite "favourite")
(:reblog "reblog")
(:mention "mention")
(:poll "poll")))
:account-id account-id)))
(defmethod find-notification ((client client) (id string))
(decode-notification (query client (format NIL "/api/v1/notifications/~a" id))))
(defmethod delete-notification ((client client) (all (eql T)))
(submit client "/api/v1/notifications/clear")
T)
(defmethod delete-notification ((client client) (id string))
(submit client (format nil "/api/v1/notifications/~a/dismiss" id))
T)
(defmethod delete-notification ((client client) (notification notification))
(delete-notification client (id notification)))
(defmethod make-subscription ((client client) endpoint public-key secret &key alerts)
(check-type endpoint string)
(check-type public-key string)
(check-type secret string)
(check-type alerts list)
(decode-push-subscription (apply #'submit client "/api/v1/push/subscription"
"subscription[endpoint]" endpoint
"subscription[keys][p256dh]" public-key
"subscription[keys][auth]" secret
(loop for alert in alerts
collect (ecase alert
(:follows "data[alerts][follow]")
(:favourites "data[alerts][favourite]")
(:reblogs "data[alerts][reblogs]")
(:mentions "data[alerts][mention]")
(:polls "data[alerts][poll]"))
collect "true"))))
(defmethod subscription ((client client))
(decode-push-subscription (query client "/api/v1/push/subscription")))
(defmethod delete-subscription ((client client))
(submit client "/api/v1/push/subscription"
:http-method :delete)
T)
;;; Reports
(defmethod reports ((client client))
(decode-report (query client "/api/v1/reports")))
(defmethod make-report ((client client) (id string) &key statuses comment forward)
(check-type statuses list)
(check-type comment (or null string))
(decode-report (submit client "/api/v1/reports"
:account-id id
:status-ids (loop for status in statuses
collect (etypecase status
(string status)
(status (id status))))
:comment comment
:forward (coerce-boolean forward t))))
(defmethod make-report ((client client) (account account) &rest args)
(apply #'make-report client (id account) args))
;;; Search
(defmethod find-results ((client client) query &key account-id max-id min-id kind (exclude-unreviewed NIL e-p) (resolve NIL r-p) (limit 20) (offset 0) (following NIL f-p))
(check-type account-id (or null string))
(check-type max-id (or null string))
(check-type min-id (or null string))
(check-type kind (or null string))
(decode-results (query client "/api/v2/search"
:q query
:account-id account-id
:max-id max-id
:min-id min-id
:type kind
:exclude-unreviewed (coerce-boolean exclude-unreviewed e-p)
:resolve (coerce-boolean resolve r-p)
:limit limit
:offset offset
:following (coerce-boolean following f-p))))
;;; Statuses
(defmethod find-status ((client client) (id string))
(decode-status (query client (format NIL "/api/v1/statuses/~a" id))))
(defmethod context ((client client) (id string))
(decode-context (query client (format NIL "/api/v1/statuses/~a/context" id))))
(defmethod context ((client client) (status status))
(context client (id status)))
(defmethod card ((client client) (id string))
(decode-card (query client (format NIL "/api/v1/statuses/~a/context" id))))
(defmethod card ((client client) (status status))
(card client (id status)))
(defmethod rebloggers ((client client) (id string) &key max-id since-id (limit 40))
(check-type max-id (or null string))
(check-type since-id (or null string))
(check-type limit (or null (integer 0)))
(decode-account (query client (format NIL "/api/v1/statuses/~a/reblogged_by" id)
:max-id max-id
:since-id since-id
:limit limit)))
(defmethod rebloggers ((client client) (status status) &rest args)
(apply #'rebloggers client (id status) args))
(defmethod favouriters ((client client) (id string) &key max-id since-id (limit 40))
(check-type max-id (or null string))
(check-type since-id (or null string))
(check-type limit (or null (integer 0)))
(decode-account (query client (format NIL "/api/v1/statuses/~a/favourited_by" id)
:max-id max-id
:since-id since-id
:limit limit)))
(defmethod favouriters ((client client) (status status) &rest args)
(apply #'favouriters client (id status) args))
(defmethod make-status ((client client) status &key in-reply-to media (sensitive NIL s-p) spoiler-text visibility language scheduled-at poll-options poll-expire-seconds (poll-multiple NIL m-p) (poll-hide-totals NIL h-p) idempotency-key)
(flet ((ensure-media-id (media)
(etypecase media
(string media)
(attachment (id media))
(pathname (id (make-media client media))))))
(let ((results-entity (submit client "/api/v1/statuses"
:status status
:in-reply-to-id (etypecase in-reply-to
(string in-reply-to)
(status (id in-reply-to))
(null NIL))
:media-ids (typecase media
(null NIL)
(cons (mapcar #'ensure-media-id media))
(T (list (ensure-media-id media))))
:sensitive (coerce-boolean sensitive s-p)
:spoiler-text spoiler-text
:visibility (ecase visibility
((NIL) NIL)
(:direct "direct")
(:private "private")
(:unlisted "unlisted")
(:public "public"))
:language (when language (string language))
:scheduled-at scheduled-at
"poll[options]" poll-options
"poll[expires-in]" poll-expire-seconds
"poll[multiple]" (coerce-boolean poll-multiple m-p)
"poll[hide_totals]" (coerce-boolean poll-hide-totals h-p)
:idempotency-key idempotency-key)))
(if scheduled-at
(decode-scheduled-status results-entity)
(decode-status results-entity)))))
(defmethod delete-status ((client client) (id string))
(submit client (format NIL "/api/v1/statuses/~a" id)
:http-method :delete)
T)
(defmethod delete-status ((client client) (status status))
(delete-status client (id status)))
(defmethod reblog ((client client) (id string))
(decode-status (submit client (format NIL "/api/v1/statuses/~a/reblog" id))))
(defmethod reblog ((client client) (status status))
(reblog client (id status)))
(defmethod unreblog ((client client) (id string))
(decode-status (submit client (format NIL "/api/v1/statuses/~a/unreblog" id))))
(defmethod unreblog ((client client) (status status))
(unreblog client (id status)))
(defmethod favourite ((client client) (id string))
(decode-status (submit client (format NIL "/api/v1/statuses/~a/favourite" id))))
(defmethod favourite ((client client) (status status))
(favourite client (id status)))
(defmethod unfavourite ((client client) (id string))
(decode-status (submit client (format NIL "/api/v1/statuses/~a/unfavourite" id))))
(defmethod unfavourite ((client client) (status status))
(unfavourite client (id status)))
(defmethod endorsements ((client client))
(decode-account (query client "/api/v1/endorsements")))
(defmethod pin ((client client) (id string))
(decode-status (submit client (format NIL "/api/v1/statuses/~a/pin" id))))
(defmethod pin ((client client) (status status))
(pin client (id status)))
(defmethod unpin ((client client) (id string))
(decode-status (submit client (format NIL "/api/v1/statuses/~a/unpin" id))))
(defmethod unpin ((client client) (status status))
(unpin client (id status)))
(defmethod mute-conversation ((client client) (id string))
(decode-status (submit client (format NIL "/api/v1/statuses/~a/mute" id))))
(defmethod mute-conversation ((client client) (status status))
(mute-conversation client (id status)))
(defmethod unmute-conversation ((client client) (id string))
(decode-status (submit client (format NIL "/api/v1/statuses/~a/unmute" id))))
(defmethod unmute-conversation ((client client) (status status))
(mute-conversation client (id status)))
(defmethod mute ((client client) (status status) &key)
(mute-conversation client (id status)))
(defmethod unmute ((client client) (status status))
(unmute-conversation client (id status)))
;;; Timelines
(defun %timeline (client url &key (local NIL l-p) (only-media NIL o-p) max-id since-id min-id (limit 20))
(check-type max-id (or null string))
(check-type since-id (or null string))
(check-type min-id (or null string))
(check-type limit (or null (integer 0)))
(decode-status (query client (format NIL "/api/v1/timelines/~a" url)
:local (coerce-boolean local l-p)
:only-media (coerce-boolean only-media o-p)
:max-id max-id
:since-id since-id
:min-id min-id
:limit limit)))
(defgeneric timeline-tag (client tag &rest args))
(defmethod timeline-tag ((client client) (tag string) &rest args)
(apply #'%timeline client (format NIL "tag/~a" tag) args))
(defgeneric timeline (client kind &key local only-media max-id since-id limit min-id))
(defmethod timeline ((client client) (kind (eql :home)) &rest args)
(apply #'%timeline client "home" args))
(defmethod timeline ((client client) (kind (eql :public)) &rest args)
(apply #'%timeline client "public" args))
(defmethod timeline ((client client) (id string) &rest args)
(apply #'%timeline client (format NIL "list/~a" id) args))
(defmethod timeline ((client client) (tag tag) &rest args)
(apply #'timeline-tag client (name tag) args))
(defmethod timeline ((client client) (user-list user-list) &rest args)
(apply #'timeline client (id user-list) args))
;;; Trends
(defmethod trends ((client client))
(decode-tag (query client "/api/v1/trends")))
;;; Directory
(defmethod account-directory ((client client))
(decode-account (query client "/api/v1/directory")))
;;; Conversations
(defgeneric conversations (client &key limit max-id since-id min-id))
(defmethod conversations ((client client) &key (limit 20) max-id since-id min-id)
(decode-conversation (query client "/api/v1/conversations"
:max-id max-id
:since-id since-id
:min-id min-id
:limit limit)))
(defmethod delete-conversation ((client client) (id string))
(query client
(format NIL "/api/v1/conversations/~a" id)
:http-method :delete))
(defmethod mark-read-conversation ((client client) (id string))
(decode-conversation (submit client
(format NIL "/api/v1/conversations/~a/read" id))))
;;; Polls
(defmethod polls ((client client) (id string))
(decode-poll (query client (format NIL "/api/v1/polls/~a" id))))
(defmethod polls ((client client) (poll poll))
(polls client (id poll)))
(defmethod poll-vote ((client client) (id string) (choices list))
(assert (every #'stringp choices))
(assert (every (lambda (a) (parse-integer a :junk-allowed t)) choices))
(decode-poll (submit client (format NIL "/api/v1/polls/~a/votes" id)
"choices" choices)))
(defmethod poll-vote ((client client) (poll poll) choices)
(poll-vote client (id poll) choices))
;;; Markers
(defmethod markers ((client client) (timeline list))
(decode-marker (query client "/api/v1/markers/"
:timeline timeline)))
(defmethod save-markers ((client client) &key last-status-read last-notification-read)
(decode-marker (submit client "/api/v1/markers/"
"home[last_read_id]" last-status-read
"notifications[last_read_id]" last-notification-read)))
;;; Identity proof
(defmethod identity-proof ((client client) (provider string) (username string))
(query client "/api/proofs"
:provider provider
:username username))
(defmethod oembed ((client client) (url string) &key (max-width 400) max-height)
(query client "/api/oembed"
:url url
:maxwidth max-width
:maxheight max-height))