Skip to content
Browse files

Merge pull request #72 from malditogeek/user_orgs

Support for user orgs
  • Loading branch information...
2 parents f53032c + d80b6a2 commit 4ddcb5716f39d23c4df2f75cfc9c9f4be55f7761 @pksunkara committed
Showing with 40 additions and 10 deletions.
  1. +10 −3 README.md
  2. +7 −4 lib/octonode/client.js
  3. +13 −0 lib/octonode/user.js
  4. +3 −3 src/octonode/client.coffee
  5. +7 −0 src/octonode/user.coffee
View
13 README.md
@@ -296,24 +296,31 @@ ghme.fork('pksunkara/hub', callback); //forked repo
No token required for the following
-#### Get information about an user (GET /users/pksunkara)
+#### Get information about a user (GET /users/pksunkara)
```js
ghuser.info(callback); //json
```
-#### Get an user followers (GET /users/pksunkara/followers)
+#### Get user followers (GET /users/pksunkara/followers)
```js
ghuser.followers(callback); //array of github users
```
-#### Get an user followings (GET /users/pksunkara/following)
+#### Get user followings (GET /users/pksunkara/following)
```js
ghuser.following(callback); //array of github users
```
+#### Get user organizations (GET /users/pksunkara/orgs)
+
+```js
+ghuser.orgs(callback); //array of organizations
+```
+
+
## Github repositories api
#### Get information about a repository (GET /repos/pksunkara/hub)
View
11 lib/octonode/client.js
@@ -96,10 +96,13 @@
if ((pageOrQuery != null) && typeof pageOrQuery === 'object') {
query = pageOrQuery;
} else {
- query = {
- page: pageOrQuery != null ? pageOrQuery : void 0,
- per_page: per_page != null ? per_page : void 0
- };
+ query = {};
+ if (pageOrQuery != null) {
+ query.page = pageOrQuery;
+ }
+ if (per_page != null) {
+ query.per_page = per_page;
+ }
}
if (typeof this.token === 'string') {
query.access_token = this.token;
View
13 lib/octonode/user.js
@@ -74,6 +74,19 @@
});
};
+ User.prototype.orgs = function(cb) {
+ return this.client.get("/users/" + this.login + "/orgs", function(err, s, b) {
+ if (err) {
+ return cb(err);
+ }
+ if (s !== 200) {
+ return cb(new Error('User organizations error'));
+ } else {
+ return cb(null, b);
+ }
+ });
+ };
+
return User;
})();
View
6 src/octonode/client.coffee
@@ -68,9 +68,9 @@ class Client
if pageOrQuery? and typeof pageOrQuery == 'object'
query = pageOrQuery
else
- query =
- page: pageOrQuery if pageOrQuery?
- per_page: per_page if per_page?
+ query = {}
+ query.page = pageOrQuery if pageOrQuery?
+ query.per_page = per_page if per_page?
if typeof @token == 'string'
query.access_token = @token
else if typeof @token == 'object' and @token.id
View
7 src/octonode/user.coffee
@@ -55,5 +55,12 @@ class User
cb null, b.filter (event) ->
return events.indexOf(event.type) != -1
+ # Get a list of organizations a user belongs to and has publicized membership.
+ # '/users/pksunkara/orgs' GET
+ orgs: (cb) ->
+ @client.get "/users/#{@login}/orgs", (err, s, b) ->
+ return cb(err) if err
+ if s isnt 200 then cb(new Error('User organizations error')) else cb null, b
+
# Export module
module.exports = User

0 comments on commit 4ddcb57

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