dolibarr 21.0.0-beta
DiasporaHandler Class Reference

Class for handling Diaspora API interactions. More...

Public Member Functions

 fetch ($urlAPI, $maxNb=5, $cacheDelay=60, $cacheDir='', $authParams=[])
 Fetch Social Network API to retrieve posts.
 
 normalizeData ($postData)
 Normalize data of retrieved posts.
 
 getPosts ()
 Get the list of retrieved posts.
 

Private Member Functions

 isCookieValid ()
 Check if the provided cookie in params is valid.
 
 getCookieFromParams ()
 Get the cookie value from params, regardless of the exact key name.
 
 formatDate ($dateString)
 Format date for normalize date.
 

Detailed Description

Class for handling Diaspora API interactions.

Definition at line 30 of file diasporahandler.class.php.

Member Function Documentation

◆ fetch()

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

Fetch Social Network API to retrieve posts.

Parameters
string$urlAPIURL of the Diaspora API.
int$maxNbMaximum number of posts to retrieve (default is 5).
int$cacheDelayNumber of seconds to use cached data (0 to disable caching).
string$cacheDirDirectory to store cached data.
array<string,string>$authParams Authentication parameters including login URL, username, and password.
Returns
bool Status code: False if error, true if success.

Definition at line 80 of file diasporahandler.class.php.

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

◆ formatDate()

DiasporaHandler::formatDate ( $dateString)
private

Format date for normalize date.

Parameters
string$dateStringDate in string format.
Returns
string Formatted date.

Definition at line 174 of file diasporahandler.class.php.

References dol_print_date().

Referenced by normalizeData().

◆ getCookieFromParams()

DiasporaHandler::getCookieFromParams ( )
private

Get the cookie value from params, regardless of the exact key name.

Returns
?string The cookie string if found, null otherwise.

Definition at line 60 of file diasporahandler.class.php.

Referenced by fetch(), and isCookieValid().

◆ getPosts()

DiasporaHandler::getPosts ( )

Get the list of retrieved posts.

Returns
array<array{id:string,content:string,created_at:string,url:string,author_name:string,author_avatar?:string}|array{}> Posts fetched from the API

Definition at line 185 of file diasporahandler.class.php.

◆ isCookieValid()

DiasporaHandler::isCookieValid ( )
private

Check if the provided cookie in params is valid.

Returns
bool True if a valid cookie is found in params, false otherwise.

Definition at line 51 of file diasporahandler.class.php.

References getCookieFromParams().

Referenced by fetch().

◆ normalizeData()

DiasporaHandler::normalizeData ( $postData)

Normalize data of retrieved posts.

Parameters
array<string,mixed>$postData Data of a single post.
Returns
array{}|array{id:string,content:string,created_at:string,url:string,author_name:string,author_avatar:string} Normalized post data.

Definition at line 153 of file diasporahandler.class.php.

References formatDate().

Referenced by fetch().


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