matteridge.api¶
Attributes¶
Exceptions¶
A generic exception that may be raised while processing an XMPP stanza |
Classes¶
An asynchronous HTTP client, with connection pooling, HTTP/2, redirects, |
|
A Client which has been authenticated for use on secured endpoints |
|
Functions¶
|
|
|
|
|
|
|
|
|
|
|
Module Contents¶
- exception matteridge.api.MattermostException(resp)[source]¶
Bases:
slixmpp.exceptions.XMPPError
A generic exception that may be raised while processing an XMPP stanza to indicate that an error response stanza should be sent.
The exception method for stanza objects extending
RootStanza
will create an error stanza and initialize any additional substanzas using the extension information included in the exception.Meant for use in Slixmpp plugins and applications using Slixmpp.
Extension information can be included to add additional XML elements to the generated error stanza.
- Parameters:
condition – The XMPP defined error condition. Defaults to
'undefined-condition'
.text – Human readable text describing the error.
etype – The XMPP error type, such as
'cancel'
or'modify'
. Defaults to'cancel'
.extension – Tag name of the extension’s XML content.
extension_ns – XML namespace of the extensions’ XML content.
extension_args – Content and attributes for the extension element. Same as the additional arguments to the
Element
constructor.clear – Indicates if the stanza’s contents should be removed before replying with an error. Defaults to
True
.resp (mattermost_api_reference_client.types.Response)
Initialize self. See help(type(self)) for accurate signature.
- class matteridge.api.RetryHTTPClient(*a, **k)[source]¶
Bases:
httpx.AsyncClient
An asynchronous HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc.
Usage:
`python >>> async with httpx.AsyncClient() as client: >>> response = await client.get('https://example.org') `
Parameters:
auth - (optional) An authentication class to use when sending
requests. * params - (optional) Query parameters to include in request URLs, as a string, dictionary, or sequence of two-tuples. * headers - (optional) Dictionary of HTTP headers to include when sending requests. * cookies - (optional) Dictionary of Cookie items to include when sending requests. * verify - (optional) SSL certificates (a.k.a CA bundle) used to verify the identity of requested hosts. Either True (default CA bundle), a path to an SSL certificate file, an ssl.SSLContext, or False (which will disable verification). * cert - (optional) An SSL certificate used by the requested host to authenticate the client. Either a path to an SSL certificate file, or two-tuple of (certificate file, key file), or a three-tuple of (certificate file, key file, password). * http2 - (optional) A boolean indicating if HTTP/2 support should be enabled. Defaults to False. * proxies - (optional) A dictionary mapping HTTP protocols to proxy URLs. * timeout - (optional) The timeout configuration to use when sending requests. * limits - (optional) The limits configuration to use. * max_redirects - (optional) The maximum number of redirect responses that should be followed. * base_url - (optional) A URL to use as the base when building request URLs. * transport - (optional) A transport class to use for sending requests over the network. * app - (optional) An ASGI application to send requests to, rather than sending actual network requests. * trust_env - (optional) Enables or disables usage of environment variables for configuration. * default_encoding - (optional) The default encoding to use for decoding response text, if no charset information is included in a response Content-Type header. Set to a callable for automatic character set detection. Default: “utf-8”.
- async request(*a, **k)[source]¶
Build and send a request.
Equivalent to:
`python request = client.build_request(...) response = await client.send(request, ...) `
See AsyncClient.build_request(), AsyncClient.send() and [Merging of configuration][0] for how the various parameters are merged with client-level configuration.
[0]: /advanced/#merging-of-configuration
- Return type:
httpx.Response
- class matteridge.api.ReplyAPIClient(*a, **k)[source]¶
Bases:
mattermost_api_reference_client.client.AuthenticatedClient
A Client which has been authenticated for use on secured endpoints
The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
base_url
: The base URL for the API, all requests are made to a relative path to this URLcookies
: A dictionary of cookies to be sent with every requestheaders
: A dictionary of headers to be sent with every requesttimeout
: The maximum amount of a time a request can take. API functions will raise httpx.TimeoutException if this is exceeded.verify_ssl
: Whether or not to verify the SSL certificate of the API server. This should be True in production, but can be set to False for testing purposes.follow_redirects
: Whether or not to follow redirects. Default value is False.httpx_args
: A dictionary of additional arguments to be passed to thehttpx.Client
andhttpx.AsyncClient
constructor.- Attributes:
- raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
status code that was not documented in the source OpenAPI document. Can also be provided as a keyword argument to the constructor.
token: The token to use for authentication prefix: The prefix to use for the Authorization header auth_header_name: The name of the Authorization header
- class matteridge.api.MattermostClient(base_url, cache, *args, **kwargs)[source]¶
- Parameters:
base_url (str)
cache (matteridge.cache.Cache)
- mm_id: asyncio.Future[str][source]¶
- me: asyncio.Future[mattermost_api_reference_client.models.User][source]¶
- async get_user(user_id)[source]¶
- Parameters:
user_id (str)
- Return type:
mattermost_api_reference_client.models.User
- async get_user_by_username(username)[source]¶
- Parameters:
username (str)
- Return type:
mattermost_api_reference_client.models.User
- async __get_other_user_id_from_direct_channel_name(channel)[source]¶
- Parameters:
channel (mattermost_api_reference_client.models.Channel)
- async __send_or_create_thread(post, thread=None)[source]¶
- Parameters:
post (mattermost_api_reference_client.models.create_post_json_body.CreatePostJsonBody)
thread (Optional[str])
- Return type:
mattermost_api_reference_client.models.Post
- async get_posts_for_channel(channel_id, per_page=60, before=None)[source]¶
Returns posts from the most recent to the oldest one
- Parameters:
- Return type:
AsyncIterator[mattermost_api_reference_client.models.Post]
:return : posts with decreasing created_at timestamp
- async matteridge.api.call_with_args_or_json_body(func, client, use_json_body, *a, **k)[source]¶
- Parameters:
func (Callable[Ellipsis, Awaitable[mattermost_api_reference_client.types.Response[T]]])
use_json_body (bool)
- Return type:
mattermost_api_reference_client.types.Response[T]
- matteridge.api.authenticated_call(func, client, force_json_decode=False, use_json_body=False)[source]¶
- Parameters:
func (Callable[Ellipsis, Awaitable[mattermost_api_reference_client.types.Response[T]]])
client (mattermost_api_reference_client.client.AuthenticatedClient)
- Return type:
Callable[Ellipsis, Awaitable[T]]
- matteridge.api.authenticated_call_return_content(func, client, use_json_body=False, return_none_when_not_found=False)[source]¶
- Parameters:
func (Callable[Ellipsis, Awaitable[mattermost_api_reference_client.types.Response]])
client (mattermost_api_reference_client.client.AuthenticatedClient)
- Return type:
Callable[Ellipsis, Awaitable[bytes]]
- matteridge.api.paginated(func)[source]¶
- Parameters:
func (Callable[Ellipsis, Awaitable[list[T]]])
- Return type:
Callable[Ellipsis, AsyncIterator[T]]
- matteridge.api.raise_maybe(resp)[source]¶
- Parameters:
resp (mattermost_api_reference_client.types.Response)
- matteridge.api.get_client_from_registration_form(f, cache)[source]¶
- Parameters:
cache (matteridge.cache.Cache)