Skip to content

Commit a1115dc

Browse files
committedApr 19, 2015
Add support for custom accept headers for real this time, added markdown-raw method, added support for non-JSON request results. Fixes octokit#239. Fixes octokit#235.
1 parent 9d0cccd commit a1115dc

20 files changed

+2836
-1611
lines changed
 

‎api/v3.0.0/authorization.js

+60-35
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ var authorization = module.exports = {
3838

3939
var ret;
4040
try {
41-
ret = res.data && JSON.parse(res.data);
41+
ret = res.data;
42+
var contentType = res.headers["content-type"];
43+
if (contentType && contentType.indexOf("application/json") !== -1)
44+
ret = JSON.parse(ret);
4245
}
4346
catch (ex) {
4447
if (callback)
@@ -48,12 +51,14 @@ var authorization = module.exports = {
4851

4952
if (!ret)
5053
ret = {};
51-
if (!ret.meta)
52-
ret.meta = {};
53-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
54-
if (res.headers[header])
55-
ret.meta[header] = res.headers[header];
56-
});
54+
if (typeof ret == "object") {
55+
if (!ret.meta)
56+
ret.meta = {};
57+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
58+
if (res.headers[header])
59+
ret.meta[header] = res.headers[header];
60+
});
61+
}
5762

5863
if (callback)
5964
callback(null, ret);
@@ -78,7 +83,10 @@ var authorization = module.exports = {
7883

7984
var ret;
8085
try {
81-
ret = res.data && JSON.parse(res.data);
86+
ret = res.data;
87+
var contentType = res.headers["content-type"];
88+
if (contentType && contentType.indexOf("application/json") !== -1)
89+
ret = JSON.parse(ret);
8290
}
8391
catch (ex) {
8492
if (callback)
@@ -88,12 +96,14 @@ var authorization = module.exports = {
8896

8997
if (!ret)
9098
ret = {};
91-
if (!ret.meta)
92-
ret.meta = {};
93-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
94-
if (res.headers[header])
95-
ret.meta[header] = res.headers[header];
96-
});
99+
if (typeof ret == "object") {
100+
if (!ret.meta)
101+
ret.meta = {};
102+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
103+
if (res.headers[header])
104+
ret.meta[header] = res.headers[header];
105+
});
106+
}
97107

98108
if (callback)
99109
callback(null, ret);
@@ -120,7 +130,10 @@ var authorization = module.exports = {
120130

121131
var ret;
122132
try {
123-
ret = res.data && JSON.parse(res.data);
133+
ret = res.data;
134+
var contentType = res.headers["content-type"];
135+
if (contentType && contentType.indexOf("application/json") !== -1)
136+
ret = JSON.parse(ret);
124137
}
125138
catch (ex) {
126139
if (callback)
@@ -130,12 +143,14 @@ var authorization = module.exports = {
130143

131144
if (!ret)
132145
ret = {};
133-
if (!ret.meta)
134-
ret.meta = {};
135-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
136-
if (res.headers[header])
137-
ret.meta[header] = res.headers[header];
138-
});
146+
if (typeof ret == "object") {
147+
if (!ret.meta)
148+
ret.meta = {};
149+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
150+
if (res.headers[header])
151+
ret.meta[header] = res.headers[header];
152+
});
153+
}
139154

140155
if (callback)
141156
callback(null, ret);
@@ -165,7 +180,10 @@ var authorization = module.exports = {
165180

166181
var ret;
167182
try {
168-
ret = res.data && JSON.parse(res.data);
183+
ret = res.data;
184+
var contentType = res.headers["content-type"];
185+
if (contentType && contentType.indexOf("application/json") !== -1)
186+
ret = JSON.parse(ret);
169187
}
170188
catch (ex) {
171189
if (callback)
@@ -175,12 +193,14 @@ var authorization = module.exports = {
175193

176194
if (!ret)
177195
ret = {};
178-
if (!ret.meta)
179-
ret.meta = {};
180-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
181-
if (res.headers[header])
182-
ret.meta[header] = res.headers[header];
183-
});
196+
if (typeof ret == "object") {
197+
if (!ret.meta)
198+
ret.meta = {};
199+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
200+
if (res.headers[header])
201+
ret.meta[header] = res.headers[header];
202+
});
203+
}
184204

185205
if (callback)
186206
callback(null, ret);
@@ -205,7 +225,10 @@ var authorization = module.exports = {
205225

206226
var ret;
207227
try {
208-
ret = res.data && JSON.parse(res.data);
228+
ret = res.data;
229+
var contentType = res.headers["content-type"];
230+
if (contentType && contentType.indexOf("application/json") !== -1)
231+
ret = JSON.parse(ret);
209232
}
210233
catch (ex) {
211234
if (callback)
@@ -215,12 +238,14 @@ var authorization = module.exports = {
215238

216239
if (!ret)
217240
ret = {};
218-
if (!ret.meta)
219-
ret.meta = {};
220-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
221-
if (res.headers[header])
222-
ret.meta[header] = res.headers[header];
223-
});
241+
if (typeof ret == "object") {
242+
if (!ret.meta)
243+
ret.meta = {};
244+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
245+
if (res.headers[header])
246+
ret.meta[header] = res.headers[header];
247+
});
248+
}
224249

225250
if (callback)
226251
callback(null, ret);

‎api/v3.0.0/events.js

