Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added gist comment API #127

Merged
merged 1 commit into from
Feb 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 207 additions & 0 deletions api/v3.0.0/gists.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,4 +508,211 @@ var gists = module.exports = {
});
};

/** section: github
* gists#getComments(msg, callback) -> null
* - msg (Object): Object that contains the parameters and their values to be sent to the server.
* - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument.
*
* ##### Params on the `msg` object:
*
* - headers (Object): Optional. Key/ value pair of request headers to pass along with the HTTP request. Valid headers are: 'If-Modified-Since', 'If-None-Match', 'Cookie', 'User-Agent', 'Accept', 'X-GitHub-OTP'.
* - gist_id (String): Required. Id of the gist to get comments for.
**/
this.getComments = function(msg, block, callback) {
var self = this;
this.client.httpSend(msg, block, function(err, res) {
if (err)
return self.sendError(err, null, msg, callback);

var ret;
try {
ret = res.data && JSON.parse(res.data);
}
catch (ex) {
if (callback)
callback(new error.InternalServerError(ex.message), res);
return;
}

if (!ret)
ret = {};
if (!ret.meta)
ret.meta = {};
["x-ratelimit-limit", "x-ratelimit-remaining", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
if (res.headers[header])
ret.meta[header] = res.headers[header];
});

if (callback)
callback(null, ret);
});
};

/** section: github
* gists#getComment(msg, callback) -> null
* - msg (Object): Object that contains the parameters and their values to be sent to the server.
* - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument.
*
* ##### Params on the `msg` object:
*
* - headers (Object): Optional. Key/ value pair of request headers to pass along with the HTTP request. Valid headers are: 'If-Modified-Since', 'If-None-Match', 'Cookie', 'User-Agent'.
* - gist_id (String): Required. Id of the gist to get comments for.
* - id (String): Required. Id of the comment to get.
**/
this.getComment = function(msg, block, callback) {
var self = this;
this.client.httpSend(msg, block, function(err, res) {
if (err)
return self.sendError(err, null, msg, callback);

var ret;
try {
ret = res.data && JSON.parse(res.data);
}
catch (ex) {
if (callback)
callback(new error.InternalServerError(ex.message), res);
return;
}

if (!ret)
ret = {};
if (!ret.meta)
ret.meta = {};
["x-ratelimit-limit", "x-ratelimit-remaining", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
if (res.headers[header])
ret.meta[header] = res.headers[header];
});

if (callback)
callback(null, ret);
});
};


/** section: github
* gists#createComment(msg, callback) -> null
* - msg (Object): Object that contains the parameters and their values to be sent to the server.
* - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument.
*
* ##### Params on the `msg` object:
*
* - headers (Object): Optional. Key/ value pair of request headers to pass along with the HTTP request. Valid headers are: 'If-Modified-Since', 'If-None-Match', 'Cookie', 'User-Agent'.
* - gist_id (String): Required. Id of the gist to get the comment for.
* - body (String): Required. The comment text.
**/
this.createComment = function(msg, block, callback) {
var self = this;
this.client.httpSend(msg, block, function(err, res) {
if (err)
return self.sendError(err, null, msg, callback);

var ret;
try {
ret = res.data && JSON.parse(res.data);
}
catch (ex) {
if (callback)
callback(new error.InternalServerError(ex.message), res);
return;
}

if (!ret)
ret = {};
if (!ret.meta)
ret.meta = {};
["x-ratelimit-limit", "x-ratelimit-remaining", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
if (res.headers[header])
ret.meta[header] = res.headers[header];
});

if (callback)
callback(null, ret);
});
};

/** section: github
* gists#editComment(msg, callback) -> null
* - msg (Object): Object that contains the parameters and their values to be sent to the server.
* - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument.
*
* ##### Params on the `msg` object:
*
* - headers (Object): Optional. Key/ value pair of request headers to pass along with the HTTP request. Valid headers are: 'If-Modified-Since', 'If-None-Match', 'Cookie', 'User-Agent'.
* - gist_id (String): Required. Id of the gist to get comments for.
* - id (String): Required. Id of the comment to get.
* - body (String): Required. The comment text.
**/
this.editComment = function(msg, block, callback) {
var self = this;
this.client.httpSend(msg, block, function(err, res) {
if (err)
return self.sendError(err, null, msg, callback);

var ret;
try {
ret = res.data && JSON.parse(res.data);
}
catch (ex) {
if (callback)
callback(new error.InternalServerError(ex.message), res);
return;
}

if (!ret)
ret = {};
if (!ret.meta)
ret.meta = {};
["x-ratelimit-limit", "x-ratelimit-remaining", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
if (res.headers[header])
ret.meta[header] = res.headers[header];
});

if (callback)
callback(null, ret);
});
};


