Skip to content

Commit 188e361

Browse files
Allow providing q parameter to Packagist API
1 parent 9844976 commit 188e361

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

app/Console/Commands/RetrieveExtensions.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
use Exception;
1111
use GuzzleHttp\Client;
1212
use GuzzleHttp\Exception\ClientException;
13+
use GuzzleHttp\Utils;
1314
use Illuminate\Console\Command;
1415
use Illuminate\Support\Arr;
1516
use Illuminate\Support\Str;
1617

1718
class RetrieveExtensions extends Command
1819
{
19-
protected $signature = 'extensions:retrieve';
20+
protected $signature = 'extensions:retrieve {q?}';
2021
protected $description = 'Retrieve extensions via Packagist';
2122

2223
protected Client $client;
@@ -34,19 +35,23 @@ public function handle()
3435
{
3536
$url = '/search.json?type=flarum-extension';
3637

38+
if ($this->hasArgument('q')) {
39+
$url .= '&q=' . urlencode($this->argument('q'));
40+
}
41+
3742
while ($url) {
3843
$this->info("Reading $url");
3944

4045
$response = $this->client->get($url);
41-
$data = \GuzzleHttp\json_decode($response->getBody()->getContents(), true);
46+
$data = Utils::jsonDecode($response->getBody()->getContents(), true);
4247

4348
$packages = Arr::get($data, 'results', []);
4449

4550
foreach ($packages as $package) {
4651
$packageName = Arr::get($package, 'name');
4752
$this->info("Saving $packageName");
4853

49-
$details = Arr::get(\GuzzleHttp\json_decode($this->client->get("/packages/$packageName.json")->getBody()->getContents(), true), 'package', []);
54+
$details = Arr::get(Utils::jsonDecode($this->client->get("/packages/$packageName.json")->getBody()->getContents(), true), 'package', []);
5055

5156
$versions = Arr::get($details, 'versions', []);
5257

0 commit comments

Comments
 (0)