+120-70
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ var events = module.exports = {
3838

3939
var ret;
4040
try {
41-
ret = res.data && JSON.parse(res.data);
41+
ret = res.data;
42+
var contentType = res.headers["content-type"];
43+
if (contentType && contentType.indexOf("application/json") !== -1)
44+
ret = JSON.parse(ret);
4245
}
4346
catch (ex) {
4447
if (callback)
@@ -48,12 +51,14 @@ var events = module.exports = {
4851

4952
if (!ret)
5053
ret = {};
51-
if (!ret.meta)
52-
ret.meta = {};
53-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
54-
if (res.headers[header])
55-
ret.meta[header] = res.headers[header];
56-
});
54+
if (typeof ret == "object") {
55+
if (!ret.meta)
56+
ret.meta = {};
57+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
58+
if (res.headers[header])
59+
ret.meta[header] = res.headers[header];
60+
});
61+
}
5762

5863
if (callback)
5964
callback(null, ret);
@@ -81,7 +86,10 @@ var events = module.exports = {
8186

8287
var ret;
8388
try {
84-
ret = res.data && JSON.parse(res.data);
89+
ret = res.data;
90+
var contentType = res.headers["content-type"];
91+
if (contentType && contentType.indexOf("application/json") !== -1)
92+
ret = JSON.parse(ret);
8593
}
8694
catch (ex) {
8795
if (callback)
@@ -91,12 +99,14 @@ var events = module.exports = {
9199

92100
if (!ret)
93101
ret = {};
94-
if (!ret.meta)
95-
ret.meta = {};
96-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
97-
if (res.headers[header])
98-
ret.meta[header] = res.headers[header];
99-
});
102+
if (typeof ret == "object") {
103+
if (!ret.meta)
104+
ret.meta = {};
105+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
106+
if (res.headers[header])
107+
ret.meta[header] = res.headers[header];
108+
});
109+
}
100110

101111
if (callback)
102112
callback(null, ret);
@@ -124,7 +134,10 @@ var events = module.exports = {
124134

125135
var ret;
126136
try {
127-
ret = res.data && JSON.parse(res.data);
137+
ret = res.data;
138+
var contentType = res.headers["content-type"];
139+
if (contentType && contentType.indexOf("application/json") !== -1)
140+
ret = JSON.parse(ret);
128141
}
129142
catch (ex) {
130143
if (callback)
@@ -134,12 +147,14 @@ var events = module.exports = {
134147

135148
if (!ret)
136149
ret = {};
137-
if (!ret.meta)
138-
ret.meta = {};
139-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
140-
if (res.headers[header])
141-
ret.meta[header] = res.headers[header];
142-
});
150+
if (typeof ret == "object") {
151+
if (!ret.meta)
152+
ret.meta = {};
153+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
154+
if (res.headers[header])
155+
ret.meta[header] = res.headers[header];
156+
});
157+
}
143158

144159
if (callback)
145160
callback(null, ret);
@@ -167,7 +182,10 @@ var events = module.exports = {
167182

168183
var ret;
169184
try {
170-
ret = res.data && JSON.parse(res.data);
185+
ret = res.data;
186+
var contentType = res.headers["content-type"];
187+
if (contentType && contentType.indexOf("application/json") !== -1)
188+
ret = JSON.parse(ret);
171189
}
172190
catch (ex) {
173191
if (callback)
@@ -177,12 +195,14 @@ var events = module.exports = {
177195

178196
if (!ret)
179197
ret = {};
180-
if (!ret.meta)
181-
ret.meta = {};
182-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
183-
if (res.headers[header])
184-
ret.meta[header] = res.headers[header];
185-
});
198+
if (typeof ret == "object") {
199+
if (!ret.meta)
200+
ret.meta = {};
201+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
202+
if (res.headers[header])
203+
ret.meta[header] = res.headers[header];
204+
});
205+
}
186206

187207
if (callback)
188208
callback(null, ret);
@@ -209,7 +229,10 @@ var events = module.exports = {
209229

210230
var ret;
211231
try {
212-
ret = res.data && JSON.parse(res.data);
232+
ret = res.data;
233+
var contentType = res.headers["content-type"];
234+
if (contentType && contentType.indexOf("application/json") !== -1)
235+
ret = JSON.parse(ret);
213236
}
214237
catch (ex) {
215238
if (callback)
@@ -219,12 +242,14 @@ var events = module.exports = {
219242

220243
if (!ret)
221244
ret = {};
222-
if (!ret.meta)
223-
ret.meta = {};
224-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
225-
if (res.headers[header])
226-
ret.meta[header] = res.headers[header];
227-
});
245+
if (typeof ret == "object") {
246+
if (!ret.meta)
247+
ret.meta = {};
248+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
249+
if (res.headers[header])
250+
ret.meta[header] = res.headers[header];
251+
});
252+
}
228253

229254
if (callback)
230255
callback(null, ret);
@@ -251,7 +276,10 @@ var events = module.exports = {
251276

252277
var ret;
253278
try {
254-
ret = res.data && JSON.parse(res.data);
279+
ret = res.data;
280+
var contentType = res.headers["content-type"];
281+
if (contentType && contentType.indexOf("application/json") !== -1)
282+
ret = JSON.parse(ret);
255283
}
256284
catch (ex) {
257285
if (callback)
@@ -261,12 +289,14 @@ var events = module.exports = {
261289

262290
if (!ret)
263291
ret = {};
264-
if (!ret.meta)
265-
ret.meta = {};
266-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
267-
if (res.headers[header])
268-
ret.meta[header] = res.headers[header];
269-
});
292+
if (typeof ret == "object") {
293+
if (!ret.meta)
294+
ret.meta = {};
295+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
296+
if (res.headers[header])
297+
ret.meta[header] = res.headers[header];
298+
});
299+
}
270300

271301
if (callback)
272302
callback(null, ret);
@@ -293,7 +323,10 @@ var events = module.exports = {
293323

294324
var ret;
295325
try {
296-
ret = res.data && JSON.parse(res.data);
326+
ret = res.data;
327+
var contentType = res.headers["content-type"];
328+
if (contentType && contentType.indexOf("application/json") !== -1)
329+
ret = JSON.parse(ret);
297330
}
298331
catch (ex) {
299332
if (callback)
@@ -303,12 +336,14 @@ var events = module.exports = {
303336

304337
if (!ret)
305338
ret = {};
306-
if (!ret.meta)
307-
ret.meta = {};
308-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
309-
if (res.headers[header])
310-
ret.meta[header] = res.headers[header];
311-
});
339+
if (typeof ret == "object") {
340+
if (!ret.meta)
341+
ret.meta = {};
342+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
343+
if (res.headers[header])
344+
ret.meta[header] = res.headers[header];
345+
});
346+
}
312347

313348
if (callback)
314349
callback(null, ret);
@@ -335,7 +370,10 @@ var events = module.exports = {
335370

336371
var ret;
337372
try {
338-
ret = res.data && JSON.parse(res.data);
373+
ret = res.data;
374+
var contentType = res.headers["content-type"];
375+
if (contentType && contentType.indexOf("application/json") !== -1)
376+
ret = JSON.parse(ret);
339377
}
340378
catch (ex) {
341379
if (callback)
@@ -345,12 +383,14 @@ var events = module.exports = {
345383

346384
if (!ret)
347385
ret = {};
348-
if (!ret.meta)
349-
ret.meta = {};
350-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
351-
if (res.headers[header])
352-
ret.meta[header] = res.headers[header];
353-
});
386+
if (typeof ret == "object") {
387+
if (!ret.meta)
388+
ret.meta = {};
389+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
390+
if (res.headers[header])
391+
ret.meta[header] = res.headers[header];
392+
});
393+
}
354394

355395
if (callback)
356396
callback(null, ret);
@@ -377,7 +417,10 @@ var events = module.exports = {
377417

378418
var ret;
379419
try {
380-
ret = res.data && JSON.parse(res.data);
420+
ret = res.data;
421+
var contentType = res.headers["content-type"];
422+
if (contentType && contentType.indexOf("application/json") !== -1)
423+
ret = JSON.parse(ret);
381424
}
382425
catch (ex) {
383426
if (callback)
@@ -387,12 +430,14 @@ var events = module.exports = {
387430

388431
if (!ret)
389432
ret = {};
390-
if (!ret.meta)
391-
ret.meta = {};
392-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
393-
if (res.headers[header])
394-
ret.meta[header] = res.headers[header];
395-
});
433+
if (typeof ret == "object") {
434+
if (!ret.meta)
435+
ret.meta = {};
436+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
437+
if (res.headers[header])
438+
ret.meta[header] = res.headers[header];
439+
});
440+
}
396441

397442
if (callback)
398443
callback(null, ret);
@@ -420,7 +465,10 @@ var events = module.exports = {
420465

421466
var ret;
422467
try {
423-
ret = res.data && JSON.parse(res.data);
468+
ret = res.data;
469+
var contentType = res.headers["content-type"];
470+
if (contentType && contentType.indexOf("application/json") !== -1)
471+
ret = JSON.parse(ret);
424472
}
425473
catch (ex) {
426474
if (callback)
@@ -430,12 +478,14 @@ var events = module.exports = {
430478

431479
if (!ret)
432480
ret = {};
433-
if (!ret.meta)
434-
ret.meta = {};
435-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
436-
if (res.headers[header])
437-
ret.meta[header] = res.headers[header];
438-
});
481+
if (typeof ret == "object") {
482+
if (!ret.meta)
483+
ret.meta = {};
484+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
485+
if (res.headers[header])
486+
ret.meta[header] = res.headers[header];
487+
});
488+
}
439489

440490
if (callback)
441491
callback(null, ret);

‎api/v3.0.0/gists.js

+204-119
Large diffs are not rendered by default.

‎api/v3.0.0/gitdata.js

+156-91
Large diffs are not rendered by default.

‎api/v3.0.0/gitignore.js

+24-14
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ var gitignore = module.exports = {
3737

3838
var ret;
3939
try {
40-
ret = res.data && JSON.parse(res.data);
40+
ret = res.data;
41+
var contentType = res.headers["content-type"];
42+
if (contentType && contentType.indexOf("application/json") !== -1)
43+
ret = JSON.parse(ret);
4144
}
4245
catch (ex) {
4346
if (callback)
@@ -47,12 +50,14 @@ var gitignore = module.exports = {
4750

4851
if (!ret)
4952
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-
});
53+
if (typeof ret == "object") {
54+
if (!ret.meta)
55+
ret.meta = {};
56+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
57+
if (res.headers[header])
58+
ret.meta[header] = res.headers[header];
59+
});
60+
}
5661

5762
if (callback)
5863
callback(null, ret);
@@ -77,7 +82,10 @@ var gitignore = module.exports = {
7782

7883
var ret;
7984
try {
80-
ret = res.data && JSON.parse(res.data);
85+
ret = res.data;
86+
var contentType = res.headers["content-type"];
87+
if (contentType && contentType.indexOf("application/json") !== -1)
88+
ret = JSON.parse(ret);
8189
}
8290
catch (ex) {
8391
if (callback)
@@ -87,12 +95,14 @@ var gitignore = module.exports = {
8795

8896
if (!ret)
8997
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-
});
98+
if (typeof ret == "object") {
99+
if (!ret.meta)
100+
ret.meta = {};
101+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
102+
if (res.headers[header])
103+
ret.meta[header] = res.headers[header];
104+
});
105+
}
96106

97107
if (callback)
98108
callback(null, ret);

‎api/v3.0.0/issues.js

+300-175
Large diffs are not rendered by default.

‎api/v3.0.0/markdown.js

+57-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ var markdown = module.exports = {
3939

4040
var ret;
4141
try {
42-
ret = res.data && JSON.parse(res.data);
42+
ret = res.data;
43+
var contentType = res.headers["content-type"];
44+
if (contentType && contentType.indexOf("application/json") !== -1)
45+
ret = JSON.parse(ret);
4346
}
4447
catch (ex) {
4548
if (callback)
@@ -49,12 +52,59 @@ var markdown = module.exports = {
4952

5053
if (!ret)
5154
ret = {};
52-
if (!ret.meta)
53-
ret.meta = {};
54-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
55-
if (res.headers[header])
56-
ret.meta[header] = res.headers[header];
57-
});
55+
if (typeof ret == "object") {
56+
if (!ret.meta)
57+
ret.meta = {};
58+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
59+
if (res.headers[header])
60+
ret.meta[header] = res.headers[header];
61+
});
62+
}
63+
64+
if (callback)
65+
callback(null, ret);
66+
});
67+
};
68+
69+
/** section: github
70+
* markdown#renderRaw(msg, callback) -> null
71+
* - msg (Object): Object that contains the parameters and their values to be sent to the server.
72+
* - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument.
73+
*
74+
* ##### Params on the `msg` object:
75+
*
76+
* - 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'.
77+
* - data (String): Required. Raw data to send as the body of the request
78+
**/
79+
this.renderRaw = function(msg, block, callback) {
80+
var self = this;
81+
this.client.httpSend(msg, block, function(err, res) {
82+
if (err)
83+
return self.sendError(err, null, msg, callback);
84+
85+
var ret;
86+
try {
87+
ret = res.data;
88+
var contentType = res.headers["content-type"];
89+
if (contentType && contentType.indexOf("application/json") !== -1)
90+
ret = JSON.parse(ret);
91+
}
92+
catch (ex) {
93+
if (callback)
94+
callback(new error.InternalServerError(ex.message), res);
95+
return;
96+
}
97+
98+
if (!ret)
99+
ret = {};
100+
if (typeof ret == "object") {
101+
if (!ret.meta)
102+
ret.meta = {};
103+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
104+
if (res.headers[header])
105+
ret.meta[header] = res.headers[header];
106+
});
107+
}
58108

59109
if (callback)
60110
callback(null, ret);

‎api/v3.0.0/markdownTest.js

+13
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,17 @@ describe("[markdown]", function() {
4040
}
4141
);
4242
});
43+
44+
it("should successfully execute POST /markdown/raw (render)", function(next) {
45+
client.markdown.renderRaw(
46+
{
47+
data: "Hello world github/linguist#1 **cool**, and #1!"
48+
},
49+
function(err, res) {
50+
Assert.equal(err, null);
51+
console.log(res);
52+
next();
53+
}
54+
);
55+
});
4356
});

‎api/v3.0.0/misc.js

+36-21
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ var misc = module.exports = {
3737

3838
var ret;
3939
try {
40-
ret = res.data && JSON.parse(res.data);
40+
ret = res.data;
41+
var contentType = res.headers["content-type"];
42+
if (contentType && contentType.indexOf("application/json") !== -1)
43+
ret = JSON.parse(ret);
4144
}
4245
catch (ex) {
4346
if (callback)
@@ -47,12 +50,14 @@ var misc = module.exports = {
4750

4851
if (!ret)
4952
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-
});
53+
if (typeof ret == "object") {
54+
if (!ret.meta)
55+
ret.meta = {};
56+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
57+
if (res.headers[header])
58+
ret.meta[header] = res.headers[header];
59+
});
60+
}
5661

5762
if (callback)
5863
callback(null, ret);
@@ -77,7 +82,10 @@ var misc = module.exports = {
7782

7883
var ret;
7984
try {
80-
ret = res.data && JSON.parse(res.data);
85+
ret = res.data;
86+
var contentType = res.headers["content-type"];
87+
if (contentType && contentType.indexOf("application/json") !== -1)
88+
ret = JSON.parse(ret);
8189
}
8290
catch (ex) {
8391
if (callback)
@@ -87,12 +95,14 @@ var misc = module.exports = {
8795

8896
if (!ret)
8997
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-
});
98+
if (typeof ret == "object") {
99+
if (!ret.meta)
100+
ret.meta = {};
101+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
102+
if (res.headers[header])
103+
ret.meta[header] = res.headers[header];
104+
});
105+
}
96106

97107
if (callback)
98108
callback(null, ret);
@@ -117,7 +127,10 @@ var misc = module.exports = {
117127

118128
var ret;
119129
try {
120-
ret = res.data && JSON.parse(res.data);
130+
ret = res.data;
131+
var contentType = res.headers["content-type"];
132+
if (contentType && contentType.indexOf("application/json") !== -1)
133+
ret = JSON.parse(ret);
121134
}
122135
catch (ex) {
123136
if (callback)
@@ -127,12 +140,14 @@ var misc = module.exports = {
127140

128141
if (!ret)
129142
ret = {};
130-
if (!ret.meta)
131-
ret.meta = {};
132-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
133-
if (res.headers[header])
134-
ret.meta[header] = res.headers[header];
135-
});
143+
if (typeof ret == "object") {
144+
if (!ret.meta)
145+
ret.meta = {};
146+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
147+
if (res.headers[header])
148+
ret.meta[header] = res.headers[header];
149+
});
150+
}
136151

137152
if (callback)
138153
callback(null, ret);

‎api/v3.0.0/orgs.js

+288-168
Large diffs are not rendered by default.

