diff options
author | Alex McGivern <[email protected]> | 2017-04-26 13:13:17 +0100 |
---|---|---|
committer | Alex McGivern <[email protected]> | 2017-04-26 13:13:17 +0100 |
commit | 00998d6d468f88fd89e4e925f3eac14cd2a0a3d6 (patch) | |
tree | 6c2d9e9de1f4ac2b1e125060d4802a315482fb01 | |
parent | 1deca1c5f6907912a13e4df92b567421f5618d33 (diff) | |
parent | 9766171729a18dd4ee28f09f2dfc150354dfcdc8 (diff) | |
download | mastodon.py-00998d6d468f88fd89e4e925f3eac14cd2a0a3d6.tar.gz |
Merge branch 'master' of https://github.com/halcy/Mastodon.py
-rw-r--r-- | DEVELOPMENT.md | 5 | ||||
-rw-r--r-- | docs/index.rst | 13 | ||||
-rw-r--r-- | mastodon/Mastodon.py | 45 |
3 files changed, 31 insertions, 32 deletions
diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index eea45be..f5d1583 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md | |||
@@ -8,11 +8,12 @@ Here's some general stuff to keep in mind, and some work that needs to be done | |||
8 | * GET /api/v1/reports | 8 | * GET /api/v1/reports |
9 | * POST /api/v1/reports | 9 | * POST /api/v1/reports |
10 | * GET /api/v1/statuses/:id/card | 10 | * GET /api/v1/statuses/:id/card |
11 | 11 | * PATCH /api/v1/accounts/update_credentials | |
12 | |||
12 | * Documentation that needs to be updated: | 13 | * Documentation that needs to be updated: |
13 | * Toot dicts are missing some fields (cards, applications, visibility) | 14 | * Toot dicts are missing some fields (cards, applications, visibility) |
14 | * Some others probably are missing stuff also | 15 | * Some others probably are missing stuff also |
15 | 16 | ||
16 | * Other things missing: | 17 | * Other things missing: |
17 | * Transparent as well as explicit pagination support | 18 | * Transparent as well as explicit pagination support |
18 | * Tests (long-term goal) | 19 | * Tests (long-term goal) |
diff --git a/docs/index.rst b/docs/index.rst index adc2a89..80687de 100644 --- a/docs/index.rst +++ b/docs/index.rst | |||
@@ -11,24 +11,24 @@ Mastodon.py | |||
11 | ''' | 11 | ''' |
12 | Mastodon.create_app( | 12 | Mastodon.create_app( |
13 | 'pytooterapp', | 13 | 'pytooterapp', |
14 | to_file = 'pytooter_clientcred.txt' | 14 | to_file = 'pytooter_clientcred.secret' |
15 | ) | 15 | ) |
16 | ''' | 16 | ''' |
17 | 17 | ||
18 | # Log in - either every time, or use persisted | 18 | # Log in - either every time, or use persisted |
19 | ''' | 19 | ''' |
20 | mastodon = Mastodon(client_id = 'pytooter_clientcred.txt') | 20 | mastodon = Mastodon(client_id = 'pytooter_clientcred.secret') |
21 | mastodon.log_in( | 21 | mastodon.log_in( |
22 | '[email protected]', | 22 | '[email protected]', |
23 | 'incrediblygoodpassword', | 23 | 'incrediblygoodpassword', |
24 | to_file = 'pytooter_usercred.txt' | 24 | to_file = 'pytooter_usercred.secret' |
25 | ) | 25 | ) |
26 | ''' | 26 | ''' |
27 | 27 | ||
28 | # Create actual instance | 28 | # Create actual instance |
29 | mastodon = Mastodon( | 29 | mastodon = Mastodon( |
30 | client_id = 'pytooter_clientcred.txt', | 30 | client_id = 'pytooter_clientcred.secret', |
31 | access_token = 'pytooter_usercred.txt' | 31 | access_token = 'pytooter_usercred.secret' |
32 | ) | 32 | ) |
33 | mastodon.toot('Tooting from python!') | 33 | mastodon.toot('Tooting from python!') |
34 | 34 | ||
@@ -329,7 +329,8 @@ Writing data: Accounts | |||
329 | These functions allow you to interact with other accounts: To (un)follow and | 329 | These functions allow you to interact with other accounts: To (un)follow and |
330 | (un)block. | 330 | (un)block. |
331 | 331 | ||
332 | .. automethod:: Mastodon.account_follow | 332 | .. automethod:: Mastodon.account_follow |
333 | .. automethod:: Mastodon.follows | ||
333 | .. automethod:: Mastodon.account_unfollow | 334 | .. automethod:: Mastodon.account_unfollow |
334 | .. automethod:: Mastodon.account_block | 335 | .. automethod:: Mastodon.account_block |
335 | .. automethod:: Mastodon.account_unblock | 336 | .. automethod:: Mastodon.account_unblock |
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 919825a..2e557e4 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -134,7 +134,6 @@ class Mastodon: | |||
134 | 134 | ||
135 | def auth_request_url(self, client_id = None, redirect_uris = "urn:ietf:wg:oauth:2.0:oob", scopes = ['read', 'write', 'follow']): | 135 | def auth_request_url(self, client_id = None, redirect_uris = "urn:ietf:wg:oauth:2.0:oob", scopes = ['read', 'write', 'follow']): |
136 | """Returns the url that a client needs to request the grant from the server. | 136 | """Returns the url that a client needs to request the grant from the server. |
137 | https://mastodon.social/oauth/authorize?client_id=XXX&response_type=code&redirect_uris=YYY&scope=read+write+follow | ||
138 | """ | 137 | """ |
139 | if client_id is None: | 138 | if client_id is None: |
140 | client_id = self.client_id | 139 | client_id = self.client_id |
@@ -155,22 +154,20 @@ class Mastodon: | |||
155 | code = None, redirect_uri = "urn:ietf:wg:oauth:2.0:oob", refresh_token = None,\ | 154 | code = None, redirect_uri = "urn:ietf:wg:oauth:2.0:oob", refresh_token = None,\ |
156 | scopes = ['read', 'write', 'follow'], to_file = None): | 155 | scopes = ['read', 'write', 'follow'], to_file = None): |
157 | """ | 156 | """ |
158 | Docs: https://github.com/doorkeeper-gem/doorkeeper/wiki/Interacting-as-an-OAuth-client-with-Doorkeeper | 157 | Your username is the e-mail you use to log in into mastodon. |
159 | 158 | ||
160 | Notes: | 159 | Can persist access token to file, to be used in the constructor. |
161 | Your username is the e-mail you use to log in into mastodon. | 160 | |
162 | 161 | Supports refresh_token but Mastodon.social doesn't implement it at the moment. | |
163 | Can persist access token to file, to be used in the constructor. | 162 | |
164 | 163 | Handles password, authorization_code, and refresh_token authentication. | |
165 | Supports refresh_token but Mastodon.social doesn't implement it at the moment. | 164 | |
166 | 165 | Will throw a MastodonIllegalArgumentError if username / password | |
167 | Handles password, authorization_code, and refresh_token authentication. | 166 | are wrong, scopes are not valid or granted scopes differ from requested. |
168 | |||
169 | Will throw a MastodonIllegalArgumentError if username / password | ||
170 | are wrong, scopes are not valid or granted scopes differ from requested. | ||
171 | 167 | ||
172 | Returns: | 168 | For OAuth2 documentation, compare https://github.com/doorkeeper-gem/doorkeeper/wiki/Interacting-as-an-OAuth-client-with-Doorkeeper |
173 | str @access_token | 169 | |
170 | Returns the access token. | ||
174 | """ | 171 | """ |
175 | if username is not None and password is not None: | 172 | if username is not None and password is not None: |
176 | params = self.__generate_params(locals(), ['scopes', 'to_file', 'code', 'refresh_token']) | 173 | params = self.__generate_params(locals(), ['scopes', 'to_file', 'code', 'refresh_token']) |
@@ -383,15 +380,6 @@ class Mastodon: | |||
383 | params = self.__generate_params(locals(), ['id']) | 380 | params = self.__generate_params(locals(), ['id']) |
384 | return self.__api_request('GET', '/api/v1/accounts/' + str(id) + '/followers', params) | 381 | return self.__api_request('GET', '/api/v1/accounts/' + str(id) + '/followers', params) |
385 | 382 | ||
386 | def follows(self, uri): | ||
387 | """ | ||
388 | Follow a remote user by uri (username@domain). | ||
389 | |||
390 | Returns a user dict. | ||
391 | """ | ||
392 | params = self.__generate_params(locals()) | ||
393 | return self.__api_request('POST', '/api/v1/follows', params) | ||
394 | |||
395 | def account_relationships(self, id): | 383 | def account_relationships(self, id): |
396 | """ | 384 | """ |
397 | Fetch relationships (following, followed_by, blocking) of the logged in user to | 385 | Fetch relationships (following, followed_by, blocking) of the logged in user to |
@@ -600,6 +588,15 @@ class Mastodon: | |||
600 | """ | 588 | """ |
601 | return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/follow") | 589 | return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/follow") |
602 | 590 | ||
591 | def follows(self, uri): | ||
592 | """ | ||
593 | Follow a remote user by uri (username@domain). | ||
594 | |||
595 | Returns a user dict. | ||
596 | """ | ||
597 | params = self.__generate_params(locals()) | ||
598 | return self.__api_request('POST', '/api/v1/follows', params) | ||
599 | |||
603 | def account_unfollow(self, id): | 600 | def account_unfollow(self, id): |
604 | """ | 601 | """ |
605 | Unfollow a user. | 602 | Unfollow a user. |