Permalink
Browse files

Merge pull request #1 from dshafik/master

Added support for pulling user specific repos/orgs. Including Users model and tests.
  • Loading branch information...
2 parents d9cc31f + 96d1553 commit e447601c5ed36554a859c1032da86183fb04660b @gwoo committed Oct 11, 2011
@@ -13,6 +13,7 @@
class GitHub extends \lithium\data\source\Http {
protected $_strings = array(
+ 'users' => '/users/{:user}/{:type}',
'issues' => '/issues',
'repos' => '/repos/{:user}/{:repo}/{:type}/{:id}',
'orgs' => '/orgs/{:org}/{:type}'
View
@@ -0,0 +1,22 @@
+<?php
+
+namespace li3_github\models;
+
+class Users extends \lithium\data\Model {
+
+ protected $_meta = array('connection' => 'github');
+}
+
+Users::finder('repos', function($self, $params, $chain) {
+ $params['options']['conditions']['type'] = 'repos';
+ $data = $chain->next($self, $params, $chain);
+ return $data;
+});
+
+Users::finder('orgs', function($self, $params, $chain) {
+ $params['options']['conditions']['type'] = 'orgs';
+ $data = $chain->next($self, $params, $chain);
+ return $data;
+});
+
+?>
@@ -6,6 +6,8 @@
use lithium\data\model\Query;
use li3_github\models\Issues;
use li3_github\models\Repos;
+use li3_github\models\Orgs;
+use li3_github\models\Users;
class GithubTest extends \lithium\test\Unit {
@@ -91,4 +93,37 @@ public function testRepoIssuesWithSortCreatedDesc() {
$result = $issues->first();
$this->assertTrue($result->number > 2);
}
+
+ public function testUsersRepos() {
+ $repos = Users::repos(array(
+ 'conditions' => array(
+ 'user' => 'octocat'
+ )
+ ));
+ $result = $repos->first();
+ $this->assertEqual($result->name, 'Hello-World');
+ }
+
+ public function testOrgsRepos() {
+ $repos = Orgs::repos(array(
+ 'conditions' => array(
+ 'org' => 'octocat'
+ )
+ ));
+ $result = $repos->first();
+ $this->assertEqual($result->name, 'Hello-World');
+ }
+
+ public function testUserOrgs() {
+ $orgs = Users::orgs(array(
+ 'conditions' => array(
+ 'user' => 'octocat'
+ )
+ ));
+
+ $result = $orgs->first();
+ $this->assertEqual($orgs->login, 'github');
+ $this->assertEqual($orgs->id, 1);
+ $this->assertEqual($orgs->url, 'https://api.github.com/orgs/1');
+ }
}
@@ -53,6 +53,12 @@ private function _response($url) {
if (strpos($url, '/users/octocat')) {
$json = '/responses/users/octocat.json';
}
+ if (strpos($url, '/users/octocat/repos') || strpos($url, '/orgs/octocat/repos')) {
+ $json = '/reponses/users/repos.json';
+ }
+ if (strpos($url, '/users/octocat/orgs')) {
+ $json = '/responses/users/orgs.json';
+ }
if (strpos($url, '/issues')) {
$json = '/responses/issues.json';
}
@@ -0,0 +1,8 @@
+[
+ {
+ "login": "github",
+ "id": 1,
+ "url": "https://api.github.com/orgs/1",
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif"
+ }
+]
@@ -0,0 +1,29 @@
+[
+ {
+ "url": "https://api.github.com/repos/octocat/Hello-World",
+ "html_url": "https://github.com/octocat/Hello-World",
+ "clone_url": "https://github.com/octocat/Hello-World.git",
+ "git_url": "git://github.com/octocat/Hello-World.git",
+ "ssh_url": "git@github.com:octocat/Hello-World.git",
+ "svn_url": "https://svn.github.com/octocat/Hello-World",
+ "owner": {
+ "login": "octocat",
+ "id": 1,
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
+ "url": "https://api.github.com/users/octocat"
+ },
+ "name": "Hello-World",
+ "description": "This your first repo!",
+ "homepage": "https://github.com",
+ "language": null,
+ "private": false,
+ "fork": false,
+ "forks": 9,
+ "watchers": 80,
+ "size": 108,
+ "master_branch": "master",
+ "open_issues": 0,
+ "pushed_at": "2011-01-26T19:06:43Z",
+ "created_at": "2011-01-26T19:01:12Z"
+ }
+]

0 comments on commit e447601

Please sign in to comment.