‎api/v3.0.0/pullRequests.js

+180-105
Large diffs are not rendered by default.

‎api/v3.0.0/releases.js

+120-70
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ var releases = module.exports = {
4040

4141
var ret;
4242
try {
43-
ret = res.data && JSON.parse(res.data);
43+
ret = res.data;
44+
var contentType = res.headers["content-type"];
45+
if (contentType && contentType.indexOf("application/json") !== -1)
46+
ret = JSON.parse(ret);
4447
}
4548
catch (ex) {
4649
if (callback)
@@ -50,12 +53,14 @@ var releases = module.exports = {
5053

5154
if (!ret)
5255
ret = {};
53-
if (!ret.meta)
54-
ret.meta = {};
55-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
56-
if (res.headers[header])
57-
ret.meta[header] = res.headers[header];
58-
});
56+
if (typeof ret == "object") {
57+
if (!ret.meta)
58+
ret.meta = {};
59+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
60+
if (res.headers[header])
61+
ret.meta[header] = res.headers[header];
62+
});
63+
}
5964

6065
if (callback)
6166
callback(null, ret);
@@ -82,7 +87,10 @@ var releases = module.exports = {
8287

8388
var ret;
8489
try {
85-
ret = res.data && JSON.parse(res.data);
90+
ret = res.data;
91+
var contentType = res.headers["content-type"];
92+
if (contentType && contentType.indexOf("application/json") !== -1)
93+
ret = JSON.parse(ret);
8694
}
8795
catch (ex) {
8896
if (callback)
@@ -92,12 +100,14 @@ var releases = module.exports = {
92100

93101
if (!ret)
94102
ret = {};
95-
if (!ret.meta)
96-
ret.meta = {};
97-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
98-
if (res.headers[header])
99-
ret.meta[header] = res.headers[header];
100-
});
103+
if (typeof ret == "object") {
104+
if (!ret.meta)
105+
ret.meta = {};
106+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
107+
if (res.headers[header])
108+
ret.meta[header] = res.headers[header];
109+
});
110+
}
101111

102112
if (callback)
103113
callback(null, ret);
@@ -129,7 +139,10 @@ var releases = module.exports = {
129139

130140
var ret;
131141
try {
132-
ret = res.data && JSON.parse(res.data);
142+
ret = res.data;
143+
var contentType = res.headers["content-type"];
144+
if (contentType && contentType.indexOf("application/json") !== -1)
145+
ret = JSON.parse(ret);
133146
}
134147
catch (ex) {
135148
if (callback)
@@ -139,12 +152,14 @@ var releases = module.exports = {
139152

140153
if (!ret)
141154
ret = {};
142-
if (!ret.meta)
143-
ret.meta = {};
144-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
145-
if (res.headers[header])
146-
ret.meta[header] = res.headers[header];
147-
});
155+
if (typeof ret == "object") {
156+
if (!ret.meta)
157+
ret.meta = {};
158+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
159+
if (res.headers[header])
160+
ret.meta[header] = res.headers[header];
161+
});
162+
}
148163

149164
if (callback)
150165
callback(null, ret);
@@ -177,7 +192,10 @@ var releases = module.exports = {
177192

178193
var ret;
179194
try {
180-
ret = res.data && JSON.parse(res.data);
195+
ret = res.data;
196+
var contentType = res.headers["content-type"];
197+
if (contentType && contentType.indexOf("application/json") !== -1)
198+
ret = JSON.parse(ret);
181199
}
182200
catch (ex) {
183201
if (callback)
@@ -187,12 +205,14 @@ var releases = module.exports = {
187205

188206
if (!ret)
189207
ret = {};
190-
if (!ret.meta)
191-
ret.meta = {};
192-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
193-
if (res.headers[header])
194-
ret.meta[header] = res.headers[header];
195-
});
208+
if (typeof ret == "object") {
209+
if (!ret.meta)
210+
ret.meta = {};
211+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
212+
if (res.headers[header])
213+
ret.meta[header] = res.headers[header];
214+
});
215+
}
196216

197217
if (callback)
198218
callback(null, ret);
@@ -219,7 +239,10 @@ var releases = module.exports = {
219239

220240
var ret;
221241
try {
222-
ret = res.data && JSON.parse(res.data);
242+
ret = res.data;
243+
var contentType = res.headers["content-type"];
244+
if (contentType && contentType.indexOf("application/json") !== -1)
245+
ret = JSON.parse(ret);
223246
}
224247
catch (ex) {
225248
if (callback)
@@ -229,12 +252,14 @@ var releases = module.exports = {
229252

230253
if (!ret)
231254
ret = {};
232-
if (!ret.meta)
233-
ret.meta = {};
234-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
235-
if (res.headers[header])
236-
ret.meta[header] = res.headers[header];
237-
});
255+
if (typeof ret == "object") {
256+
if (!ret.meta)
257+
ret.meta = {};
258+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
259+
if (res.headers[header])
260+
ret.meta[header] = res.headers[header];
261+
});
262+
}
238263

239264
if (callback)
240265
callback(null, ret);
@@ -261,7 +286,10 @@ var releases = module.exports = {
261286

262287
var ret;
263288
try {
264-
ret = res.data && JSON.parse(res.data);
289+
ret = res.data;
290+
var contentType = res.headers["content-type"];
291+
if (contentType && contentType.indexOf("application/json") !== -1)
292+
ret = JSON.parse(ret);
265293
}
266294
catch (ex) {
267295
if (callback)
@@ -271,12 +299,14 @@ var releases = module.exports = {
271299

272300
if (!ret)
273301
ret = {};
274-
if (!ret.meta)
275-
ret.meta = {};
276-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
277-
if (res.headers[header])
278-
ret.meta[header] = res.headers[header];
279-
});
302+
if (typeof ret == "object") {
303+
if (!ret.meta)
304+
ret.meta = {};
305+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
306+
if (res.headers[header])
307+
ret.meta[header] = res.headers[header];
308+
});
309+
}
280310

281311
if (callback)
282312
callback(null, ret);
@@ -303,7 +333,10 @@ var releases = module.exports = {
303333

304334
var ret;
305335
try {
306-
ret = res.data && JSON.parse(res.data);
336+
ret = res.data;
337+
var contentType = res.headers["content-type"];
338+
if (contentType && contentType.indexOf("application/json") !== -1)
339+
ret = JSON.parse(ret);
307340
}
308341
catch (ex) {
309342
if (callback)
@@ -313,12 +346,14 @@ var releases = module.exports = {
313346

314347
if (!ret)
315348
ret = {};
316-
if (!ret.meta)
317-
ret.meta = {};
318-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
319-
if (res.headers[header])
320-
ret.meta[header] = res.headers[header];
321-
});
349+
if (typeof ret == "object") {
350+
if (!ret.meta)
351+
ret.meta = {};
352+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
353+
if (res.headers[header])
354+
ret.meta[header] = res.headers[header];
355+
});
356+
}
322357

323358
if (callback)
324359
callback(null, ret);
@@ -346,7 +381,10 @@ var releases = module.exports = {
346381

347382
var ret;
348383
try {
349-
ret = res.data && JSON.parse(res.data);
384+
ret = res.data;
385+
var contentType = res.headers["content-type"];
386+
if (contentType && contentType.indexOf("application/json") !== -1)
387+
ret = JSON.parse(ret);
350388
}
351389
catch (ex) {
352390
if (callback)
@@ -356,12 +394,14 @@ var releases = module.exports = {
356394

357395
if (!ret)
358396
ret = {};
359-
if (!ret.meta)
360-
ret.meta = {};
361-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
362-
if (res.headers[header])
363-
ret.meta[header] = res.headers[header];
364-
});
397+
if (typeof ret == "object") {
398+
if (!ret.meta)
399+
ret.meta = {};
400+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
401+
if (res.headers[header])
402+
ret.meta[header] = res.headers[header];
403+
});
404+
}
365405

366406
if (callback)
367407
callback(null, ret);
@@ -390,7 +430,10 @@ var releases = module.exports = {
390430

391431
var ret;
392432
try {
393-
ret = res.data && JSON.parse(res.data);
433+
ret = res.data;
434+
var contentType = res.headers["content-type"];
435+
if (contentType && contentType.indexOf("application/json") !== -1)
436+
ret = JSON.parse(ret);
394437
}
395438
catch (ex) {
396439
if (callback)
@@ -400,12 +443,14 @@ var releases = module.exports = {
400443

401444
if (!ret)
402445
ret = {};
403-
if (!ret.meta)
404-
ret.meta = {};
405-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
406-
if (res.headers[header])
407-
ret.meta[header] = res.headers[header];
408-
});
446+
if (typeof ret == "object") {
447+
if (!ret.meta)
448+
ret.meta = {};
449+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
450+
if (res.headers[header])
451+
ret.meta[header] = res.headers[header];
452+
});
453+
}
409454

410455
if (callback)
411456
callback(null, ret);
@@ -432,7 +477,10 @@ var releases = module.exports = {
432477

433478
var ret;
434479
try {
435-
ret = res.data && JSON.parse(res.data);
480+
ret = res.data;
481+
var contentType = res.headers["content-type"];
482+
if (contentType && contentType.indexOf("application/json") !== -1)
483+
ret = JSON.parse(ret);
436484
}
437485
catch (ex) {
438486
if (callback)
@@ -442,12 +490,14 @@ var releases = module.exports = {
442490

443491
if (!ret)
444492
ret = {};
445-
if (!ret.meta)
446-
ret.meta = {};
447-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
448-
if (res.headers[header])
449-
ret.meta[header] = res.headers[header];
450-
});
493+
if (typeof ret == "object") {
494+
if (!ret.meta)
495+
ret.meta = {};
496+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
497+
if (res.headers[header])
498+
ret.meta[header] = res.headers[header];
499+
});
500+
}
451501

452502
if (callback)
453503
callback(null, ret);

‎api/v3.0.0/repos.js

+876-511
Large diffs are not rendered by default.

‎api/v3.0.0/routes.json

+16-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"If-None-Match",
2727
"Cookie",
2828
"User-Agent",
29-
"Accept",
3029
"X-GitHub-OTP"
3130
],
3231
"params": {
@@ -345,6 +344,13 @@
345344
"invalidmsg": "",
346345
"description": "Search Term",
347346
"combined": true
347+
},
348+
"data": {
349+
"type": "String",
350+
"required": true,
351+
"validation": "",
352+
"invalidmsg": "",
353+
"description": "Raw data to send as the body of the request"
348354
}
349355
}
350356
},
@@ -3847,6 +3853,15 @@
38473853
"description": "The repository context, only taken into account when rendering as `gfm`"
38483854
}
38493855
}
3856+
},
3857+
3858+
"render-raw": {
3859+
"url": "/markdown/raw",
3860+
"method": "POST",
3861+
"requestFormat": "raw",
3862+
"params": {
3863+
"$data": null
3864+
}
38503865
}
38513866
},
38523867

‎api/v3.0.0/search.js

