Skip to content

Instantly share code, notes, and snippets.

@enjalot
Created April 26, 2013 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enjalot/5469678 to your computer and use it in GitHub Desktop.
Save enjalot/5469678 to your computer and use it in GitHub Desktop.
create a new gist with github api. change your user-agent appropriately
var url = 'https://api.github.com/gists'
var method = "POST";
var headers = {
'User-Agent': 'tributary'
, 'content-type': 'application/json'
, 'accept': 'application/json'
};
if(token) {
headers['Authorization'] = 'token ' + token;
}
request({
url: url,
body: data.toString(),
method: method,
headers: headers
}, onResponse)
function onResponse(error, response, body) {
if (!error && response.statusCode == 201) {
callback(null, JSON.parse(body));
} else {
callback(error, null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment