|
| 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 <info@mikedeboer.nl> |
| 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); |
0 commit comments