+60-35
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ var search = module.exports = {
4141

4242
var ret;
4343
try {
44-
ret = res.data && JSON.parse(res.data);
44+
ret = res.data;
45+
var contentType = res.headers["content-type"];
46+
if (contentType && contentType.indexOf("application/json") !== -1)
47+
ret = JSON.parse(ret);
4548
}
4649
catch (ex) {
4750
if (callback)
@@ -51,12 +54,14 @@ var search = module.exports = {
5154

5255
if (!ret)
5356
ret = {};
54-
if (!ret.meta)
55-
ret.meta = {};
56-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
57-
if (res.headers[header])
58-
ret.meta[header] = res.headers[header];
59-
});
57+
if (typeof ret == "object") {
58+
if (!ret.meta)
59+
ret.meta = {};
60+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
61+
if (res.headers[header])
62+
ret.meta[header] = res.headers[header];
63+
});
64+
}
6065

6166
if (callback)
6267
callback(null, ret);
@@ -85,7 +90,10 @@ var search = module.exports = {
8590

8691
var ret;
8792
try {
88-
ret = res.data && JSON.parse(res.data);
93+
ret = res.data;
94+
var contentType = res.headers["content-type"];
95+
if (contentType && contentType.indexOf("application/json") !== -1)
96+
ret = JSON.parse(ret);
8997
}
9098
catch (ex) {
9199
if (callback)
@@ -95,12 +103,14 @@ var search = module.exports = {
95103

96104
if (!ret)
97105
ret = {};
98-
if (!ret.meta)
99-
ret.meta = {};
100-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
101-
if (res.headers[header])
102-
ret.meta[header] = res.headers[header];
103-
});
106+
if (typeof ret == "object") {
107+
if (!ret.meta)
108+
ret.meta = {};
109+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
110+
if (res.headers[header])
111+
ret.meta[header] = res.headers[header];
112+
});
113+
}
104114

105115
if (callback)
106116
callback(null, ret);
@@ -129,7 +139,10 @@ var search = module.exports = {
129139

130140
var ret;
131141
try {
132-
ret = res.data && JSON.parse(res.data);
142+
ret = res.data;
143+
var contentType = res.headers["content-type"];
144+
if (contentType && contentType.indexOf("application/json") !== -1)
145+
ret = JSON.parse(ret);
133146
}
134147
catch (ex) {
135148
if (callback)
@@ -139,12 +152,14 @@ var search = module.exports = {
139152

140153
if (!ret)
141154
ret = {};
142-
if (!ret.meta)
143-
ret.meta = {};
144-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
145-
if (res.headers[header])
146-
ret.meta[header] = res.headers[header];
147-
});
155+
if (typeof ret == "object") {
156+
if (!ret.meta)
157+
ret.meta = {};
158+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
159+
if (res.headers[header])
160+
ret.meta[header] = res.headers[header];
161+
});
162+
}
148163

149164
if (callback)
150165
callback(null, ret);
@@ -173,7 +188,10 @@ var search = module.exports = {
173188

174189
var ret;
175190
try {
176-
ret = res.data && JSON.parse(res.data);
191+
ret = res.data;
192+
var contentType = res.headers["content-type"];
193+
if (contentType && contentType.indexOf("application/json") !== -1)
194+
ret = JSON.parse(ret);
177195
}
178196
catch (ex) {
179197
if (callback)
@@ -183,12 +201,14 @@ var search = module.exports = {
183201

184202
if (!ret)
185203
ret = {};
186-
if (!ret.meta)
187-
ret.meta = {};
188-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
189-
if (res.headers[header])
190-
ret.meta[header] = res.headers[header];
191-
});
204+
if (typeof ret == "object") {
205+
if (!ret.meta)
206+
ret.meta = {};
207+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
208+
if (res.headers[header])
209+
ret.meta[header] = res.headers[header];
210+
});
211+
}
192212

193213
if (callback)
194214
callback(null, ret);
@@ -213,7 +233,10 @@ var search = module.exports = {
213233

214234
var ret;
215235
try {
216-
ret = res.data && JSON.parse(res.data);
236+
ret = res.data;
237+
var contentType = res.headers["content-type"];
238+
if (contentType && contentType.indexOf("application/json") !== -1)
239+
ret = JSON.parse(ret);
217240
}
218241
catch (ex) {
219242
if (callback)
@@ -223,12 +246,14 @@ var search = module.exports = {
223246

224247
if (!ret)
225248
ret = {};
226-
if (!ret.meta)
227-
ret.meta = {};
228-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
229-
if (res.headers[header])
230-
ret.meta[header] = res.headers[header];
231-
});
249+
if (typeof ret == "object") {
250+
if (!ret.meta)
251+
ret.meta = {};
252+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
253+
if (res.headers[header])
254+
ret.meta[header] = res.headers[header];
255+
});
256+
}
232257

233258
if (callback)
234259
callback(null, ret);

‎api/v3.0.0/statuses.js

+36-21
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ var statuses = module.exports = {
3939

4040
var ret;
4141
try {
42-
ret = res.data && JSON.parse(res.data);
42+
ret = res.data;
43+
var contentType = res.headers["content-type"];
44+
if (contentType && contentType.indexOf("application/json") !== -1)
45+
ret = JSON.parse(ret);
4346
}
4447
catch (ex) {
4548
if (callback)
@@ -49,12 +52,14 @@ var statuses = module.exports = {
4952

5053
if (!ret)
5154
ret = {};
52-
if (!ret.meta)
53-
ret.meta = {};
54-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
55-
if (res.headers[header])
56-
ret.meta[header] = res.headers[header];
57-
});
55+
if (typeof ret == "object") {
56+
if (!ret.meta)
57+
ret.meta = {};
58+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
59+
if (res.headers[header])
60+
ret.meta[header] = res.headers[header];
61+
});
62+
}
5863

