Skip to content

Commit

Permalink
added a cli tool
Browse files Browse the repository at this point in the history
  • Loading branch information
AJ ONeal committed Oct 26, 2012
1 parent 82bb0f6 commit d5a3f14
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 38 deletions.
97 changes: 60 additions & 37 deletions Readme.md
@@ -1,49 +1,72 @@
Node.js Gist client ## Node.js Gist client
===================
Gist API v3 client for Node.JS Gist API v3 client for Node.JS


Usage ## Installation
------
var gist = require('gist')(validOAuthToken); For use in your modules (adds to package.json automatically)


// get all your gists (or all public if you didnt specify a token) npm install -S gist
gist.gists(function(err, resp, json) {
console.log(err, json) For the commandline gist
})

npm install -g gist
// get all public gists for some user
gist.gists('maxogden', function(err, resp, json) { ## Usage
console.log(err, json)
}) ### Commandline


// get a gist by id gist </path/to/file>
gist.gist('2698151', function(err, resp, json) {
console.log(err, json) echo "Hello World!" > ./hello.txt
}) gist ./hello.txt


// creating a new gist ### API
var newGist = {
"description": "the description for this gist", * `gist.gists([username], fn)`
"public": false, * `gist.gist(id, fn)`
"files": { * `gist([validOauthToken]).create(newGist, fn)`
"file1.txt": {
"content": "String file contents" ```javascript
} var gist = require('gist')(validOAuthToken);
}
// get all your gists (or all public if you didnt specify a token)
gist.gists(function(err, resp, json) {
console.log(err, json)
})

// get all public gists for some user
gist.gists('maxogden', function(err, resp, json) {
console.log(err, json)
})

// get a gist by id
gist.gist('2698151', function(err, resp, json) {
console.log(err, json)
})

// creating a new gist
var newGist = {
"description": "the description for this gist",
"public": false,
"files": {
"file1.txt": {
"content": "String file contents"
} }
gist(validOauthToken).create(newGist, function(err, resp, json) { }
console.log(err, json) }
}) gist(validOauthToken).create(newGist, function(err, resp, json) {
console.log(err, json)
})
```


## Author


Author
------
* Max Ogden (@maxogden) * Max Ogden (@maxogden)


this library was forked from Emerson Macedo (<http://codificando.com/>) and entirely rewritten this library was forked from Emerson Macedo (<http://codificando.com/>) and entirely rewritten


License: ## License
--------


(The MIT License) (The MIT License)


Expand Down
87 changes: 87 additions & 0 deletions bin/gist.js
@@ -0,0 +1,87 @@
#!/usr/bin/env node
/*jshint strict:true node:true es5:true onevar:true laxcomma:true laxbreak:true eqeqeq:true immed:true latedef:true*/
(function () {
"use strict";

var gist = require('../')
, fs = require('fs')
, filename = process.argv[2]
, desc = process.argv[3]
;

function usage() {
console.log('Usage: gist </path/to/file>');
}

if (!filename) {
usage();
return;
}

fs.readFile(filename, 'utf8', function (err, data) {
var meta
, name = filename.replace(/.*\//, '')
;

if (err) {
usage();
return;
}

meta = {
"description": desc
, "public": true
, "files": {}
};
meta.files[name] = data;

gist().create(meta, function (err, resp, json) {
//console.log(JSON.stringify(json, null, ' '));
console.log('[gist]', json.html_url);
console.log('[raw]', json.files[name].raw_url);
console.log('[git]', json.git_push_url);
});
});

/*
{
"git_push_url": "git@gist.github.com:3960244.git",
"user": null,
"html_url": "https://gist.github.com/3960244",
"history": [
{
"user": null,
"version": "10564662c34f251be04ac7936758e8ff6c6df4a6",
"committed_at": "2012-10-26T17:51:27Z",
"change_status": {
"additions": 1,
"total": 1,
"deletions": 0
},
"url": "https://api.github.com/gists/3960244/10564662c34f251be04ac7936758e8ff6c6df4a6"
}
],
"comments": 0,
"created_at": "2012-10-26T17:51:27Z",
"description": null,
"public": true,
"forks": [],
"updated_at": "2012-10-26T17:51:27Z",
"id": "3960244",
"url": "https://api.github.com/gists/3960244",
"files": {
"index.js": {
"type": "application/javascript",
"filename": "index.js",
"raw_url": "https://gist.github.com/raw/3960244/6b584e8ece562ebffc15d38808cd6b98fc3d97ea/index.js",
"size": 7,
"content": "content",
"language": "JavaScript"
}
},
"git_pull_url": "git://gist.github.com/3960244.git"
}
*/


}());
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -7,13 +7,16 @@
"api", "api",
"package.json" "package.json"
], ],
"version": "0.3.0", "version": "1.0.0",
"author": "Max Ogden <mogden@gmail.com>", "author": "Max Ogden <mogden@gmail.com>",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/maxogden/node-gist.git" "url": "git://github.com/maxogden/node-gist.git"
}, },
"main": "index", "main": "index",
"bin": {
"gist": "bin/gist.js"
},
"engines": { "engines": {
"node": ">=0.6.0" "node": ">=0.6.0"
}, },
Expand Down

0 comments on commit d5a3f14

Please sign in to comment.