Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

When a user has concealed their membership in an organisation the Org.member() method does not work correctly #74

Merged
merged 3 commits into from

3 participants

@suprememoocow

In this case, Github returned a 302 Found with a redirection to the public_membership resource, however, the fact that the 302 was returned as opposed to a 404 is enough to indicate membership (when membership is concealed, the redirected URL will return a 404). When the user is not a member of an org, GitHub will return a 404 immediately.

Please let me know if you want me to rework this in any way.

src/octonode/client.coffee
@@ -106,6 +106,16 @@ class Client
return callback(err) if err
@errorHandle res, body, callback
+ # Github api GET request
+ getNoFollow: (path, params..., callback) ->
+ request
+ uri: @buildUrl path, params...
+ method: 'GET'
+ followRedirect: false
+ headers:
+ 'User-Agent': 'octonode/0.3 (https://github.com/pksunkara/octonode) terminal/0.0'
+ , @handleResponse(callback)
@pksunkara Owner

What's this?

Shouldn't this be the same as above in get ?

Well, it's identical to get, but includes the followRedirect: false attribute. If you prefer I do it another way, let me know

@pksunkara Owner

Not that. lol.

I meant about @handleResponse. It doesn't exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@suprememoocow

Sorry about that. I've been experimenting with something and had merged it across into the wrong branch by accident.

This commit should fix it.

@pksunkara pksunkara merged commit e3327d2 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 3, 2013
  1. @trevorah @suprememoocow

    version bump

    trevorah authored suprememoocow committed
  2. @suprememoocow
  3. @suprememoocow
This page is out of date. Refresh to see the latest.
View
19 lib/octonode/client.js
@@ -157,6 +157,25 @@
});
};
+ Client.prototype.getNoFollow = function() {
+ var callback, params, path, _i,
+ _this = this;
+ path = arguments[0], params = 3 <= arguments.length ? __slice.call(arguments, 1, _i = arguments.length - 1) : (_i = 1, []), callback = arguments[_i++];
+ return request({
+ uri: this.buildUrl.apply(this, [path].concat(__slice.call(params))),
+ method: 'GET',
+ followRedirect: false,
+ headers: {
+ 'User-Agent': 'octonode/0.3 (https://github.com/pksunkara/octonode) terminal/0.0'
+ }
+ }, function(err, res, body) {
+ if (err) {
+ return callback(err);
+ }
+ return _this.errorHandle(res, body, callback);
+ });
+ };
+
Client.prototype.post = function(path, content, callback) {
var _this = this;
return request({
View
4 lib/octonode/org.js
@@ -92,11 +92,11 @@
};
Org.prototype.member = function(user, cb) {
- return this.client.get("/orgs/" + this.name + "/members/" + user, function(err, s, b) {
+ return this.client.getNoFollow("/orgs/" + this.name + "/members/" + user, function(err, s, b) {
if (err) {
return cb(err);
}
- return cb(null, s === 204);
+ return cb(null, s === 204 || s === 302);
});
};
View
2  package.json
@@ -1,6 +1,6 @@
{
"name": "octonode",
- "version": "0.3.8",
+ "version": "0.3.9",
"author": "Pavan Kumar Sunkara <pavan.sss1991@gmail.com> (http://pksunkara.github.com)",
"description": "nodejs wrapper for github v3 api",
"main": "./lib/octonode",
View
12 src/octonode/client.coffee
@@ -106,6 +106,18 @@ class Client
return callback(err) if err
@errorHandle res, body, callback
+ # Github api GET request
+ getNoFollow: (path, params..., callback) ->
+ request
+ uri: @buildUrl path, params...
+ method: 'GET'
+ followRedirect: false
+ headers:
+ 'User-Agent': 'octonode/0.3 (https://github.com/pksunkara/octonode) terminal/0.0'
+ , (err, res, body) =>
+ return callback(err) if err
+ @errorHandle res, body, callback
+
# Github api POST request
post: (path, content, callback) ->
request
View
4 src/octonode/org.coffee
@@ -60,9 +60,9 @@ class Org
# Check an organization's member.
# '/orgs/flatiron/members/pksunkara' GET
member: (user, cb) ->
- @client.get "/orgs/#{@name}/members/#{user}", (err, s, b) ->
+ @client.getNoFollow "/orgs/#{@name}/members/#{user}", (err, s, b) ->
return cb(err) if err
- cb null, s is 204
+ cb null, s is 204 or s is 302
# Export module
module.exports = Org
Something went wrong with that request. Please try again.