-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhunter.ex
807 lines (552 loc) · 21.1 KB
/
hunter.ex
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
defmodule Hunter do
@moduledoc """
An Elixir client for Mastodon, a GNU Social compatible micro-blogging service
"""
use Application
@hunter_version Mix.Project.config()[:version]
@doc false
def start(_type, _args) do
children = [
{Finch, name: Mastodon}
]
opts = [strategy: :one_for_one, name: Hunter.Supervisor]
Supervisor.start_link(children, opts)
end
@doc """
Retrieve account of authenticated user
## Parameters
* `conn` - connection credentials
"""
@spec verify_credentials(Hunter.Client.t()) :: Hunter.Account.t()
defdelegate verify_credentials(conn), to: Hunter.Account
@doc """
Make changes to the authenticated user
## Parameters
* `conn` - connection credentials
* `data` - data payload
## Possible keys for payload
* `display_name` - name to display in the user's profile
* `note` - new biography for the user
* `avatar` - base64 encoded image to display as the user's avatar (e.g. `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUoAAADrCAYAAAA...`)
* `header` - base64 encoded image to display as the user's header image (e.g. `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUoAAADrCAYAAAA...`)
"""
@spec update_credentials(Hunter.Client.t(), map) :: Hunter.Account.t()
defdelegate update_credentials(conn, data), to: Hunter.Account
@doc """
Retrieve account
## Parameters
* `conn` - connection credentials
* `id` - account identifier
"""
@spec account(Hunter.Client.t(), non_neg_integer) :: Hunter.Account.t()
defdelegate account(conn, id), to: Hunter.Account
@doc """
Get a list of followers
## Parameters
* `conn` - connection credentials
* `id` - account identifier
* `options` - options list
## Options
* `max_id` - get a list of followers with id less than or equal this value
* `since_id` - get a list of followers with id greater than this value
* `limit` - maximum number of followers to get, default: 40, maximum: 80
"""
@spec followers(Hunter.Client.t(), non_neg_integer, Keyword.t()) :: [Hunter.Account.t()]
defdelegate followers(conn, id, options \\ []), to: Hunter.Account
@doc """
Get a list of followed accounts
## Parameters
* `conn` - connection credentials
* `id` - account identifier
* `options` - options list
## Options
* `max_id` - get a list of followings with id less than or equal this value
* `since_id` - get a list of followings with id greater than this value
* `limit` - maximum number of followings to get, default: 40, maximum: 80
"""
@spec following(Hunter.Client.t(), non_neg_integer, Keyword.t()) :: [Hunter.Account.t()]
defdelegate following(conn, id, options \\ []), to: Hunter.Account
@doc """
Follow a remote user
## Parameters
* `conn` - connection credentials
* `uri` - URI of the remote user, in the format of `username@domain`
"""
@spec follow_by_uri(Hunter.Client.t(), String.t()) :: Hunter.Account.t()
defdelegate follow_by_uri(conn, uri), to: Hunter.Account
@doc """
Search for accounts
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `q`: what to search for
* `limit`: maximum number of matching accounts to return, default: 40
"""
@spec search_account(Hunter.Client.t(), Keyword.t()) :: [Hunter.Account.t()]
defdelegate search_account(conn, options), to: Hunter.Account
@doc """
Retrieve user's blocks
## Parameters
* `conn` - connection credentials
## Options
* `max_id` - get a list of blocks with id less than or equal this value
* `since_id` - get a list of blocks with id greater than this value
* `limit` - maximum number of blocks to get, default: 40, max: 80
"""
@spec blocks(Hunter.Client.t(), Keyword.t()) :: [Hunter.Account.t()]
defdelegate blocks(conn, options \\ []), to: Hunter.Account
@doc """
Retrieve a list of follow requests
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of follow requests with id less than or equal this value
* `since_id` - get a list of follow requests with id greater than this value
* `limit` - maximum number of requests to get, default: 40, max: 80
"""
@spec follow_requests(Hunter.Client.t(), Keyword.t()) :: [Hunter.Account.t()]
defdelegate follow_requests(conn, options \\ []), to: Hunter.Account
@doc """
Retrieve user's mutes
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of mutes with id less than or equal this value
* `since_id` - get a list of mutes with id greater than this value
* `limit` - maximum number of mutes to get, default: 40, max: 80
"""
@spec mutes(Hunter.Client.t(), Keyword.t()) :: [Hunter.Account.t()]
defdelegate mutes(conn, options \\ []), to: Hunter.Account
@doc """
Accepts a follow request
## Parameters
* `conn` - connection credentials
* `id` - follow request id
"""
@spec accept_follow_request(Hunter.Client.t(), non_neg_integer) :: boolean
defdelegate accept_follow_request(conn, id), to: Hunter.Account
@doc """
Rejects a follow request
## Parameters
* `conn` - connection credentials
* `id` - follow request id
"""
@spec reject_follow_request(Hunter.Client.t(), non_neg_integer) :: boolean
defdelegate reject_follow_request(conn, id), to: Hunter.Account
## Application
@doc """
Register a new OAuth client app on the target instance
## Parameters
* `name` - name of your application
* `redirect_uri` - where the user should be redirected after authorization,
default: `urn:ietf:wg:oauth:2.0:oob` (no redirect)
* `scopes` - scope list, see the scope section for more details, default: `read`
* `website` - URL to the homepage of your app, default: `nil`
* `options` - option list
## Scopes
* `read` - read data
* `write` - post statuses and upload media for statuses
* `follow` - follow, unfollow, block, unblock
Multiple scopes can be requested during the authorization phase with the `scope` query param
## Options
* `save?` - persists your application information to a file, so, you can use
them later. default: `false`
* `api_base_url` - specifies if you want to register an application on a
different instance. default: `https://mastodon.social`
"""
@spec create_app(String.t(), String.t(), [String.t()], nil | String.t(), Keyword.t()) ::
Hunter.Application.t() | no_return
defdelegate create_app(
name,
redirect_uri \\ "urn:ietf:wg:oauth:2.0:oob",
scopes \\ ["read"],
website \\ nil,
options \\ []
),
to: Hunter.Application
@doc """
Load persisted application's credentials
## Parameters
* `name` - application's name
"""
@spec load_credentials(String.t()) :: Hunter.Application.t()
defdelegate load_credentials(name), to: Hunter.Application
@doc """
Initializes a client
## Options
* `base_url` - URL of the instance you want to connect to
* `bearer_token` - [String] OAuth access token for your authenticated user
"""
@spec new(Keyword.t()) :: Hunter.Client.t()
defdelegate new(options \\ []), to: Hunter.Client
@doc """
User agent of the client
"""
@spec user_agent() :: String.t()
defdelegate user_agent, to: Hunter.Client
@doc """
Upload a media file
## Parameters
* `conn` - connection credentials
* `file` - media to be uploaded
* `options` - option list
## Options
* `description` - plain-text description of the media for accessibility (max 420 chars)
* `focus` - two floating points, comma-delimited
"""
@spec upload_media(Hunter.Client.t(), Path.t(), Keyword.t()) :: Hunter.Attachment.t()
defdelegate upload_media(conn, file, options \\ []), to: Hunter.Attachment
@doc """
Get the relationships of authenticated user towards given other users
## Parameters
* `conn` - connection credentials
* `id` - list of relationship IDs
"""
@spec relationships(Hunter.Client.t(), [non_neg_integer]) :: [Hunter.Relationship.t()]
defdelegate relationships(conn, ids), to: Hunter.Relationship
@doc """
Follow a user
## Parameters
* `conn` - connection credentials
* `id` - user identifier
"""
@spec follow(Hunter.Client.t(), non_neg_integer) :: Hunter.Relationship.t()
defdelegate follow(conn, id), to: Hunter.Relationship
@doc """
Unfollow a user
## Parameters
* `conn` - connection credentials
* `id` - user identifier
"""
@spec unfollow(Hunter.Client.t(), non_neg_integer) :: Hunter.Relationship.t()
defdelegate unfollow(conn, id), to: Hunter.Relationship
@doc """
Block a user
## Parameters
* `conn` - connection credentials
* `id` - user identifier
"""
@spec block(Hunter.Client.t(), non_neg_integer) :: Hunter.Relationship.t()
defdelegate block(conn, id), to: Hunter.Relationship
@doc """
Unblock a user
* `conn` - connection credentials
* `id` - user identifier
"""
@spec unblock(Hunter.Client.t(), non_neg_integer) :: Hunter.Relationship.t()
defdelegate unblock(conn, id), to: Hunter.Relationship
@doc """
Mute a user
## Parameters
* `conn` - connection credentials
* `id` - user identifier
"""
@spec mute(Hunter.Client.t(), non_neg_integer) :: Hunter.Relationship.t()
defdelegate mute(conn, id), to: Hunter.Relationship
@doc """
Unmute a user
## Parameters
* `conn` - connection credentials
* `id` - user identifier
"""
@spec unmute(Hunter.Client.t(), non_neg_integer) :: Hunter.Relationship.t()
defdelegate unmute(conn, id), to: Hunter.Relationship
@doc """
Search for content
## Parameters
* `conn` - connection credentials
* `q` - the search query
* `options` - option list
## Options
* `resolve` - whether to resolve non-local accounts
"""
@spec search(Hunter.Client.t(), String.t(), Keyword.t()) :: Hunter.Result.t()
defdelegate search(conn, query, options \\ []), to: Hunter.Result
@doc """
Create new status
## Parameters
* `conn` - connection credentials
* `status` - text of the status
* `options` - option list
## Options
* `in_reply_to_id` - local ID of the status you want to reply to
* `media_ids` - list of media IDs to attach to the status (maximum: 4)
* `sensitive` - whether the media of the status is NSFW
* `spoiler_text` - text to be shown as a warning before the actual content
* `visibility` - either `direct`, `private`, `unlisted` or `public`
"""
@spec create_status(Hunter.Client.t(), String.t(), Keyword.t()) :: Hunter.Status.t() | no_return
defdelegate create_status(conn, status, options \\ []), to: Hunter.Status
@doc """
Retrieve status
## Parameters
* `conn` - connection credentials
* `id` - status identifier
"""
@spec status(Hunter.Client.t(), non_neg_integer) :: Hunter.Status.t()
defdelegate status(conn, id), to: Hunter.Status
@doc """
Destroy status
## Parameters
* `conn` - connection credentials
* `id` - status identifier
"""
@spec destroy_status(Hunter.Client.t(), non_neg_integer) :: boolean
defdelegate destroy_status(conn, id), to: Hunter.Status
@doc """
Reblog a status
## Parameters
* `conn` - connection credentials
* `id` - status identifier
"""
@spec reblog(Hunter.Client.t(), non_neg_integer) :: Hunter.Status.t()
defdelegate reblog(conn, id), to: Hunter.Status
@doc """
Undo a reblog of a status
## Parameters
* `conn` - connection credentials
* `id` - status identifier
"""
@spec unreblog(Hunter.Client.t(), non_neg_integer) :: Hunter.Status.t()
defdelegate unreblog(conn, id), to: Hunter.Status
@doc """
Fetch the list of users who reblogged the status.
## Parameters
* `conn` - connection credentials
* `id` - status identifier
* `options` - option list
## Options
* `max_id` - get a list of *reblogged by* ids less than or equal this value
* `since_id` - get a list of *reblogged by* ids greater than this value
* `limit` - maximum number of *reblogged by* to get, default: 40, max: 80
"""
@spec reblogged_by(Hunter.Client.t(), non_neg_integer, Keyword.t()) :: [Hunter.Account.t()]
defdelegate reblogged_by(conn, id, options \\ []), to: Hunter.Account
@doc """
Favorite a status
## Parameters
* `conn` - connection credentials
* `id` - status identifier
"""
@spec favourite(Hunter.Client.t(), non_neg_integer) :: Hunter.Status.t()
defdelegate favourite(conn, id), to: Hunter.Status
@doc """
Undo a favorite of a status
## Parameters
* `conn` - connection credentials
* `id` - status identifier
"""
@spec unfavourite(Hunter.Client.t(), non_neg_integer) :: Hunter.Status.t()
defdelegate unfavourite(conn, id), to: Hunter.Status
@doc """
Fetch a user's favourites
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of favourites with id less than or equal this value
* `since_id` - get a list of favourites with id greater than this value
* `limit` - maximum of favourites to get, default: 20, max: 40
"""
@spec favourites(Hunter.Client.t(), Keyword.t()) :: [Hunter.Status.t()]
defdelegate favourites(conn, options \\ []), to: Hunter.Status
@doc """
Fetch the list of users who favourited the status
## Parameters
* `conn` - connection credentials
* `id` - status identifier
* `options` - option list
## Options
* `max_id` - get a list of *favourited by* ids less than or equal this value
* `since_id` - get a list of *favourited by* ids greater than this value
* `limit` - maximum number of *favourited by* to get, default: 40, max: 80
"""
@spec favourited_by(Hunter.Client.t(), non_neg_integer, Keyword.t()) :: [Hunter.Account.t()]
defdelegate favourited_by(conn, id, options \\ []), to: Hunter.Account
@doc """
Get a list of statuses by a user
## Parameters
* `conn` - connection credentials -
* `account_id` - account identifier
* `options` - option list
## Options
* `only_media` - only return `Hunter.Status.t` that have media attachments
* `exclude_replies` - skip statuses that reply to other statuses
* `max_id` - get a list of statuses with id less than or equal this value
* `since_id` - get a list of statuses with id greater than this value
* `limit` - maximum number of statuses to get, default: 20, max: 40
"""
@spec statuses(Hunter.Client.t(), non_neg_integer, Keyword.t()) :: [Hunter.Status.t()]
defdelegate statuses(conn, account_id, options \\ []), to: Hunter.Status
@doc """
Retrieve statuses from the home timeline
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of timelines with id less than or equal this value
* `since_id` - get a list of timelines with id greater than this value
* `limit` - maximum number of statuses on the requested timeline to get, default: 20, max: 40
"""
@spec home_timeline(Hunter.Client.t(), Keyword.t()) :: [Hunter.Status.t()]
defdelegate home_timeline(conn, options \\ []), to: Hunter.Status
@doc """
Retrieve statuses from the public timeline
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `local` - only return statuses originating from this instance
* `max_id` - get a list of timelines with id less than or equal this value
* `since_id` - get a list of timelines with id greater than this value
* `limit` - maximum number of statuses on the requested timeline to get, default: 20, max: 40
"""
@spec public_timeline(Hunter.Client.t(), Keyword.t()) :: [Hunter.Status.t()]
defdelegate public_timeline(conn, options \\ []), to: Hunter.Status
@doc """
Retrieve statuses from a hashtag
## Parameters
* `conn` - connection credentials
* `hashtag` - string list
* `options` - option list
## Options
* `local` - only return statuses originating from this instance
* `max_id` - get a list of timelines with id less than or equal this value
* `since_id` - get a list of timelines with id greater than this value
* `limit` - maximum number of statuses on the requested timeline to get, default: 20, max: 40
"""
@spec hashtag_timeline(Hunter.Client.t(), [String.t()], Keyword.t()) :: [Hunter.Status.t()]
defdelegate hashtag_timeline(conn, hashtag, options \\ []), to: Hunter.Status
@doc """
Retrieve instance information
## Parameters
* `conn` - connection credentials
"""
@spec instance_info(Hunter.Client.t()) :: Hunter.Instance.t()
defdelegate instance_info(conn), to: Hunter.Instance
@doc """
Retrieve user's notifications
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of notifications with id less than or equal this value
* `since_id` - get a list of notifications with id greater than this value
* `limit` - maximum number of notifications to get, default: 15, max: 30
"""
@spec notifications(Hunter.Client.t(), Keyword.t()) :: [Hunter.Notification.t()]
defdelegate notifications(conn, options \\ []), to: Hunter.Notification
@doc """
Retrieve single notification
## Parameters
* `conn` - connection credentials
* `id` - notification identifier
"""
@spec notification(Hunter.Client.t(), non_neg_integer) :: Hunter.Notification.t()
defdelegate notification(conn, id), to: Hunter.Notification
@doc """
Deletes all notifications from the Mastodon server for the authenticated user
## Parameters
* `conn` - connection credentials
"""
@spec clear_notifications(Hunter.Client.t()) :: boolean
defdelegate clear_notifications(conn), to: Hunter.Notification
@doc """
Dismiss a single notification
## Parameters
* `conn` - connection credentials
* `id` - notification id
"""
@spec clear_notification(Hunter.Client.t(), non_neg_integer) :: boolean
defdelegate clear_notification(conn, id), to: Hunter.Notification
@doc """
Retrieve a user's reports
## Parameters
* `conn` - connection credentials
"""
@spec reports(Hunter.Client.t()) :: [Hunter.Report.t()]
defdelegate reports(conn), to: Hunter.Report
@doc """
Report a user
## Parameters
* `conn` - connection credentials
* `account_id` - the ID of the account to report
* `status_ids` - the IDs of statuses to report
* `comment` - a comment to associate with the report
"""
@spec report(Hunter.Client.t(), non_neg_integer, [non_neg_integer], String.t()) ::
Hunter.Report.t()
defdelegate report(conn, account_id, status_ids, comment), to: Hunter.Report
@doc """
Retrieve status context
## Parameters
* `conn` - connection credentials
* `id` - status identifier
"""
@spec status_context(Hunter.Client.t(), non_neg_integer) :: Hunter.Context.t()
defdelegate status_context(conn, id), to: Hunter.Context
@doc """
Retrieve a card associated with a status
## Parameters
* `conn` - connection credentials
* `id` - status id
"""
@spec card_by_status(Hunter.Client.t(), non_neg_integer) :: Hunter.Card.t()
defdelegate card_by_status(conn, id), to: Hunter.Card
@doc """
Retrieve access token
## Parameters
* `app` - application details, see: `Hunter.Application.create_app/5` for more details.
* `username` - account's email
* `password` - account's password
* `base_url` - API base url, default: `https://mastodon.social`
"""
@spec log_in(Hunter.Application.t(), String.t(), String.t(), String.t()) :: Hunter.Client.t()
defdelegate log_in(app, username, password, base_url \\ "https://mastodon.social"),
to: Hunter.Client
@doc """
Retrieve access token via OAuth
## Parameters
* `app` - application details, see: `Hunter.Application.create_app/5` for more details.
* `oauth_code` - OAuth authentication code
* `base_url` - API base url, default: `https://mastodon.social`
"""
@spec log_in_oauth(Hunter.Application.t(), String.t(), String.t()) :: Hunter.Client.t()
defdelegate log_in_oauth(app, oauth_code, base_url \\ "https://mastodon.social"),
to: Hunter.Client
@doc """
Fetch user's blocked domains
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of blocks with id less than or equal this value
* `since_id` - get a list of blocks with id greater than this value
* `limit` - maximum number of blocks to get, default: 40, max: 80
"""
defdelegate blocked_domains(conn, options \\ []), to: Hunter.Domain
@doc """
Block a domain
## Parameters
* `conn` - connection credentials
* `domain` - domain to block
"""
@spec block_domain(Hunter.Client.t(), String.t()) :: boolean()
defdelegate block_domain(conn, domain), to: Hunter.Domain
@doc """
Unblock a domain
## Parameters
* `conn` - connection credentials
* `domain` - domain to unblock
"""
@spec unblock_domain(Hunter.Client.t(), String.t()) :: boolean()
defdelegate unblock_domain(conn, domain), to: Hunter.Domain
@doc """
Returns Hunter version
"""
@spec version() :: String.t()
def version, do: @hunter_version
end