matteridge.api

Module Contents

Classes

RetryHTTPClient

An asynchronous HTTP client, with connection pooling, HTTP/2, redirects,

ReplyAPIClient

A Client which has been authenticated for use on secured endpoints

MattermostClient

Functions

call_with_args_or_json_body(func, client, ...)

authenticated_call(func, client[, force_json_decode, ...])

authenticated_call_return_content(func, client[, ...])

paginated(func)

raise_maybe(resp)

get_client_from_registration_form(f, cache)

Attributes

P

T

log

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.

ERROR_TYPES: dict[int, slixmpp.types.ErrorConditions][source]
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”.

DEFAULT_RETRY = 5.0[source]
_update_counters(resp)[source]
Parameters:

resp (httpx.Response)

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 URL

cookies: A dictionary of cookies to be sent with every request

headers: A dictionary of headers to be sent with every request

timeout: 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 the httpx.Client and httpx.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:
async static get_token(base_url, login_id, password)[source]
Parameters:
  • base_url (str)

  • login_id (str)

  • password (str)

async login()[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_users_by_ids(user_ids)[source]
Parameters:

user_ids (list[str])

Return type:

list[mattermost_api_reference_client.models.User]

async get_username_by_user_id(user_id)[source]
Parameters:

user_id (str)

Return type:

str

async get_user_id_by_username(username)[source]
Parameters:

username (str)

Return type:

str

async get_other_username_from_direct_channel_id(channel_id)[source]
Parameters:

channel_id (str)

Return type:

Optional[str]

async __get_other_user_id_from_direct_channel_name(channel)[source]
Parameters:

channel (mattermost_api_reference_client.models.Channel)

async get_channels()[source]
Return type:

list[mattermost_api_reference_client.models.Channel]

async get_contacts()[source]
async send_message_to_user(username, text, thread=None)[source]
Parameters:
  • username (str)

  • text (str)

  • thread (Optional[str])

Return type:

str

async send_message_to_user_id(user_id, text, thread=None)[source]
Parameters:
  • user_id (str)

  • text (str)

  • thread (Optional[str])

Return type:

str

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 send_message_to_channel(channel_id, text, thread=None)[source]
Parameters:
  • channel_id (str)

  • text (str)

  • thread (Optional[str])

async send_message_with_file(channel_id, file_id, thread=None)[source]
Parameters:
  • channel_id (str)

  • file_id (str)

async get_direct_channel_id(user_id)[source]
Parameters:

user_id (str)

Return type:

str

async update_post(post_id, body)[source]
Parameters:
async get_latest_post_id_for_channel(channel_id)[source]
Parameters:

channel_id (str)

Return type:

Optional[Union[str, mattermost_api_reference_client.types.Unset]]

async get_posts_for_channel(channel_id, per_page=60, before=None)[source]

Returns posts from the most recent to the oldest one

Parameters:
  • channel_id (str)

  • per_page (Optional[int])

  • before (Optional[Union[str, mattermost_api_reference_client.types.Unset]]) – a msg id, return messages before this one

Return type:

AsyncIterator[mattermost_api_reference_client.models.Post]

:return : posts with decreasing created_at timestamp

async upload_file(channel_id, url, http_response)[source]
Parameters:
  • channel_id (str)

  • url (str)

  • http_response (aiohttp.ClientResponse)

async react(post_id, emoji)[source]
Parameters:
async get_reactions(post_id)[source]
Parameters:

post_id (str)

Return type:

set[tuple[str, str]]

async delete_reaction(post_id, emoji)[source]
Parameters:
async view_channel(channel_id)[source]
Parameters:

channel_id (str)

async set_user_status(status, text=None)[source]
Parameters:
  • status (matteridge.events.StatusType)

  • text (Optional[str])

matteridge.api.P[source]
matteridge.api.T[source]
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:
matteridge.api.log[source]