-
-
Notifications
You must be signed in to change notification settings - Fork 58
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 #61 from zabirauf/master
Added Hex package manager
- Loading branch information
Showing
8 changed files
with
116 additions
and
4 deletions.
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"version": 2.11, | ||
"version": 2.12, | ||
"download_url": "https://raw.github.com/willfarrell/alfred-pkgman-workflow/master/Package%20Managers.alfredworkflow", | ||
"description": "Package Repo Search" | ||
} |
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.
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,109 @@ | ||
<?php | ||
|
||
/* | ||
Hex | ||
*/ | ||
|
||
// **************** | ||
|
||
require_once('cache.php'); | ||
|
||
class Repo { | ||
|
||
private $id = 'hex'; | ||
private $kind = 'components'; // for none found msg | ||
private $min_query_length = 1; // increase for slow DBs | ||
private $max_return = 25; | ||
|
||
private $cache; | ||
private $w; | ||
private $pkgs; | ||
|
||
function __construct() { | ||
|
||
$this->cache = new Cache(); | ||
|
||
// get DB here if not dynamic search | ||
//$data = (array) $this->cache->get_db('.$this->id.'); | ||
} | ||
|
||
// return id | url | pkgstr | ||
function makeArg($id, $url, $version) { | ||
return $id . "|" . $url . "|" . "\"$id\":\"$version\","; | ||
} | ||
|
||
/*function check($pkg, $query) { | ||
if (!$query) { return true; } | ||
if (strpos($pkg["name"], $query) !== false) { | ||
return true; | ||
} else if (strpos($pkg["description"], $query) !== false) { | ||
return true; | ||
} | ||
return false; | ||
}*/ | ||
|
||
function search($query) { | ||
if ( strlen($query) < $this->min_query_length) { | ||
if ( strlen($query) === 0 ) { return; } | ||
$this->cache->w->result( | ||
"{$this->id}-min", | ||
$query, | ||
"Minimum query length of {$this->min_query_length} not met.", | ||
"", | ||
"icon-cache/{$this->id}.png" | ||
); | ||
return; | ||
} | ||
|
||
$this->pkgs = $this->cache->get_query_json('hex', $query, 'https://hex.pm/api/packages?search='.$query); | ||
|
||
foreach($this->pkgs as $pkg) { | ||
$url = str_replace("api/", "", $pkg->url); | ||
$this->cache->w->result( | ||
$pkg->url, | ||
$this->makeArg($pkg->name, $url, "*"), | ||
$pkg->name, $url, | ||
"icon-cache/{$this->id}.png" | ||
); | ||
|
||
// only search till max return reached | ||
if ( count ( $this->cache->w->results() ) == $this->max_return ) { | ||
break; | ||
} | ||
} | ||
|
||
if ( count( $this->cache->w->results() ) == 0) { | ||
$this->cache->w->result( | ||
"{$this->id}-search", | ||
"https://hex.pm/packages?search={$query}", | ||
"No {$this->kind} were found that matched \"{$query}\"", | ||
"Click to see the results for yourself", | ||
"icon-cache/{$this->id}.png" | ||
); | ||
} | ||
} | ||
|
||
function xml() { | ||
$this->cache->w->result( | ||
"{$this->id}-www", | ||
"http://hex.pm/", | ||
"Go to the website", | ||
"http://hex.pm", | ||
"icon-cache/{$this->id}.png" | ||
); | ||
|
||
return $this->cache->w->toxml(); | ||
} | ||
|
||
} | ||
|
||
// **************** | ||
|
||
/*$query = "leaflet"; | ||
$repo = new Repo(); | ||
$repo->search($query); | ||
echo $repo->xml();*/ | ||
|
||
?> |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"version": 2.03, | ||
"version": 2.04, | ||
"remote_json": "https://raw.githubusercontent.com/willfarrell/alfred-pkgman-workflow/master/current-version.json" | ||
} | ||
} |