/** section: github
* gists#deleteComment(msg, callback) -> null
* - msg (Object): Object that contains the parameters and their values to be sent to the server.
* - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument.
*
* ##### Params on the `msg` object:
*
* - headers (Object): Optional. Key/ value pair of request headers to pass along with the HTTP request. Valid headers are: 'If-Modified-Since', 'If-None-Match', 'Cookie', 'User-Agent'.
* - gist_id (String): Required. Id of the gist to delete the comment for.
* - id (String): Required. Id of the comment to delete.
**/
this.deleteComment = function(msg, block, callback) {
var self = this;
this.client.httpSend(msg, block, function(err, res) {
if (err)
return self.sendError(err, null, msg, callback);

var ret;
try {
ret = res.data && JSON.parse(res.data);
}
catch (ex) {
if (callback)
callback(new error.InternalServerError(ex.message), res);
return;
}

if (!ret)
ret = {};
if (!ret.meta)
ret.meta = {};
["x-ratelimit-limit", "x-ratelimit-remaining", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
if (res.headers[header])
ret.meta[header] = res.headers[header];
});

if (callback)
callback(null, ret);
});
};

}).call(gists.gists);
183 changes: 183 additions & 0 deletions api/v3.0.0/gistsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,187 @@ describe("[gists]", function() {
}
);
});

it("should successfully execute GET /gists/:gist_id/comments/:id (getComments)", function(next) {
client.gists.createComment(
{
gist_id: "3047099",
body: "This is a test comment.",
},
function(err, res) {
Assert.equal(err, null);
var id = res.id;

client.gists.getComments(
{
gist_id: "3047099"
},
function(err, res) {
var comment = res.pop();
Assert.equal(err, null);
Assert.equal(comment.user.login, "mikedeboertest");
Assert.equal(comment.id, id);
Assert.equal(comment.body, "This is a test comment.");

client.gists["deleteComment"](
{
gist_id: "3047099",
id: id
},
function(err, res) {
Assert.equal(err, null);
next();
}
);
}
);
}
);
});

it("should successfully execute GET /gists/:gist_id/comments/:id (getComment)", function(next) {
client.gists.createComment(
{
gist_id: "3047099",
body: "This is a test comment.",
},
function(err, res) {
Assert.equal(err, null);
var id = res.id;

client.gists.getComment(
{
gist_id: "3047099",
id: id
},
function(err, res) {
Assert.equal(err, null);
Assert.equal(res.user.login, "mikedeboertest");
Assert.equal(res.id, id);
Assert.equal(res.body, "This is a test comment.");

client.gists["deleteComment"](
{
gist_id: "3047099",
id: id
},
function(err, res) {
Assert.equal(err, null);
next();
}
);
}
);
}
);
});

it("should successfully execute POST /gists/:gist_id/comments (createComment)", function(next) {
client.gists.createComment(
{
gist_id: "3047099",
body: "This is a test comment.",
},
function(err, res) {
Assert.equal(err, null);
var id = res.id;

client.gists.getComment(
{
gist_id: "3047099",
id: id
},
function(err, res) {
Assert.equal(err, null);
Assert.equal(res.user.login, "mikedeboertest");
Assert.equal(res.id, id);
Assert.equal(res.body, "This is a test comment.");

client.gists["deleteComment"](
{
gist_id: "3047099",
id: id
},
function(err, res) {
Assert.equal(err, null);
next();
}
);
}
);
}
);
});

it("should successfully execute PATCH /gists/:gist_id/comments/:id (editComment)", function(next) {
client.gists.createComment(
{
gist_id: "3047099",
body: "This is a test comment.",
},
function(err, res) {
Assert.equal(err, null);
var id = res.id;

client.gists.editComment(
{
gist_id: "3047099",
id: id,
body: "This comment has been edited."
},
function(err, res) {
Assert.equal(err, null);
var id = res.id;
client.gists.getComment(
{
gist_id: "3047099",
id: id
},
function(err, res) {
Assert.equal(err, null);
Assert.equal(res.user.login, "mikedeboertest");
Assert.equal(res.id, id);
Assert.equal(res.body, "This comment has been edited.");

client.gists["deleteComment"](
{
gist_id: "3047099",
id: id
},
function(err, res) {
Assert.equal(err, null);
next();
}
);
}
);
}
);
}
);
});

it("should successfully execute DELETE /gists/:gist_id/comments/:id (deleteComment)", function(next) {
client.gists.createComment(
{
gist_id: "3047099",
body: "This is a test comment.",
},
function(err, res) {
Assert.equal(err, null);
var id = res.id;

client.gists["deleteComment"](
{
gist_id: "3047099",
id: id
},
function(err, res) {
Assert.equal(err, null);
next();
}
);
}
);
});
});
Loading