mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-09 16:38:50 +00:00
Add stickers endpoint for search (#2483)
This commit is contained in:
parent
acef0ab5cc
commit
b5ab2ee676
@ -14,6 +14,16 @@ class GiphyBridge extends BridgeAbstract {
|
|||||||
'exampleValue' => 'bird',
|
'exampleValue' => 'bird',
|
||||||
'required' => true
|
'required' => true
|
||||||
),
|
),
|
||||||
|
'noGif' => array(
|
||||||
|
'name' => 'Without gifs',
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'title' => 'Exclude gifs from the results'
|
||||||
|
),
|
||||||
|
'noStick' => array(
|
||||||
|
'name' => 'Without stickers',
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'title' => 'Exclude stickers from the results'
|
||||||
|
),
|
||||||
'n' => array(
|
'n' => array(
|
||||||
'name' => 'max number of returned items (max 50)',
|
'name' => 'max number of returned items (max 50)',
|
||||||
'type' => 'number',
|
'type' => 'number',
|
||||||
@ -21,25 +31,8 @@ class GiphyBridge extends BridgeAbstract {
|
|||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
public function collectData() {
|
protected function getGiphyItems($entries){
|
||||||
/**
|
foreach($entries as $entry) {
|
||||||
* This uses a public beta key which has severe rate limiting.
|
|
||||||
*
|
|
||||||
* https://giphy.api-docs.io/1.0/welcome/access-and-api-keys
|
|
||||||
* https://giphy.api-docs.io/1.0/gifs/search-1
|
|
||||||
*/
|
|
||||||
$apiKey = 'dc6zaTOxFJmzC';
|
|
||||||
$limit = min($this->getInput('n') ?: 10, 50);
|
|
||||||
$uri = sprintf(
|
|
||||||
'https://api.giphy.com/v1/gifs/search?q=%s&limit=%s&api_key=%s',
|
|
||||||
rawurlencode($this->getInput('s')),
|
|
||||||
$limit,
|
|
||||||
$apiKey
|
|
||||||
);
|
|
||||||
|
|
||||||
$result = json_decode(getContents($uri));
|
|
||||||
|
|
||||||
foreach($result->data as $entry) {
|
|
||||||
$createdAt = new \DateTime($entry->import_datetime);
|
$createdAt = new \DateTime($entry->import_datetime);
|
||||||
|
|
||||||
$this->items[] = array(
|
$this->items[] = array(
|
||||||
@ -59,6 +52,38 @@ class GiphyBridge extends BridgeAbstract {
|
|||||||
HTML
|
HTML
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function collectData() {
|
||||||
|
/**
|
||||||
|
* This uses a public beta key which has severe rate limiting.
|
||||||
|
*
|
||||||
|
* https://giphy.api-docs.io/1.0/welcome/access-and-api-keys
|
||||||
|
* https://giphy.api-docs.io/1.0/gifs/search-1
|
||||||
|
*/
|
||||||
|
$apiKey = 'dc6zaTOxFJmzC';
|
||||||
|
$limit = min($this->getInput('n') ?: 10, 50);
|
||||||
|
$endpoints = array();
|
||||||
|
if (empty($this->getInput('noGif'))) {
|
||||||
|
$endpoints[] = 'gifs';
|
||||||
|
}
|
||||||
|
if (empty($this->getInput('noStick'))) {
|
||||||
|
$endpoints[] = 'stickers';
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($endpoints as $endpoint) {
|
||||||
|
$uri = sprintf(
|
||||||
|
'https://api.giphy.com/v1/%s/search?q=%s&limit=%s&api_key=%s',
|
||||||
|
$endpoint,
|
||||||
|
rawurlencode($this->getInput('s')),
|
||||||
|
$limit,
|
||||||
|
$apiKey
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = json_decode(getContents($uri));
|
||||||
|
|
||||||
|
$this->getGiphyItems($result->data);
|
||||||
|
}
|
||||||
|
|
||||||
usort($this->items, function ($a, $b) {
|
usort($this->items, function ($a, $b) {
|
||||||
return $a['timestamp'] < $b['timestamp'];
|
return $a['timestamp'] < $b['timestamp'];
|
||||||
|
Loading…
Reference in New Issue
Block a user