dolibarr 21.0.0-alpha
MastodonHandler Class Reference

Class for handler Mastodon. More...

Public Member Functions

 __construct ($authParams)
 Constructor to set the necessary credentials.
 
 fetch ($urlAPI, $maxNb=5, $cacheDelay=60, $cacheDir='', $authParams=[])
 Fetch posts from Mastodon API using the access token.
 
 normalizeData ($postData)
 Normalize data of retrieved posts.
 
 getPosts ()
 Get the list of retrieved posts.
 
 getRedirectUri ()
 Getter for url to redirect.
 
 getAccessToken ()
 Getter for access token.
 
 getClientId ()
 Getter for client Id.
 
 getClientSecret ()
 Getter for secret client.
 

Private Member Functions

 formatDate ($dateString)
 Format date for normalize date.
 

Detailed Description

Class for handler Mastodon.

Definition at line 31 of file mastodonhandler.class.php.

Constructor & Destructor Documentation

◆ __construct()

MastodonHandler::__construct ( $authParams)

Constructor to set the necessary credentials.

Parameters
array$authParamsparameters for authentication

Definition at line 69 of file mastodonhandler.class.php.

Member Function Documentation

◆ fetch()

MastodonHandler::fetch ( $urlAPI,
$maxNb = 5,
$cacheDelay = 60,
$cacheDir = '',
$authParams = [] )

Fetch posts from Mastodon API using the access token.

Parameters
string$urlAPIThe URL of the API endpoint
int$maxNbMaximum number of posts to retrieve
int$cacheDelayCache delay in seconds
string$cacheDirDirectory for caching
array$authParamsAuthentication parameters
Returns
array|false Array of posts if successful, False otherwise

Definition at line 89 of file mastodonhandler.class.php.

References dol_filemtime(), dol_hash(), dol_is_file(), dol_mkdir(), dol_now(), getURLContent(), and normalizeData().

◆ formatDate()

MastodonHandler::formatDate ( $dateString)
private

Format date for normalize date.

Parameters
string$dateStringdate with string format
Returns
string return correct format

Definition at line 175 of file mastodonhandler.class.php.

References dol_print_date().

Referenced by normalizeData().

◆ getAccessToken()

MastodonHandler::getAccessToken ( )

Getter for access token.

Returns
string token

Definition at line 204 of file mastodonhandler.class.php.

◆ getClientId()

MastodonHandler::getClientId ( )

Getter for client Id.

Returns
string client Id

Definition at line 213 of file mastodonhandler.class.php.

◆ getClientSecret()

MastodonHandler::getClientSecret ( )

Getter for secret client.

Returns
string secret client

Definition at line 222 of file mastodonhandler.class.php.

◆ getPosts()

MastodonHandler::getPosts ( )

Get the list of retrieved posts.

Returns
array<array{id:string,content:string,created_at:string,url:string,media_url:string}|array{}> List of posts

Definition at line 186 of file mastodonhandler.class.php.

◆ getRedirectUri()

MastodonHandler::getRedirectUri ( )

Getter for url to redirect.

Returns
string url

Definition at line 195 of file mastodonhandler.class.php.

◆ normalizeData()

MastodonHandler::normalizeData ( $postData)

Normalize data of retrieved posts.

Parameters
array{content?:string,created_at?:string,url?:string,media_attachments?:array<array{url:string}>}$postData post retrieved
Returns
array{id:string,content:string,created_at:string,url:string,media_url:string}|array{} return array with normalized postData

Definition at line 156 of file mastodonhandler.class.php.

References formatDate().

Referenced by fetch().


The documentation for this class was generated from the following file: