forked from willfarrell/alfred-pkgman-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request willfarrell#106 from ajliv/definitely-typed
Add DefinitelyTyped TypeScript definitions search
- Loading branch information
Showing
5 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
namespace WillFarrell\AlfredPkgMan; | ||
|
||
require_once('Cache.php'); | ||
require_once('Repo.php'); | ||
|
||
class DefinitelyTyped extends Repo | ||
{ | ||
protected $id = 'dt'; | ||
protected $url = 'http://definitelytyped.org'; | ||
protected $search_url = 'https://api.npms.io/v2/search?q=scope:types+'; | ||
|
||
public function search($query) | ||
{ | ||
if (!$this->hasMinQueryLength($query)) { | ||
return $this->xml(); | ||
} | ||
|
||
$this->pkgs = $this->cache->get_query_json( | ||
$this->id, | ||
$query, | ||
"{$this->search_url}{$query}&size={$this->max_return}" | ||
); | ||
|
||
foreach($this->pkgs->results as $pkg) { | ||
$p = $pkg->package; | ||
$name = $p->name; | ||
|
||
$this->cache->w->result( | ||
$this->id, | ||
$this->makeArg($name, $p->links->npm, "{$p->name}: {$p->version}"), | ||
$name, | ||
$p->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 DefinitelyTyped(); | ||
// echo $repo->search('react'); |