Skip to content

Added bin and pulled all forks together #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 20, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 60 additions & 37 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,72 @@
Node.js Gist client
===================
## Node.js Gist client

Gist API v3 client for Node.JS

Usage
------
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"
}
}
## Installation

For use in your modules (adds to package.json automatically)

npm install -S gist

For the commandline gist

npm install -g gist

## Usage

### Commandline

gist </path/to/file>

echo "Hello World!" > ./hello.txt
gist ./hello.txt

### API

* `gist.gists([username], fn)`
* `gist.gist(id, fn)`
* `gist([validOauthToken]).create(newGist, fn)`

```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)

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

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

(The MIT License)

Expand Down
101 changes: 101 additions & 0 deletions bin/gist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/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')
, filepath = process.argv[2]
, desc = process.argv[3]
;

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

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

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

//filename = 'index.js';

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

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

gist().create(meta, function (err, resp, json) {
if (err) {
console.error(err);
return;
}

if (json.errors) {
console.log('[DEBUG]');
console.log(JSON.stringify(meta, null, ' '));
console.log('[GIST ERROR]');
console.log(JSON.stringify(json, null, ' '));
return;
}

console.log('[gist]', json.html_url);
console.log('[raw]', json.files[filename].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"
}
*/


}());
35 changes: 25 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
{
"name" : "gist",
"description" : "Gist api client for node.js",
"keywords" : [ "gist", "github", "api", "package.json" ],
"version" : "0.3.0",
"author" : "Max Ogden <mogden@gmail.com>",
"repository" : { "type" : "git",
"url" : "git://github.com/maxogden/node-gist.git" },
{
"name": "gist",
"description": "Gist api client for node.js",
"keywords": [
"gist",
"github",
"api",
"package.json"
],
"version": "1.0.2",
"author": "Max Ogden <mogden@gmail.com>",
"repository": {
"type": "git",
"url": "git://github.com/maxogden/node-gist.git"
},
"main": "index",
"engines" : { "node" : ">=0.6.0" }
"bin": {
"gist": "bin/gist.js"
},
"engines": {
"node": ">=0.6.0"
},
"dependencies": {
"request": "~2.10.0",
"underscore": "~1.3.3"
}
}