This commit is contained in:
Alex McGivern 2017-04-26 13:13:17 +01:00
commit 00998d6d46
S'han modificat 3 arxius amb 31 adicions i 32 eliminacions

Veure arxiu

@ -8,11 +8,12 @@ Here's some general stuff to keep in mind, and some work that needs to be done
* GET /api/v1/reports * GET /api/v1/reports
* POST /api/v1/reports * POST /api/v1/reports
* GET /api/v1/statuses/:id/card * GET /api/v1/statuses/:id/card
* PATCH /api/v1/accounts/update_credentials
* Documentation that needs to be updated: * Documentation that needs to be updated:
* Toot dicts are missing some fields (cards, applications, visibility) * Toot dicts are missing some fields (cards, applications, visibility)
* Some others probably are missing stuff also * Some others probably are missing stuff also
* Other things missing: * Other things missing:
* Transparent as well as explicit pagination support * Transparent as well as explicit pagination support
* Tests (long-term goal) * Tests (long-term goal)

Veure arxiu

@ -11,24 +11,24 @@ Mastodon.py
''' '''
Mastodon.create_app( Mastodon.create_app(
'pytooterapp', 'pytooterapp',
to_file = 'pytooter_clientcred.txt' to_file = 'pytooter_clientcred.secret'
) )
''' '''
# Log in - either every time, or use persisted # Log in - either every time, or use persisted
''' '''
mastodon = Mastodon(client_id = 'pytooter_clientcred.txt') mastodon = Mastodon(client_id = 'pytooter_clientcred.secret')
mastodon.log_in( mastodon.log_in(
'my_login_email@example.com', 'my_login_email@example.com',
'incrediblygoodpassword', 'incrediblygoodpassword',
to_file = 'pytooter_usercred.txt' to_file = 'pytooter_usercred.secret'
) )
''' '''
# Create actual instance # Create actual instance
mastodon = Mastodon( mastodon = Mastodon(
client_id = 'pytooter_clientcred.txt', client_id = 'pytooter_clientcred.secret',
access_token = 'pytooter_usercred.txt' access_token = 'pytooter_usercred.secret'
) )
mastodon.toot('Tooting from python!') mastodon.toot('Tooting from python!')
@ -329,7 +329,8 @@ Writing data: Accounts
These functions allow you to interact with other accounts: To (un)follow and These functions allow you to interact with other accounts: To (un)follow and
(un)block. (un)block.
.. automethod:: Mastodon.account_follow .. automethod:: Mastodon.account_follow
.. automethod:: Mastodon.follows
.. automethod:: Mastodon.account_unfollow .. automethod:: Mastodon.account_unfollow
.. automethod:: Mastodon.account_block .. automethod:: Mastodon.account_block
.. automethod:: Mastodon.account_unblock .. automethod:: Mastodon.account_unblock

Veure arxiu

@ -134,7 +134,6 @@ class Mastodon:
def auth_request_url(self, client_id = None, redirect_uris = "urn:ietf:wg:oauth:2.0:oob", scopes = ['read', 'write', 'follow']): def auth_request_url(self, client_id = None, redirect_uris = "urn:ietf:wg:oauth:2.0:oob", scopes = ['read', 'write', 'follow']):
"""Returns the url that a client needs to request the grant from the server. """Returns the url that a client needs to request the grant from the server.
https://mastodon.social/oauth/authorize?client_id=XXX&response_type=code&redirect_uris=YYY&scope=read+write+follow
""" """
if client_id is None: if client_id is None:
client_id = self.client_id client_id = self.client_id
@ -155,22 +154,20 @@ class Mastodon:
code = None, redirect_uri = "urn:ietf:wg:oauth:2.0:oob", refresh_token = None,\ code = None, redirect_uri = "urn:ietf:wg:oauth:2.0:oob", refresh_token = None,\
scopes = ['read', 'write', 'follow'], to_file = None): scopes = ['read', 'write', 'follow'], to_file = None):
""" """
Docs: https://github.com/doorkeeper-gem/doorkeeper/wiki/Interacting-as-an-OAuth-client-with-Doorkeeper Your username is the e-mail you use to log in into mastodon.
Notes: Can persist access token to file, to be used in the constructor.
Your username is the e-mail you use to log in into mastodon.
Supports refresh_token but Mastodon.social doesn't implement it at the moment.
Can persist access token to file, to be used in the constructor.
Supports refresh_token but Mastodon.social doesn't implement it at the moment.
Handles password, authorization_code, and refresh_token authentication.
Will throw a MastodonIllegalArgumentError if username / password
are wrong, scopes are not valid or granted scopes differ from requested.
Returns: Handles password, authorization_code, and refresh_token authentication.
str @access_token
Will throw a MastodonIllegalArgumentError if username / password
are wrong, scopes are not valid or granted scopes differ from requested.
For OAuth2 documentation, compare https://github.com/doorkeeper-gem/doorkeeper/wiki/Interacting-as-an-OAuth-client-with-Doorkeeper
Returns the access token.
""" """
if username is not None and password is not None: if username is not None and password is not None:
params = self.__generate_params(locals(), ['scopes', 'to_file', 'code', 'refresh_token']) params = self.__generate_params(locals(), ['scopes', 'to_file', 'code', 'refresh_token'])
@ -383,15 +380,6 @@ class Mastodon:
params = self.__generate_params(locals(), ['id']) params = self.__generate_params(locals(), ['id'])
return self.__api_request('GET', '/api/v1/accounts/' + str(id) + '/followers', params) return self.__api_request('GET', '/api/v1/accounts/' + str(id) + '/followers', params)
def follows(self, uri):
"""
Follow a remote user by uri (username@domain).
Returns a user dict.
"""
params = self.__generate_params(locals())
return self.__api_request('POST', '/api/v1/follows', params)
def account_relationships(self, id): def account_relationships(self, id):
""" """
Fetch relationships (following, followed_by, blocking) of the logged in user to Fetch relationships (following, followed_by, blocking) of the logged in user to
@ -600,6 +588,15 @@ class Mastodon:
""" """
return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/follow") return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/follow")
def follows(self, uri):
"""
Follow a remote user by uri (username@domain).
Returns a user dict.
"""
params = self.__generate_params(locals())
return self.__api_request('POST', '/api/v1/follows', params)
def account_unfollow(self, id): def account_unfollow(self, id):
""" """
Unfollow a user. Unfollow a user.