diff options
-rw-r--r-- | docs/index.rst | 38 | ||||
-rw-r--r-- | mastodon/Mastodon.py | 8 |
2 files changed, 32 insertions, 14 deletions
diff --git a/docs/index.rst b/docs/index.rst index 63a8594..a8181b1 100644 --- a/docs/index.rst +++ b/docs/index.rst | |||
@@ -112,23 +112,23 @@ Error handling | |||
112 | When Mastodon.py encounters an error, it will raise an exception, generally with | 112 | When Mastodon.py encounters an error, it will raise an exception, generally with |
113 | some text included to tell you what went wrong. | 113 | some text included to tell you what went wrong. |
114 | 114 | ||
115 | The base class that all mastodon exceptions inherit from is the MastodonError | 115 | The base class that all mastodon exceptions inherit from is `MastodonError`. |
116 | class. If you are only interested in the fact an error was raised somewhere in | 116 | If you are only interested in the fact an error was raised somewhere in |
117 | Mastodon.py, and not the details, this is the exception you can catch. | 117 | Mastodon.py, and not the details, this is the exception you can catch. |
118 | 118 | ||
119 | MastodonIllegalArgumentError is generally a programming problem - you asked the | 119 | `MastodonIllegalArgumentError` is generally a programming problem - you asked the |
120 | API to do something obviously invalid (i.e. specify a privacy scope that does | 120 | API to do something obviously invalid (i.e. specify a privacy scope that does |
121 | not exist). | 121 | not exist). |
122 | 122 | ||
123 | MastodonFileNotFoundError and MastodonNetworkError are IO errors - could be you | 123 | `MastodonFileNotFoundError` and `MastodonNetworkError` are IO errors - could be you |
124 | specified a wrong URL, could be the internet is down or your hard drive is | 124 | specified a wrong URL, could be the internet is down or your hard drive is |
125 | dying. They inherit from MastodonIOError, for easy catching. | 125 | dying. They inherit from MastodonIOError, for easy catching. |
126 | 126 | ||
127 | MastodonAPIError is an error returned from the Mastodon instance - the server | 127 | `MastodonAPIError` is an error returned from the Mastodon instance - the server |
128 | has decided it can't fullfill your request (i.e. you requested info on a user that | 128 | has decided it can't fullfill your request (i.e. you requested info on a user that |
129 | does not exist). | 129 | does not exist). |
130 | 130 | ||
131 | MastodonRatelimitError is raised when you hit an API rate limit. You should try | 131 | `MastodonRatelimitError` is raised when you hit an API rate limit. You should try |
132 | again after a while (see the rate limiting section above). | 132 | again after a while (see the rate limiting section above). |
133 | 133 | ||
134 | Return values | 134 | Return values |
@@ -538,10 +538,28 @@ If async is True, the listener will listen on another thread and these methods | |||
538 | will return a handle corresponding to the open connection. The | 538 | will return a handle corresponding to the open connection. The |
539 | connection may be closed at any time by calling its close() method. | 539 | connection may be closed at any time by calling its close() method. |
540 | 540 | ||
541 | .. automethod:: Mastodon.user_stream | 541 | The streaming functions take instances of `StreamListener` as a parameter. |
542 | .. automethod:: Mastodon.public_stream | 542 | A `CallbackStreamListener` class that allows you to specify function callbacks |
543 | .. automethod:: Mastodon.local_stream | 543 | directly is included for convenience. |
544 | .. automethod:: Mastodon.hashtag_stream | 544 | |
545 | .. automethod:: Mastodon.stream_user | ||
546 | .. automethod:: Mastodon.stream_public | ||
547 | .. automethod:: Mastodon.stream_local | ||
548 | .. automethod:: Mastodon.stream_hashtag | ||
549 | |||
550 | StreamListener | ||
551 | ~~~~~~~~~~~~~~ | ||
552 | |||
553 | .. autoclass:: StreamListener | ||
554 | .. automethod:: StreamListener.on_update | ||
555 | .. automethod:: StreamListener.on_notification | ||
556 | .. automethod:: StreamListener.on_delete | ||
557 | .. automethod:: StreamListener.handle_heartbeat | ||
558 | |||
559 | CallbackStreamListener | ||
560 | ~~~~~~~~~~~~~~~~~~~~~~ | ||
561 | |||
562 | .. autoclass:: CallbackStreamListener | ||
545 | 563 | ||
546 | .. _Mastodon: https://github.com/tootsuite/mastodon | 564 | .. _Mastodon: https://github.com/tootsuite/mastodon |
547 | .. _Mastodon flagship instance: http://mastodon.social/ | 565 | .. _Mastodon flagship instance: http://mastodon.social/ |
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 9b28861..011d731 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -1010,7 +1010,7 @@ class Mastodon: | |||
1010 | ### | 1010 | ### |
1011 | # Streaming | 1011 | # Streaming |
1012 | ### | 1012 | ### |
1013 | def user_stream(self, listener, async=False): | 1013 | def stream_user(self, listener, async=False): |
1014 | """ | 1014 | """ |
1015 | Streams events that are relevant to the authorized user, i.e. home | 1015 | Streams events that are relevant to the authorized user, i.e. home |
1016 | timeline and notifications. 'listener' should be a subclass of | 1016 | timeline and notifications. 'listener' should be a subclass of |
@@ -1018,14 +1018,14 @@ class Mastodon: | |||
1018 | """ | 1018 | """ |
1019 | return self.__stream('/api/v1/streaming/user', listener, async=async) | 1019 | return self.__stream('/api/v1/streaming/user', listener, async=async) |
1020 | 1020 | ||
1021 | def public_stream(self, listener, async=False): | 1021 | def stream_public(self, listener, async=False): |
1022 | """ | 1022 | """ |
1023 | Streams public events. 'listener' should be a subclass of StreamListener | 1023 | Streams public events. 'listener' should be a subclass of StreamListener |
1024 | which will receive callbacks for incoming events. | 1024 | which will receive callbacks for incoming events. |
1025 | """ | 1025 | """ |
1026 | return self.__stream('/api/v1/streaming/public', listener, async=async) | 1026 | return self.__stream('/api/v1/streaming/public', listener, async=async) |
1027 | 1027 | ||
1028 | def local_stream(self, listener, async=False): | 1028 | def stream_local(self, listener, async=False): |
1029 | """ | 1029 | """ |
1030 | Streams local events. 'listener' should be a subclass of StreamListener | 1030 | Streams local events. 'listener' should be a subclass of StreamListener |
1031 | which will receive callbacks for incoming events. | 1031 | which will receive callbacks for incoming events. |
@@ -1033,7 +1033,7 @@ class Mastodon: | |||
1033 | """ | 1033 | """ |
1034 | return self.__stream('/api/v1/streaming/public/local', listener, async=async) | 1034 | return self.__stream('/api/v1/streaming/public/local', listener, async=async) |
1035 | 1035 | ||
1036 | def hashtag_stream(self, tag, listener, async=False): | 1036 | def stream_hashtag(self, tag, listener, async=False): |
1037 | """ | 1037 | """ |
1038 | Returns all public statuses for the hashtag 'tag'. 'listener' should be | 1038 | Returns all public statuses for the hashtag 'tag'. 'listener' should be |
1039 | a subclass of StreamListener which will receive callbacks for incoming | 1039 | a subclass of StreamListener which will receive callbacks for incoming |