Skip to content

Commit c5f7852

Browse files
committed
Merge pull request octokit#165 from strongloop/misc
Add remaining miscellaneous APIs
2 parents d32ccbc + 2f78b66 commit c5f7852

File tree

7 files changed

+298
-1
lines changed

7 files changed

+298
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ github.authorization.create({
145145
* Markdown: 100%
146146
* Rate Limit: 100%
147147
* Releases: 90%
148+
* Gitignore: 100%
149+
* Meta: 100%
150+
* Emojis: 100%
148151

149152
## Running the Tests
150153

api/v3.0.0/gitignore.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* mixin gitignore
3+
*
4+
* Copyright 2012 Cloud9 IDE, Inc.
5+
*
6+
* This product includes software developed by
7+
* Cloud9 IDE, Inc (http://c9.io).
8+
*
9+
* Author: Mike de Boer <[email protected]>
10+
**/
11+
12+
"use strict";
13+
14+
var error = require("./../../error");
15+
var Util = require("./../../util");
16+
17+
var gitignore = module.exports = {
18+
gitignore: {}
19+
};
20+
21+
(function() {
22+
/** section: github
23+
* gitignore#templates(msg, callback) -> null
24+
* - msg (Object): Object that contains the parameters and their values to be sent to the server.
25+
* - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument.
26+
*
27+
* ##### Params on the `msg` object:
28+
*
29+
* - 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'.
30+
* No other params, simply pass an empty Object literal `{}`
31+
**/
32+
this.templates = function(msg, block, callback) {
33+
var self = this;
34+
this.client.httpSend(msg, block, function(err, res) {
35+
if (err)
36+
return self.sendError(err, null, msg, callback);
37+
38+
var ret;
39+
try {
40+
ret = res.data && JSON.parse(res.data);
41+
}
42+
catch (ex) {
43+
if (callback)
44+
callback(new error.InternalServerError(ex.message), res);
45+
return;
46+
}
47+
48+
if (!ret)
49+
ret = {};
50+
if (!ret.meta)
51+
ret.meta = {};
52+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
53+
if (res.headers[header])
54+
ret.meta[header] = res.headers[header];
55+
});
56+
57+
if (callback)
58+
callback(null, ret);
59+
});
60+
};
61+
62+
/** section: github
63+
* gitignore#template(msg, callback) -> null
64+
* - msg (Object): Object that contains the parameters and their values to be sent to the server.
65+
* - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument.
66+
*
67+
* ##### Params on the `msg` object:
68+
*
69+
* - 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'.
70+
* - name (String): Required. The name of the .gitignore template to get
71+
**/
72+
this.template = function(msg, block, callback) {
73+
var self = this;
74+
this.client.httpSend(msg, block, function(err, res) {
75+
if (err)
76+
return self.sendError(err, null, msg, callback);
77+
78+
var ret;
79+
try {
80+
ret = res.data && JSON.parse(res.data);
81+
}
82+
catch (ex) {
83+
if (callback)
84+
callback(new error.InternalServerError(ex.message), res);
85+
return;
86+
}
87+
88+
if (!ret)
89+
ret = {};
90+
if (!ret.meta)
91+
ret.meta = {};
92+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
93+
if (res.headers[header])
94+
ret.meta[header] = res.headers[header];
95+
});
96+
97+
if (callback)
98+
callback(null, ret);
99+
});
100+
};
101+
102+
}).call(gitignore.gitignore);

api/v3.0.0/gitignoreTest.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2012 Cloud9 IDE, Inc.
3+
*
4+
* This product includes software developed by
5+
* Cloud9 IDE, Inc (http://c9.io).
6+
*
7+
* Author: Mike de Boer <[email protected]>
8+
*/
9+
10+
"use strict";
11+
12+
var Assert = require("assert");
13+
var Client = require("./../../index");
14+
15+
describe("[gitignore]", function() {
16+
var client;
17+
18+
beforeEach(function() {
19+
client = new Client({
20+
version: "3.0.0"
21+
});
22+
});
23+
24+
it("should successfully execute GET /gitignore/templates (templates)", function(next) {
25+
client.gitignore.templates(
26+
{},
27+
function(err, res) {
28+
Assert.equal(err, null);
29+
// other assertions go here
30+
Assert.ifError(err);
31+
Assert(Array.isArray(res));
32+
Assert(res.length > 10);
33+
next();
34+
}
35+
);
36+
});
37+
38+
it("should successfully execute GET /gitignore/templates/:name (template)", function(next) {
39+
client.gitignore.template(
40+
{
41+
name: "C"
42+
},
43+
function(err, res) {
44+
Assert.equal(err, null);
45+
// other assertions go here
46+
Assert.ifError(err);
47+
Assert('name' in res);
48+
Assert('source' in res);
49+
Assert(typeof res.source === 'string');
50+
next();
51+
}
52+
);
53+
});
54+
});

api/v3.0.0/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var proto = {
3333
}
3434
};
3535

