class RedditHandler (View source)

Class for handler Reddit

Properties

string $error

Methods

__construct(array $authParams)

Constructor to initialize RedditHandler.

array<array{id: string, content: string, created_at: string, url: string, author_name?: string, author_avatar?: string, media_url?: string}|array{}>|false
fetch(string $urlAPI, int $maxNb = 5, int $cacheDelay = 60, string $cacheDir = '', array{client_id?: string, client_secret?: string, username?: string, password?: string, name_app?: string} $authParams = [])

Fetch Reddit API to retrieve posts.

array{}|array{id: string, content: string, created_at: string, url: string, media_url: string}
normalizeData(array{id?: string, title?: string, created?: string, permalink?: string, thumbnail?: string} $postData)

Normalize the data fetched from the Reddit API.

array<array{id: string, content: string, created_at: string, url: string, author_name: string, author_avatar?: string}|array{}>
getPosts()

Get the list of retrieved posts.

string
getAuthUrl()

Get url for authenticate with Reddit

Details

__construct(array $authParams)

Constructor to initialize RedditHandler.

Parameters

array $authParams

Array containing 'client_id', 'client_secret', 'username', and 'password'.

array<array{id: string, content: string, created_at: string, url: string, author_name?: string, author_avatar?: string, media_url?: string}|array{}>|false fetch(string $urlAPI, int $maxNb = 5, int $cacheDelay = 60, string $cacheDir = '', array{client_id?: string, client_secret?: string, username?: string, password?: string, name_app?: string} $authParams = [])

Fetch Reddit API to retrieve posts.

Parameters

string $urlAPI

URL of the Reddit API to retrieve posts.

int $maxNb

Maximum number of posts to retrieve (default is 5).

int $cacheDelay

Number of seconds to use cached data (0 to disable caching).

string $cacheDir

Directory 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).

Return Value

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.

array{}|array{id: string, content: string, created_at: string, url: string, media_url: string} normalizeData(array{id?: string, title?: string, created?: string, permalink?: string, thumbnail?: string} $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.

Return Value

array{}|array{id: string, content: string, created_at: string, url: string, media_url: string}

Normalized post data.

array<array{id: string, content: string, created_at: string, url: string, author_name: string, author_avatar?: string}|array{}> getPosts()

Get the list of retrieved posts.

Return Value

array<array{id: string, content: string, created_at: string, url: string, author_name: string, author_avatar?: string}|array{}>

Posts fetched from the API

string getAuthUrl()

Get url for authenticate with Reddit

Return Value

string

Url of Reddit to get access token