Skip to content

Commit

Permalink
[GithubTrendingBridge] Add support for spoken languages (#4149)
Browse files Browse the repository at this point in the history
* [GithubTrendingBridge] Add support for spoken languages

* Update GithubTrendingBridge.php
  • Loading branch information
tillcash authored Jul 28, 2024
1 parent f7ddbcd commit 00d5242
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions bridges/GithubTrendingBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,16 +586,18 @@ class GithubTrendingBridge extends BridgeAbstract
'Monthly' => 'monthly',
],
'defaultValue' => 'today'
],
'spokenLanguage' => [
'name' => 'Spoken Language Code',
'type' => 'text',
'exampleValue' => 'en',
]
]

];

public function collectData()
{
$params = ['since' => urlencode($this->getInput('date_range'))];
$url = self::URI . '/' . $this->getInput('language') . '?' . http_build_query($params);

$url = $this->constructUrl();
$html = getSimpleHTMLDOM($url);

$this->items = [];
Expand Down Expand Up @@ -630,4 +632,32 @@ public function getName()

return parent::getName();
}

private function constructUrl()
{
$url = self::URI;
$language = $this->getInput('language');
$dateRange = $this->getInput('date_range');
$spokenLanguage = $this->getInput('spokenLanguage');

if (!empty($language)) {
$url .= '/' . $language;
}

$queryParams = [];

if (!empty($dateRange)) {
$queryParams['since'] = $dateRange;
}

if (!empty($spokenLanguage)) {
$queryParams['spoken_language_code'] = trim($spokenLanguage);
}

if (!empty($queryParams)) {
$url .= '?' . http_build_query($queryParams);
}

return $url;
}
}

0 comments on commit 00d5242

Please sign in to comment.