36-
["gists", "gitdata", "issues", "authorization", "orgs", "statuses", "pullRequests", "repos", "user", "events", "releases", "search", "markdown", "misc"].forEach(function(api) {
36+
["gists", "gitdata", "issues", "authorization", "orgs", "statuses", "pullRequests", "repos", "user", "events", "releases", "search", "markdown", "gitignore", "misc"].forEach(function(api) {
3737
Util.extend(proto, require("./" + api));
3838
});
3939

api/v3.0.0/misc.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,86 @@ var misc = module.exports = {
1919
};
2020

2121
(function() {
22+
/** section: github
23+
* misc#emojis(msg, callback) -> null
24+
* - msg (Object): Object that contains the parameters and their values to be sent to the server.
25+
* - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument.
26+
*
27+
* ##### Params on the `msg` object:
28+
*
29+
* - 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'.
30+
* No other params, simply pass an empty Object literal `{}`
31+
**/
32+
this.emojis = function(msg, block, callback) {
33+
var self = this;
34+
this.client.httpSend(msg, block, function(err, res) {
35+
if (err)
36+
return self.sendError(err, null, msg, callback);
37+
38+
var ret;
39+
try {
40+
ret = res.data && JSON.parse(res.data);
41+
}
42+
catch (ex) {
43+
if (callback)
44+
callback(new error.InternalServerError(ex.message), res);
45+
return;
46+
}
47+
48+
if (!ret)
49+
ret = {};
50+
if (!ret.meta)
51+
ret.meta = {};
52+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
53+
if (res.headers[header])
54+
ret.meta[header] = res.headers[header];
55+
});
56+
57+
if (callback)
58+
callback(null, ret);
59+
});
60+
};
61+
62+
/** section: github
63+
* misc#meta(msg, callback) -> null
64+
* - msg (Object): Object that contains the parameters and their values to be sent to the server.
65+
* - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument.
66+
*
67+
* ##### Params on the `msg` object:
68+
*
69+
* - 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'.
70+
* No other params, simply pass an empty Object literal `{}`
71+
**/
72+
this.meta = function(msg, block, callback) {
73+
var self = this;
74+
this.client.httpSend(msg, block, function(err, res) {
75+
if (err)
76+
return self.sendError(err, null, msg, callback);
77+
78+
var ret;
79+
try {
80+
ret = res.data && JSON.parse(res.data);
81+
}
82+
catch (ex) {
83+
if (callback)
84+
callback(new error.InternalServerError(ex.message), res);
85+
return;
86+
}
87+
88+
if (!ret)
89+
ret = {};
90+
if (!ret.meta)
91+
ret.meta = {};
92+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
93+
if (res.headers[header])
94+
ret.meta[header] = res.headers[header];
95+
});
96+
97+
if (callback)
98+
callback(null, ret);
99+
});
100+
};
101+
22102
/** section: github
23103
* misc#rateLimit(msg, callback) -> null
24104
* - msg (Object): Object that contains the parameters and their values to be sent to the server.

api/v3.0.0/miscTest.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,33 @@ describe("[misc]", function() {
2121
});
2222
});
2323

24+
it("should successfully execute GET /emojis (emojis)", function(next) {
25+
client.misc.emojis(
26+
{},
27+
function(err, res) {
28+
Assert.equal(err, null);
29+
// other assertions go here
30+
Assert.ifError(err);
31+
// A common emoji on github
32+
Assert('shipit' in res);
33+
next();
34+
}
35+
);
36+
});
37+
38+
it("should successfully execute GET /meta (meta)", function(next) {
39+
client.misc.meta(
40+
{},
41+
function(err, res) {
42+
Assert.equal(err, null);
43+
// other assertions go here
44+
Assert('hooks' in res);
45+
Assert('git' in res);
46+
next();
47+
}
48+
);
49+
});
50+
2451
it("should successfully execute GET /rate_limit (rateLimit)", function(next) {
2552
client.misc.rateLimit(
2653
{},

api/v3.0.0/routes.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3517,7 +3517,38 @@
35173517
}
35183518
},
35193519

3520+
"gitignore": {
3521+
"templates": {
3522+
"url": "/gitignore/templates",
3523+
"method": "GET",
3524+
"params": { }
3525+
},
3526+
"template": {
3527+
"url": "/gitignore/templates/:name",
3528+
"method": "GET",
3529+
"params": {
3530+
"name": {
3531+
"type": "String",
3532+
"required": true,
3533+
"validation": "",
3534+
"invalidmsg": "",
3535+
"description": "The name of the .gitignore template to get"
3536+
}
3537+
}
3538+
}
3539+
},
3540+
35203541
"misc": {
3542+
"emojis": {
3543+
"url": "/emojis",
3544+
"method": "GET",
3545+
"params": { }
3546+
},
3547+
"meta": {
3548+
"url": "/meta",
3549+
"method": "GET",
3550+
"params": { }
3551+
},
35213552
"rate-limit": {
35223553
"url": "/rate_limit",
35233554
"method": "GET",

0 commit comments

Comments
 (0)