diff options
-rw-r--r-- | docs/index.rst | 130 | ||||
-rw-r--r-- | mastodon/Mastodon.py | 2 |
2 files changed, 116 insertions, 16 deletions
diff --git a/docs/index.rst b/docs/index.rst index 2780eaa..06c3678 100644 --- a/docs/index.rst +++ b/docs/index.rst | |||
@@ -1,25 +1,125 @@ | |||
1 | .. py:currentmodule:: mastodon | ||
2 | .. py:class:: Mastodon | ||
3 | |||
4 | Mastodon.py | 1 | Mastodon.py |
5 | =========== | 2 | =========== |
6 | 3 | ||
7 | App creation and auth | 4 | .. code-block:: python |
8 | --------------------- | 5 | |
6 | from mastodon import Mastodon | ||
7 | |||
8 | # Register app - only once! | ||
9 | ''' | ||
10 | Mastodon.create_app( | ||
11 | 'pytooterapp', | ||
12 | to_file = 'pytooter_clientcred.txt' | ||
13 | ) | ||
14 | ''' | ||
15 | |||
16 | # Log in - either every time, or use persisted | ||
17 | ''' | ||
18 | mastodon = Mastodon(client_id = 'pytooter_clientcred.txt') | ||
19 | mastodon.log_in( | ||
20 | 'pytooter', | ||
21 | 'incrediblygoodpassword', | ||
22 | to_file = 'pytooter_usercred.txt' | ||
23 | ) | ||
24 | ''' | ||
25 | |||
26 | # Create actual instance | ||
27 | mastodon = Mastodon( | ||
28 | client_id = 'pytooter_clientcred.txt', | ||
29 | access_token = 'pytooter_usercred.txt' | ||
30 | ) | ||
31 | mastodon.toot('Tooting from python!') | ||
9 | 32 | ||
10 | Before you can use the mastodon API, you have to register your application (which gets you a client key and client secret) | 33 | `Mastodon`_ is an ostatus based twitter-like federated social |
11 | and then log in (which gets you an access token). These functions allow you to do those things. | 34 | network node. It has an API that allows you to interact with its |
12 | For convenience, once you have a client id, secret and access token, you can simply pass them to the constructor of the class, too! | 35 | every aspect. This is a simple python wrapper for that api, provided |
36 | as a single python module. By default, it talks to the | ||
37 | `Mastodon flagship instance`_, but it can be set to talk to any | ||
38 | node running Mastodon. | ||
13 | 39 | ||
14 | Note that while it is perfectly reasonable to log back in whenever your app starts, registering a new application on every | 40 | For complete documentation on what every function returns, |
15 | startup is not, so don't do that - instead, register an application once, and then persist your client id and secret. Convenience | 41 | check the `Mastodon API docs`_, or just play around a bit. |
42 | |||
43 | .. py:module:: mastodon | ||
44 | .. py:class: Mastodon | ||
45 | |||
46 | App registration and user authentication | ||
47 | ---------------------------------------- | ||
48 | Before you can use the mastodon API, you have to register your | ||
49 | application (which gets you a client key and client secret) | ||
50 | and then log in (which gets you an access token). These functions | ||
51 | allow you to do those things. | ||
52 | For convenience, once you have a client id, secret and access token, | ||
53 | you can simply pass them to the constructor of the class, too! | ||
54 | |||
55 | Note that while it is perfectly reasonable to log back in whenever | ||
56 | your app starts, registering a new application on every | ||
57 | startup is not, so don't do that - instead, register an application | ||
58 | once, and then persist your client id and secret. Convenience | ||
16 | methods for this are provided. | 59 | methods for this are provided. |
17 | 60 | ||
18 | .. autofunction:: create_app | 61 | .. automethod:: Mastodon.create_app |
19 | .. automethod:: __init__ | 62 | .. automethod:: Mastodon.__init__ |
20 | .. automethod:: log_in | 63 | .. automethod:: Mastodon.log_in |
64 | |||
65 | Reading data: Timelines | ||
66 | ----------------------- | ||
67 | This function allows you to access the timelines a logged in | ||
68 | user could see, as well as hashtag timelines and the public timeline. | ||
69 | |||
70 | .. automethod:: Mastodon.timeline | ||
71 | |||
72 | Reading data: Statuses | ||
73 | ---------------------- | ||
74 | These functions allow you to get information about single statuses. | ||
75 | |||
76 | .. automethod:: Mastodon.status | ||
77 | .. automethod:: Mastodon.status_context | ||
78 | .. automethod:: Mastodon.status_reblogged_by | ||
79 | .. automethod:: Mastodon.status_favourited_by | ||
80 | |||
81 | Reading data: Accounts | ||
82 | ---------------------- | ||
83 | These functions allow you to get information about accounts and | ||
84 | their relationships. | ||
85 | |||
86 | .. automethod:: Mastodon.account | ||
87 | .. automethod:: Mastodon.account_statuses | ||
88 | .. automethod:: Mastodon.account_following | ||
89 | .. automethod:: Mastodon.account_followers | ||
90 | .. automethod:: Mastodon.account_relationships | ||
91 | .. automethod:: Mastodon.account_suggestions | ||
92 | .. automethod:: Mastodon.account_search | ||
93 | |||
94 | Writing data: Statuses | ||
95 | ---------------------- | ||
96 | These functions allow you to post statuses to Mastodon and to | ||
97 | interact with already posted statuses. | ||
98 | |||
99 | .. automethod:: Mastodon.status_post | ||
100 | .. automethod:: Mastodon.toot | ||
101 | .. automethod:: Mastodon.status_delete | ||
102 | .. automethod:: Mastodon.status_reblog | ||
103 | .. automethod:: Mastodon.status_unreblog | ||
104 | .. automethod:: Mastodon.status_favourite | ||
105 | .. automethod:: Mastodon.status_unfavourite | ||
106 | |||
107 | Writing data: Accounts | ||
108 | ---------------------- | ||
109 | These functions allow you to interact with other accounts: To (un)follow and | ||
110 | (un)block. | ||
21 | 111 | ||
22 | Reading timelines | 112 | .. automethod:: Mastodon.account_follow |
23 | ----------------- | 113 | .. automethod:: Mastodon.account_unfollow |
114 | .. automethod:: Mastodon.account_block | ||
115 | .. automethod:: Mastodon.account_unblock | ||
24 | 116 | ||
117 | Writing data: Media | ||
118 | ------------------- | ||
119 | This function allows you to upload media to Mastodon. Except it | ||
120 | doesn't, because it is currently broken. But it will. | ||
121 | .. automethod:: media_post | ||
25 | 122 | ||
123 | .. _Mastodon: https://github.com/Gargron/mastodon | ||
124 | .. _Mastodon flagship instance: http://mastodon.social/ | ||
125 | .. _Mastodon api docs: https://github.com/Gargron/mastodon/wiki/API | ||
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 8d54455..558d1c1 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -253,7 +253,7 @@ class Mastodon: | |||
253 | return self.__api_request('POST', '/api/v1/statuses/' + str(id) + "/unfavourite") | 253 | return self.__api_request('POST', '/api/v1/statuses/' + str(id) + "/unfavourite") |
254 | 254 | ||
255 | ### | 255 | ### |
256 | # Writing data: Statuses | 256 | # Writing data: Accounts |
257 | ### | 257 | ### |
258 | def account_follow(self, id): | 258 | def account_follow(self, id): |
259 | """ | 259 | """ |