dolibarr 21.0.0-alpha
RedditHandler Class Reference

Class for handler Reddit. More...

Public Member Functions

 __construct (array $authParams)
 Constructor to initialize RedditHandler.
 
 fetch ($urlAPI, $maxNb=5, $cacheDelay=60, $cacheDir='', $authParams=[])
 Fetch Reddit API to retrieve posts.
 
 normalizeData ($postData)
 Normalize the data fetched from the Reddit API.
 
 getPosts ()
 Get the list of retrieved posts.
 
 getAuthUrl ()
 Get url for authenticate with Reddit.
 

Private Member Functions

 authenticate ()
 Authenticate with Reddit to get an access token.
 
 formatDate ($dateString)
 Format date for normalize date.
 

Detailed Description

Class for handler Reddit.

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

Constructor & Destructor Documentation

◆ __construct()

RedditHandler::__construct ( array $authParams)

Constructor to initialize RedditHandler.

Parameters
array$authParamsArray containing 'client_id', 'client_secret', 'username', and 'password'.

Definition at line 82 of file reddithandler.class.php.

Member Function Documentation

◆ authenticate()

RedditHandler::authenticate ( )
private

Authenticate with Reddit to get an access token.

Returns
bool True if authentication was successful, false otherwise.

Definition at line 96 of file reddithandler.class.php.

References getAuthUrl(), and getURLContent().

Referenced by fetch().

◆ fetch()

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

Fetch Reddit API to retrieve posts.

Parameters
string$urlAPIURL of the Reddit API to retrieve posts.
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$authParamsAuthentication parameters (not used in this context).
Returns
array|false Array of posts if successful, false otherwise.

Definition at line 139 of file reddithandler.class.php.

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

◆ formatDate()

RedditHandler::formatDate ( $dateString)
private

Format date for normalize date.

Parameters
string | int$dateStringDate in string format or timestamp.
Returns
string Formatted date.

Definition at line 230 of file reddithandler.class.php.

References dol_print_date().

Referenced by normalizeData().

◆ getAuthUrl()

RedditHandler::getAuthUrl ( )

Get url for authenticate with Reddit.

Returns
string Url of Reddit to get access token

Definition at line 250 of file reddithandler.class.php.

Referenced by authenticate().

◆ getPosts()

RedditHandler::getPosts ( )

Get the list of retrieved posts.

Returns
array List of posts.

Definition at line 241 of file reddithandler.class.php.

◆ normalizeData()

RedditHandler::normalizeData ( $postData)

Normalize the data fetched from the Reddit API.

Parameters
array$postDataData of a single post.
Returns
array Normalized post data.

Definition at line 210 of file reddithandler.class.php.

References formatDate().

Referenced by fetch().


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