wordpress_client module#
- class wordpress_client.WP_Client(url: str, user: str, password: str, verify_requests: bool = True)[source]#
Bases:
object
This client allows to connect and authenticate with wordpress’s rest API.
- Args:
url (str): The URL of the website. user (str): The user we will use to authenticate. password (str): The API password generated for this application. verify_requests (bool): Whether to verify SSL reequests or not.
- check_credentials() bool [source]#
Checks if the credentials are correct.
- Returns:
bool: True if login was successful, False if login was not successful.
- discord_link(discord_id: str, link_token: str)[source]#
Link a discord account to a wordpress account using a link token.
- Args:
discord_id (str): The ID of the discord account. link_token (str): The link token used to link the accounts.
- discord_unlink(discord_id: str)[source]#
Unlink a discord account from the wordpress account it’s linked with.
- Args:
discord_id (str): The ID of the discord account we want to unlink.
- execute_and_check_errors(endpoint: str, action: str, parameters: list[str]) dict [source]#
Send a request to the specified endpoint, calling the specified action with the specified parameters.
- Args:
endpoint (str): The endpoint to use. action (str): The action to call. parameters (list[str]): The list with the parameters to pass.
- Raises:
WP_Error: An Error thrown by the API.
- Returns:
dict: A dictionary with the API’s response.
- generate_header(user: str, password: str)[source]#
Generate the authentication header.
- Args:
user (str): The username of the owner of this application. password (str): This application’s password.
- generate_request(endpoint: str, action: str, parameters: list[str]) str [source]#
Generate the link for a rest request.
- Args:
endpoint (str): The name of the endpoint to use. (see the keys of ‘wp_endpoints’ for a list of values) action (str): The name of the action to perform. parameters (list[str]): A list with the parameters that the API needs.
- Returns:
str: A string with the URL that calls the API function.
- get_account_details(discord_id: str) dict [source]#
Get details about the connected account.
- Args:
discord_id (str): The ID of the discord account.
- Returns:
dict: The details of the linked user.
- send_request(URL: str, request_type: str = 'GET', data: dict | None = None) dict [source]#
Send a request of “request_type” to the “URL” with “data” as body.
- Args:
URL (str): The URL that should receive the request. request_type (str, optional): The request type we should send. Defaults to “GET”. data (Optional[dict], optional): The data we want to send. Defaults to None.
- Returns:
dict: A dictionary created from the parsed json.
- token_create() str [source]#
Create a link token for the account we are connected as.
- Returns:
str: The generated link token.