Skip to content
Browse files

Merge pull request #21 from boenrobot/patch-githubAPI

GitHub API fix
  • Loading branch information...
2 parents 017a0e4 + 647e5f5 commit 2ec00fede602f737b1558b57bcfda02fdf0fd0b4 @saltybeagle saltybeagle committed Aug 9, 2012
Showing with 26 additions and 32 deletions.
  1. +26 −32 src/PEAR2Web/Models/Package.php
View
58 src/PEAR2Web/Models/Package.php
@@ -4,41 +4,51 @@
class Package extends \PEAR2\SimpleChannelFrontend\Package
{
- const GIT_HUB_API = 'http://github.com/api/v2/json/issues/list/pear2/';
+ const GIT_HUB_API = 'https://api.github.com/repos/pear2/';
+ const GIT_HUB_LINK = 'https://github.com/pear2/';
- protected $cache = null;
+ protected $cache;
+
+ protected $shortName;
public function __construct($options = array())
{
parent::__construct($options);
$this->cache = new \PEAR2\Cache\Lite\Main();
$this->cache->setLifeTime(15 * 60);
+
+ $this->shortName = str_replace('PEAR2_', '', $this->name, 1);
+ }
+
+ public function getShortName()
+ {
+ return $this->shortName;
}
public function getGitHubNewIssueLink()
{
- return 'https://github.com/pear2/' . str_replace('PEAR2_', '', $this->name) . '/issues/new';
+ return self::GIT_HUB_LINK . $this->shortName . '/issues/new';
}
public function getGitHubOpenIssuesLink()
{
- return 'https://github.com/pear2/' . str_replace('PEAR2_', '', $this->name) . '/issues';
+ return self::GIT_HUB_LINK . $this->shortName . '/issues';
}
public function getGitHubClosedIssuesLink()
{
- return 'https://github.com/pear2/' . str_replace('PEAR2_', '', $this->name) . '/issues?state=closed';
+ return self::GIT_HUB_LINK . $this->shortName . '/issues?state=closed';
}
-
- public function getGitHubClosedIssueCount()
+
+ public function getGitHubIssueCount($state)
{
$count = 0;
- $key = $this->name.'-closed-issues';
+ $key = $this->name."-{$state}-issues";
$json = $this->cache->get($key);
if ($json === false) {
- $uri = self::GIT_HUB_API . str_replace('PEAR2_', '', $this->name) . '/closed';
+ $uri = self::GIT_HUB_API . $this->shortName . '/issues?state=' . $state;
$json = file_get_contents($uri);
if ($json === false) {
$json = $this->cache->get($key, 'default', false);
@@ -48,35 +58,19 @@ public function getGitHubClosedIssueCount()
}
if ($json !== false) {
- $result = json_decode($json);
- $count = count($result->issues);
+ $count = count(json_decode($json));
}
return $count;
}
- public function getGitHubOpenIssueCount()
+ public function getGitHubClosedIssueCount()
{
- $count = 0;
-
- $key = $this->name.'-open-issues';
- $json = $this->cache->get($key);
-
- if ($json === false) {
- $uri = self::GIT_HUB_API . str_replace('PEAR2_', '', $this->name) . '/open';
- $json = file_get_contents($uri);
- if ($json === false) {
- $json = $this->cache->get($key, 'default', false);
- } else {
- $this->cache->save($json, $key);
- }
- }
-
- if ($json !== false) {
- $result = json_decode($json);
- $count = count($result->issues);
- }
+ return $this->getGitHubIssueCount('closed');
+ }
- return $count;
+ public function getGitHubOpenIssueCount()
+ {
+ return $this->getGitHubIssueCount('open');
}
}

0 comments on commit 2ec00fe

Please sign in to comment.
Something went wrong with that request. Please try again.