Skip to content

Commit 7e57ce4

Browse files
committed
Merge pull request #2 from coolaj86/added-bin
Added bin and pulled all forks together
2 parents 78166bf + 987c165 commit 7e57ce4

File tree

3 files changed

+186
-47
lines changed

3 files changed

+186
-47
lines changed

Readme.md

Lines changed: 60 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,72 @@
1-
Node.js Gist client
2-
===================
1+
## Node.js Gist client
2+
33
Gist API v3 client for Node.JS
44

5-
Usage
6-
------
7-
var gist = require('gist')(validOAuthToken);
8-
9-
// get all your gists (or all public if you didnt specify a token)
10-
gist.gists(function(err, resp, json) {
11-
console.log(err, json)
12-
})
13-
14-
// get all public gists for some user
15-
gist.gists('maxogden', function(err, resp, json) {
16-
console.log(err, json)
17-
})
18-
19-
// get a gist by id
20-
gist.gist('2698151', function(err, resp, json) {
21-
console.log(err, json)
22-
})
23-
24-
// creating a new gist
25-
var newGist = {
26-
"description": "the description for this gist",
27-
"public": false,
28-
"files": {
29-
"file1.txt": {
30-
"content": "String file contents"
31-
}
32-
}
5+
## Installation
6+
7+
For use in your modules (adds to package.json automatically)
8+
9+
npm install -S gist
10+
11+
For the commandline gist
12+
13+
npm install -g gist
14+
15+
## Usage
16+
17+
### Commandline
18+
19+
gist </path/to/file>
20+
21+
echo "Hello World!" > ./hello.txt
22+
gist ./hello.txt
23+
24+
### API
25+
26+
* `gist.gists([username], fn)`
27+
* `gist.gist(id, fn)`
28+
* `gist([validOauthToken]).create(newGist, fn)`
29+
30+
```javascript
31+
var gist = require('gist')(validOAuthToken);
32+
33+
// get all your gists (or all public if you didnt specify a token)
34+
gist.gists(function(err, resp, json) {
35+
console.log(err, json)
36+
})
37+
38+
// get all public gists for some user
39+
gist.gists('maxogden', function(err, resp, json) {
40+
console.log(err, json)
41+
})
42+
43+
// get a gist by id
44+
gist.gist('2698151', function(err, resp, json) {
45+
console.log(err, json)
46+
})
47+
48+
// creating a new gist
49+
var newGist = {
50+
"description": "the description for this gist",
51+
"public": false,
52+
"files": {
53+
"file1.txt": {
54+
"content": "String file contents"
3355
}
34-
gist(validOauthToken).create(newGist, function(err, resp, json) {
35-
console.log(err, json)
36-
})
56+
}
57+
}
58+
gist(validOauthToken).create(newGist, function(err, resp, json) {
59+
console.log(err, json)
60+
})
61+
```
3762

63+
## Author
3864

39-
Author
40-
------
4165
* Max Ogden (@maxogden)
4266

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

45-
License:
46-
--------
69+
## License
4770

4871
(The MIT License)
4972

bin/gist.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env node
2+
/*jshint strict:true node:true es5:true onevar:true laxcomma:true laxbreak:true eqeqeq:true immed:true latedef:true*/
3+
(function () {
4+
"use strict";
5+
6+
var gist = require('../')
7+
, fs = require('fs')
8+
, filepath = process.argv[2]
9+
, desc = process.argv[3]
10+
;
11+
12+
function usage() {
13+
console.log('Usage: gist </path/to/file>');
14+
}
15+
16+
if (!filepath) {
17+
usage();
18+
return;
19+
}
20+
21+
fs.readFile(filepath, 'utf8', function (err, data) {
22+
var meta
23+
, filename = filepath.replace(/.*\//, '')
24+
;
25+
26+
//filename = 'index.js';
27+
28+
if (err) {
29+
usage();
30+
return;
31+
}
32+
33+
meta = {
34+
"description": desc || ""
35+
, "public": true
36+
, "files": {}
37+
};
38+
meta.files[filename] = { content: data };
39+
40+
gist().create(meta, function (err, resp, json) {
41+
if (err) {
42+
console.error(err);
43+
return;
44+
}
45+
46+
if (json.errors) {
47+
console.log('[DEBUG]');
48+
console.log(JSON.stringify(meta, null, ' '));
49+
console.log('[GIST ERROR]');
50+
console.log(JSON.stringify(json, null, ' '));
51+
return;
52+
}
53+
54+
console.log('[gist]', json.html_url);
55+
console.log('[raw]', json.files[filename].raw_url);
56+
console.log('[git]', json.git_push_url);
57+
});
58+
});
59+
60+
/*
61+
{
62+
"git_push_url": "git@gist.github.com:3960244.git",
63+
"user": null,
64+
"html_url": "https://gist.github.com/3960244",
65+
"history": [
66+
{
67+
"user": null,
68+
"version": "10564662c34f251be04ac7936758e8ff6c6df4a6",
69+
"committed_at": "2012-10-26T17:51:27Z",
70+
"change_status": {
71+
"additions": 1,
72+
"total": 1,
73+
"deletions": 0
74+
},
75+
"url": "https://api.github.com/gists/3960244/10564662c34f251be04ac7936758e8ff6c6df4a6"
76+
}
77+
],
78+
"comments": 0,
79+
"created_at": "2012-10-26T17:51:27Z",
80+
"description": null,
81+
"public": true,
82+
"forks": [],
83+
"updated_at": "2012-10-26T17:51:27Z",
84+
"id": "3960244",
85+
"url": "https://api.github.com/gists/3960244",
86+
"files": {
87+
"index.js": {
88+
"type": "application/javascript",
89+
"filename": "index.js",
90+
"raw_url": "https://gist.github.com/raw/3960244/6b584e8ece562ebffc15d38808cd6b98fc3d97ea/index.js",
91+
"size": 7,
92+
"content": "content",
93+
"language": "JavaScript"
94+
}
95+
},
96+
"git_pull_url": "git://gist.github.com/3960244.git"
97+
}
98+
*/
99+
100+
101+
}());

package.json

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1-
{
2-
"name" : "gist",
3-
"description" : "Gist api client for node.js",
4-
"keywords" : [ "gist", "github", "api", "package.json" ],
5-
"version" : "0.3.0",
6-
"author" : "Max Ogden <mogden@gmail.com>",
7-
"repository" : { "type" : "git",
8-
"url" : "git://github.com/maxogden/node-gist.git" },
1+
{
2+
"name": "gist",
3+
"description": "Gist api client for node.js",
4+
"keywords": [
5+
"gist",
6+
"github",
7+
"api",
8+
"package.json"
9+
],
10+
"version": "1.0.2",
11+
"author": "Max Ogden <mogden@gmail.com>",
12+
"repository": {
13+
"type": "git",
14+
"url": "git://github.com/maxogden/node-gist.git"
15+
},
916
"main": "index",
10-
"engines" : { "node" : ">=0.6.0" }
17+
"bin": {
18+
"gist": "bin/gist.js"
19+
},
20+
"engines": {
21+
"node": ">=0.6.0"
22+
},
23+
"dependencies": {
24+
"request": "~2.10.0",
25+
"underscore": "~1.3.3"
26+
}
1127
}
12-

0 commit comments

Comments
 (0)