Permalink
Browse files

Changed GitHub API to v3;

Added $shortName to the package model, with a getter;
Moved link base to a new GIT_HUB_LINK constant.
  • Loading branch information...
1 parent 017a0e4 commit f14aca52d5b34d125da47e5371854fff9563ea14 @boenrobot boenrobot committed Aug 9, 2012
Showing with 18 additions and 9 deletions.
  1. +18 −9 src/PEAR2Web/Models/Package.php
View
27 src/PEAR2Web/Models/Package.php
@@ -4,30 +4,40 @@
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()
@@ -38,7 +48,7 @@ public function getGitHubClosedIssueCount()
$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=closed';
$json = file_get_contents($uri);
if ($json === false) {
$json = $this->cache->get($key, 'default', false);
@@ -63,7 +73,7 @@ public function getGitHubOpenIssueCount()
$json = $this->cache->get($key);
if ($json === false) {
- $uri = self::GIT_HUB_API . str_replace('PEAR2_', '', $this->name) . '/open';
+ $uri = self::GIT_HUB_API . $this->shortName . '/issues?state=open';
$json = file_get_contents($uri);
if ($json === false) {
$json = $this->cache->get($key, 'default', false);
@@ -73,8 +83,7 @@ public function getGitHubOpenIssueCount()
}
if ($json !== false) {
- $result = json_decode($json);
- $count = count($result->issues);
+ $count = count(json_decode($json));
}
return $count;

0 comments on commit f14aca5

Please sign in to comment.