5964
if (callback)
6065
callback(null, ret);
@@ -81,7 +86,10 @@ var statuses = module.exports = {
8186

8287
var ret;
8388
try {
84-
ret = res.data && JSON.parse(res.data);
89+
ret = res.data;
90+
var contentType = res.headers["content-type"];
91+
if (contentType && contentType.indexOf("application/json") !== -1)
92+
ret = JSON.parse(ret);
8593
}
8694
catch (ex) {
8795
if (callback)
@@ -91,12 +99,14 @@ var statuses = module.exports = {
9199

92100
if (!ret)
93101
ret = {};
94-
if (!ret.meta)
95-
ret.meta = {};
96-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
97-
if (res.headers[header])
98-
ret.meta[header] = res.headers[header];
99-
});
102+
if (typeof ret == "object") {
103+
if (!ret.meta)
104+
ret.meta = {};
105+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
106+
if (res.headers[header])
107+
ret.meta[header] = res.headers[header];
108+
});
109+
}
100110

101111
if (callback)
102112
callback(null, ret);
@@ -127,7 +137,10 @@ var statuses = module.exports = {
127137

128138
var ret;
129139
try {
130-
ret = res.data && JSON.parse(res.data);
140+
ret = res.data;
141+
var contentType = res.headers["content-type"];
142+
if (contentType && contentType.indexOf("application/json") !== -1)
143+
ret = JSON.parse(ret);
131144
}
132145
catch (ex) {
133146
if (callback)
@@ -137,12 +150,14 @@ var statuses = module.exports = {
137150

138151
if (!ret)
139152
ret = {};
140-
if (!ret.meta)
141-
ret.meta = {};
142-
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
143-
if (res.headers[header])
144-
ret.meta[header] = res.headers[header];
145-
});
153+
if (typeof ret == "object") {
154+
if (!ret.meta)
155+
ret.meta = {};
156+
["x-ratelimit-limit", "x-ratelimit-remaining", "x-ratelimit-reset", "x-oauth-scopes", "link", "location", "last-modified", "etag", "status"].forEach(function(header) {
157+
if (res.headers[header])
158+
ret.meta[header] = res.headers[header];
159+
});
160+
}
146161

147162
if (callback)
148163
callback(null, ret);

‎api/v3.0.0/user.js

+264-154
Large diffs are not rendered by default.

‎index.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -573,13 +573,20 @@ var Client = module.exports = function(config) {
573573
getPage.call(this, link, "first", callback);
574574
};
575575

576+
function getRequestFormat(hasBody, block) {
577+
if (hasBody)
578+
return block.requestFormat || this.constants.requestFormat;
579+
580+
return "query";
581+
}
582+
576583
function getQueryAndUrl(msg, def, format, config) {
577584
var url = def.url;
578585
if (config.pathPrefix && url.indexOf(config.pathPrefix) !== 0) {
579586
url = config.pathPrefix + def.url;
580587
}
581588
var ret = {
582-
query: format == "json" ? {} : []
589+
query: format == "json" ? {} : format == "raw" ? msg.data : []
583590
};
584591
if (!def || !def.params) {
585592
ret.url = url;
@@ -625,7 +632,7 @@ var Client = module.exports = function(config) {
625632
else {
626633
if (format == "json")
627634
ret.query[paramName] = val;
628-
else
635+
else if (format != "raw")
629636
ret.query.push(paramName + "=" + val);
630637
}
631638
});
@@ -649,9 +656,7 @@ var Client = module.exports = function(config) {
649656
var method = block.method.toLowerCase();
650657
var hasFileBody = block.hasFileBody;
651658
var hasBody = !hasFileBody && ("head|get|delete".indexOf(method) === -1);
652-
var format = hasBody && this.constants.requestFormat
653-
? this.constants.requestFormat
654-
: "query";
659+
var format = getRequestFormat.call(this, hasBody, block);
655660
var obj = getQueryAndUrl(msg, block, format, self.config);
656661
var query = obj.query;
657662
var url = this.config.url ? this.config.url + obj.url : obj.url;
@@ -692,12 +697,14 @@ var Client = module.exports = function(config) {
692697
if (hasBody) {
693698
if (format == "json")
694699
query = JSON.stringify(query);
695-
else
700+
else if (format != "raw")
696701
query = query.join("&");
697702
headers["content-length"] = Buffer.byteLength(query, "utf8");
698703
headers["content-type"] = format == "json"
699704
? "application/json; charset=utf-8"
700-
: "application/x-www-form-urlencoded; charset=utf-8";
705+
: format == "raw"
706+
? "text/plain; charset=utf-8"
707+
: "application/x-www-form-urlencoded; charset=utf-8";
701708
}
702709
if (this.auth) {
703710
var basic;

‎templates/after_request.js.tpl

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11

22
if (!ret)
33
ret = {};
4-
if (!ret.meta)
5-
ret.meta = {};
6-
[<%headers%>].forEach(function(header) {
7-
if (res.headers[header])
8-
ret.meta[header] = res.headers[header];
9-
});
4+
if (typeof ret == "object") {
5+
if (!ret.meta)
6+
ret.meta = {};
7+
[<%headers%>].forEach(function(header) {
8+
if (res.headers[header])
9+
ret.meta[header] = res.headers[header];
10+
});
11+
}

‎templates/handler.js.tpl

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
88
var ret;
99
try {
10-
ret = res.data && JSON.parse(res.data);
10+
ret = res.data;
11+
var contentType = res.headers["content-type"];
12+
if (contentType && contentType.indexOf("application/json") !== -1)
13+
ret = JSON.parse(ret);
1114
}
1215
catch (ex) {
1316
if (callback)

0 commit comments

Comments
 (0)
Please sign in to comment.