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 31 of file reddithandler.class.php.

Constructor & Destructor Documentation

◆ __construct()

RedditHandler::__construct ( array $authParams)

Constructor to initialize RedditHandler.

Parameters
array{client_id?:string,client_secret?:string,username?:string,password?:string,name_app?:string}$authParams Array containing 'client_id', 'client_secret', 'username', and 'password'.

Definition at line 83 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 97 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{client_id?:string,client_secret?:string,username?:string,password?:string,name_app?:string}$authParams Authentication parameters (not used in this context).
Returns
array<array{id:string,content:string,created_at:string,url:string,author_name?:string,author_avatar?:string,media_url?:string}|array{}>|false Array of posts if successful, false otherwise.

Definition at line 140 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 231 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 251 of file reddithandler.class.php.

Referenced by authenticate().

◆ getPosts()

RedditHandler::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 242 of file reddithandler.class.php.

◆ normalizeData()

RedditHandler::normalizeData ( $postData)

Normalize the data fetched from the Reddit API.

Parameters
array{id?:string,title?:string,created?:string,permalink?:string,thumbnail?:string}$postData Data of a single post.
Returns
array{}|array{id:string,content:string,created_at:string,url:string,media_url:string} Normalized post data.

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

References formatDate().

Referenced by fetch().


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