forked from willfarrell/alfred-pkgman-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNuGet.php
51 lines (42 loc) · 1.45 KB
/
NuGet.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace WillFarrell\AlfredPkgMan;
require_once('Repo.php');
class NuGet extends Repo
{
protected $id = 'nuget';
protected $url = 'https://www.nuget.org';
protected $search_url = 'https://www.nuget.org/packages?q=';
protected $package_url = 'https://www.nuget.org/packages/';
public function search($query)
{
if (!$this->hasMinQueryLength($query)) {
return $this->xml();
}
$this->pkgs = $this->cache->get_query_json(
$this->id,
$query,
"https://api-v2v3search-1.nuget.org/query?q={$query}"
);
foreach ($this->pkgs->data as $pkg) {
$title = $pkg->title;
$version = $pkg->version;
$url = "{$package_url}$pkg->id";
$this->cache->w->result(
$title,
$this->makeArg($title, $url, "nuget {$pkg->id} ~> {$pkg->version}"),
$title,
$pkg->description,
"icon-cache/{$this->id}.png"
);
// only search till max return reached
if (count($this->cache->w->results()) == $this->max_return) {
break;
}
}
$this->noResults($query, "{$this->search_url}{$query}");
return $this->xml();
}
}
// Test code, uncomment to debug this script from the command-line
// $repo = new NuGet();
// echo $repo->search('nhibernate');