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,6 +8,7 @@ Here's some general stuff to keep in mind, and some work that needs to be done
* GET /api/v1/reports
* POST /api/v1/reports
* GET /api/v1/statuses/:id/card
* PATCH /api/v1/accounts/update_credentials
* Documentation that needs to be updated:
* Toot dicts are missing some fields (cards, applications, visibility)

Veure arxiu

@ -11,24 +11,24 @@ Mastodon.py
'''
Mastodon.create_app(
'pytooterapp',
to_file = 'pytooter_clientcred.txt'
to_file = 'pytooter_clientcred.secret'
)
'''
# 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(
'my_login_email@example.com',
'incrediblygoodpassword',
to_file = 'pytooter_usercred.txt'
to_file = 'pytooter_usercred.secret'
)
'''
# Create actual instance
mastodon = Mastodon(
client_id = 'pytooter_clientcred.txt',
access_token = 'pytooter_usercred.txt'
client_id = 'pytooter_clientcred.secret',
access_token = 'pytooter_usercred.secret'
)
mastodon.toot('Tooting from python!')
@ -330,6 +330,7 @@ These functions allow you to interact with other accounts: To (un)follow and
(un)block.
.. automethod:: Mastodon.account_follow
.. automethod:: Mastodon.follows
.. automethod:: Mastodon.account_unfollow
.. automethod:: Mastodon.account_block
.. 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']):
"""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:
client_id = self.client_id
@ -155,9 +154,6 @@ class Mastodon:
code = None, redirect_uri = "urn:ietf:wg:oauth:2.0:oob", refresh_token = None,\
scopes = ['read', 'write', 'follow'], to_file = None):
"""
Docs: https://github.com/doorkeeper-gem/doorkeeper/wiki/Interacting-as-an-OAuth-client-with-Doorkeeper
Notes:
Your username is the e-mail you use to log in into mastodon.
Can persist access token to file, to be used in the constructor.
@ -169,8 +165,9 @@ class Mastodon:
Will throw a MastodonIllegalArgumentError if username / password
are wrong, scopes are not valid or granted scopes differ from requested.
Returns:
str @access_token
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:
params = self.__generate_params(locals(), ['scopes', 'to_file', 'code', 'refresh_token'])
@ -383,15 +380,6 @@ class Mastodon:
params = self.__generate_params(locals(), ['id'])
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):
"""
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")
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):
"""
Unfollow a user.