|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class Mastodon |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md |
|
6
|
|
|
* @link https://github.com/tootsuite/documentation/blob/master/Using-the-API/OAuth-details.md |
|
7
|
|
|
* |
|
8
|
|
|
* @filesource Mastodon.php |
|
9
|
|
|
* @created 19.08.2018 |
|
10
|
|
|
* @package chillerlan\OAuth\Providers\Mastodon |
|
11
|
|
|
* @author smiley <[email protected]> |
|
12
|
|
|
* @copyright 2018 smiley |
|
13
|
|
|
* @license MIT |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace chillerlan\OAuth\Providers\Mastodon; |
|
17
|
|
|
|
|
18
|
|
|
use chillerlan\OAuth\Core\{CSRFToken, OAuth2Provider, TokenRefresh}; |
|
19
|
|
|
use chillerlan\OAuth\OAuthException; |
|
20
|
|
|
|
|
21
|
|
|
use function parse_url; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @method \Psr\Http\Message\ResponseInterface acceptFollowRequest(string $request_id) |
|
25
|
|
|
* @method \Psr\Http\Message\ResponseInterface addListMembers(string $list_id, array $body = ['account_ids']) |
|
26
|
|
|
* @method \Psr\Http\Message\ResponseInterface addPushSubscription(array $body = ['subscription', 'data']) |
|
27
|
|
|
* @method \Psr\Http\Message\ResponseInterface block(string $account_id) |
|
28
|
|
|
* @method \Psr\Http\Message\ResponseInterface blockDomain(array $body = ['domain']) |
|
29
|
|
|
* @method \Psr\Http\Message\ResponseInterface boost(string $toot_id) |
|
30
|
|
|
* @method \Psr\Http\Message\ResponseInterface clearNotifications() |
|
31
|
|
|
* @method \Psr\Http\Message\ResponseInterface createApp(array $body = ['client_name', 'redirect_uris', 'scopes', 'website']) |
|
32
|
|
|
* @method \Psr\Http\Message\ResponseInterface createAttachment(array $body = ['file', 'description', 'focus']) |
|
33
|
|
|
* @method \Psr\Http\Message\ResponseInterface createFilter(array $body = ['phrase', 'context', 'irreversible', 'whole_word', 'expires_in']) |
|
34
|
|
|
* @method \Psr\Http\Message\ResponseInterface createList(array $body = ['title']) |
|
35
|
|
|
* @method \Psr\Http\Message\ResponseInterface deleteFilter(string $filter_id) |
|
36
|
|
|
* @method \Psr\Http\Message\ResponseInterface deleteFollowSuggestion(string $account_id) |
|
37
|
|
|
* @method \Psr\Http\Message\ResponseInterface deleteList(string $list_id) |
|
38
|
|
|
* @method \Psr\Http\Message\ResponseInterface deletePushSubscription() |
|
39
|
|
|
* @method \Psr\Http\Message\ResponseInterface deleteToot(string $toot_id) |
|
40
|
|
|
* @method \Psr\Http\Message\ResponseInterface dismissNotification(array $body = ['notification_id']) |
|
41
|
|
|
* @method \Psr\Http\Message\ResponseInterface favourite(string $toot_id) |
|
42
|
|
|
* @method \Psr\Http\Message\ResponseInterface follow(string $account_id, array $params = ['reblogs']) |
|
43
|
|
|
* @method \Psr\Http\Message\ResponseInterface follows(array $body = ['uri']) |
|
44
|
|
|
* @method \Psr\Http\Message\ResponseInterface getAccount(string $account_id) |
|
45
|
|
|
* @method \Psr\Http\Message\ResponseInterface getCurrentUser() |
|
46
|
|
|
* @method \Psr\Http\Message\ResponseInterface getCurrentUserBlocks(array $params = ['max_id', 'since_id', 'limit']) |
|
47
|
|
|
* @method \Psr\Http\Message\ResponseInterface getCurrentUserDomainBlocks(array $params = ['max_id', 'since_id', 'limit']) |
|
48
|
|
|
* @method \Psr\Http\Message\ResponseInterface getCurrentUserRelationships(array $params = ['account_id']) |
|
49
|
|
|
* @method \Psr\Http\Message\ResponseInterface getFilter(string $filter_id) |
|
50
|
|
|
* @method \Psr\Http\Message\ResponseInterface getFilters() |
|
51
|
|
|
* @method \Psr\Http\Message\ResponseInterface getFollowRequests(array $params = ['max_id', 'since_id', 'limit']) |
|
52
|
|
|
* @method \Psr\Http\Message\ResponseInterface getFollowSuggestions() |
|
53
|
|
|
* @method \Psr\Http\Message\ResponseInterface getFollowers(string $account_id, array $params = ['max_id', 'since_id', 'limit']) |
|
54
|
|
|
* @method \Psr\Http\Message\ResponseInterface getFollowing(string $account_id, array $params = ['max_id', 'since_id', 'limit']) |
|
55
|
|
|
* @method \Psr\Http\Message\ResponseInterface getHomeTimeline(array $params = ['local', 'only_media', 'max_id', 'since_id', 'limit']) |
|
56
|
|
|
* @method \Psr\Http\Message\ResponseInterface getInstance() |
|
57
|
|
|
* @method \Psr\Http\Message\ResponseInterface getInstanceCustomEmojis() |
|
58
|
|
|
* @method \Psr\Http\Message\ResponseInterface getList(string $list_id) |
|
59
|
|
|
* @method \Psr\Http\Message\ResponseInterface getListMembers(string $list_id, array $params = ['max_id', 'since_id', 'limit']) |
|
60
|
|
|
* @method \Psr\Http\Message\ResponseInterface getListTimeline(string $list_id, array $params = ['local', 'only_media', 'max_id', 'since_id', 'limit']) |
|
61
|
|
|
* @method \Psr\Http\Message\ResponseInterface getLists() |
|
62
|
|
|
* @method \Psr\Http\Message\ResponseInterface getListsByMembership(string $account_id) |
|
63
|
|
|
* @method \Psr\Http\Message\ResponseInterface getMutes(string $list_id, array $params = ['max_id', 'since_id', 'limit']) |
|
64
|
|
|
* @method \Psr\Http\Message\ResponseInterface getNotification(string $notification_id) |
|
65
|
|
|
* @method \Psr\Http\Message\ResponseInterface getNotifications(string $list_id, array $params = ['exclude_types', 'max_id', 'since_id', 'limit']) |
|
66
|
|
|
* @method \Psr\Http\Message\ResponseInterface getPublicTimeline(array $params = ['local', 'only_media', 'max_id', 'since_id', 'limit']) |
|
67
|
|
|
* @method \Psr\Http\Message\ResponseInterface getPushSubscriptionStatus() |
|
68
|
|
|
* @method \Psr\Http\Message\ResponseInterface getReports() |
|
69
|
|
|
* @method \Psr\Http\Message\ResponseInterface getStatuses(string $account_id, array $params = ['only_media', 'pinned', 'exclude_replies', 'max_id', 'since_id', 'limit']) |
|
70
|
|
|
* @method \Psr\Http\Message\ResponseInterface getTagTimeline(string $hashtag, array $params = ['local', 'only_media', 'max_id', 'since_id', 'limit']) |
|
71
|
|
|
* @method \Psr\Http\Message\ResponseInterface getToot(string $toot_id) |
|
72
|
|
|
* @method \Psr\Http\Message\ResponseInterface getTootBoostedBy(string $toot_id, array $params = ['max_id', 'since_id', 'limit']) |
|
73
|
|
|
* @method \Psr\Http\Message\ResponseInterface getTootCard(string $toot_id) |
|
74
|
|
|
* @method \Psr\Http\Message\ResponseInterface getTootContext(string $toot_id) |
|
75
|
|
|
* @method \Psr\Http\Message\ResponseInterface getTootFavouritedBy(string $toot_id, array $params = ['max_id', 'since_id', 'limit']) |
|
76
|
|
|
* @method \Psr\Http\Message\ResponseInterface mute(string $account_id, array $body = ['notifications']) |
|
77
|
|
|
* @method \Psr\Http\Message\ResponseInterface muteToot(string $toot_id) |
|
78
|
|
|
* @method \Psr\Http\Message\ResponseInterface pinToot(string $toot_id) |
|
79
|
|
|
* @method \Psr\Http\Message\ResponseInterface rejectFollowRequest(string $request_id) |
|
80
|
|
|
* @method \Psr\Http\Message\ResponseInterface removeListMembers(string $list_id, array $body = ['account_ids']) |
|
81
|
|
|
* @method \Psr\Http\Message\ResponseInterface report(array $body = ['account_id', 'status_ids', 'comment']) |
|
82
|
|
|
* @method \Psr\Http\Message\ResponseInterface search(array $params = ['q', 'resolve']) |
|
83
|
|
|
* @method \Psr\Http\Message\ResponseInterface searchV2(array $params = ['q', 'resolve']) |
|
84
|
|
|
* @method \Psr\Http\Message\ResponseInterface toot(array $body = ['status', 'in_reply_to_id', 'media_ids', 'sensitive', 'spoiler_text', 'visibility', 'language']) |
|
85
|
|
|
* @method \Psr\Http\Message\ResponseInterface unblock(string $account_id) |
|
86
|
|
|
* @method \Psr\Http\Message\ResponseInterface unblockDomain(array $body = ['domain']) |
|
87
|
|
|
* @method \Psr\Http\Message\ResponseInterface unboost(string $toot_id) |
|
88
|
|
|
* @method \Psr\Http\Message\ResponseInterface unfavourite(string $toot_id) |
|
89
|
|
|
* @method \Psr\Http\Message\ResponseInterface unfollow(string $account_id) |
|
90
|
|
|
* @method \Psr\Http\Message\ResponseInterface unmute(string $account_id) |
|
91
|
|
|
* @method \Psr\Http\Message\ResponseInterface unmuteToot(string $toot_id) |
|
92
|
|
|
* @method \Psr\Http\Message\ResponseInterface unpinToot(string $toot_id) |
|
93
|
|
|
* @method \Psr\Http\Message\ResponseInterface updateAttachment(string $attachment_id, array $body = ['description', 'focus']) |
|
94
|
|
|
* @method \Psr\Http\Message\ResponseInterface updateCurrentUser(array $body = ['display_name', 'note', 'avatar', 'header', 'locked', 'source', 'fields_attributes']) |
|
95
|
|
|
* @method \Psr\Http\Message\ResponseInterface updateFilter(string $filter_id, array $body = ['phrase', 'context', 'irreversible', 'whole_word', 'expires_in']) |
|
96
|
|
|
* @method \Psr\Http\Message\ResponseInterface updateList(string $list_id, array $body = ['title']) |
|
97
|
|
|
* @method \Psr\Http\Message\ResponseInterface updatePushSubscription(array $body = ['data']) |
|
98
|
|
|
* @method \Psr\Http\Message\ResponseInterface userSearch(array $params = ['q', 'limit', 'following']) |
|
99
|
|
|
*/ |
|
100
|
|
|
class Mastodon extends OAuth2Provider implements CSRFToken, TokenRefresh{ |
|
101
|
|
|
|
|
102
|
|
|
public const SCOPE_READ = 'read'; |
|
103
|
|
|
public const SCOPE_WRITE = 'write'; |
|
104
|
|
|
public const SCOPE_FOLLOW = 'follow'; |
|
105
|
|
|
public const SCOPE_PUSH = 'push'; |
|
106
|
|
|
|
|
107
|
|
|
protected ?string $endpointMap = MastodonEndpoints::class; |
|
108
|
|
|
protected ?string $apiDocs = 'https://docs.joinmastodon.org/api/guidelines/'; |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* set the internal URLs for the given Mastodon instance |
|
112
|
|
|
* |
|
113
|
|
|
* @param string $instance |
|
114
|
|
|
* |
|
115
|
|
|
* @return \chillerlan\OAuth\Providers\Mastodon\Mastodon |
|
116
|
|
|
* @throws \chillerlan\OAuth\OAuthException |
|
117
|
|
|
*/ |
|
118
|
|
|
public function setInstance(string $instance):Mastodon{ |
|
119
|
|
|
$instance = parse_url($instance); |
|
120
|
|
|
|
|
121
|
|
|
if(!isset($instance['scheme']) || !isset($instance['host'])){ |
|
122
|
|
|
throw new OAuthException('invalid instance URL'); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
// @todo: check if host exists/responds |
|
126
|
|
|
|
|
127
|
|
|
$instance = $instance['scheme'].'://'.$instance['host']; |
|
128
|
|
|
|
|
129
|
|
|
$this->apiURL = $instance.'/api'; |
|
130
|
|
|
$this->authURL = $instance.'/oauth/authorize'; |
|
131
|
|
|
$this->accessTokenURL = $instance.'/oauth/token'; |
|
132
|
|
|
$this->userRevokeURL = $instance.'/oauth/authorized_applications'; |
|
133
|
|
|
$this->applicationURL = $instance.'/settings/applications'; |
|
134
|
|
|
|
|
135
|
|
|
return $this; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
|