Treat your gist account like a database
npm install --save gist-db
var config =github:username: "mcwhittemore"var db = config;dbevent;dbevent;
id = gist_id+"_"+filenamefilename = filenamegist_id = gist_iderror: undefinedraw: "THE RAW VALUE OF THE FILE"type: "mime type"language: "language the file is written in"raw_url: "https path to the raw text version of the file"size: numeric size of the filegist:id: gist_idpublic: booleancreated_at: date objectupdated_at: date objectdescription: "the gist description"
# Clone the repositorygit clone https://github.com/pinn3/gist-db# Install dependencies, this will also run the build scriptnpm install# Try out the demo!node demo/demo.js
Please refer to the TaffyDB docs for more details
Create a new gist-db.
Required:github:username:"SOME_USER_NAME"Defaults:refreshMin: 10github:per_page: 100timeout: 5000version: "3.0.0"local:save: "NEVER" //NEVER, ON_REFRESH, ALWAYSlocation: undefinedAvailable:refreshMin: 10github:per_page: 100timeout: 5000version: "3.0.0"authenticate:type: "basic or oauth"username: "your_username_if_basic"password: "your_password_if_basic"token: "your_oauth_token_if_oauth"local:save: "NEVER OR NEVER OR ON_REFRESH OR ALWAYS"location: "path and filename"
fileInit: function(file). A function that returns the file obj if it should be added to the DB and undefined if it should be excluded.
fileSave: function(file, callback). A function that allows for further parameter work on files after the raw data has been received. A functioning implementation of this MUST pass the file object as a parameter to callback to save changes to the DB. Note: this will perform an update to the database.
Returns: All rows that meet the passed criteria. Not passing an object, will return all rows.
Inserts records into the database.
Full use of the github module passed the github subsection of your config file.
An implementation of require("events").EventEmitter
Use to be notified when gist-db is connecting gist for a refresh.
Use to be notified when gist-db is done its current refresh. If err is set, this refresh was ended due to error.
Use to be notified of errors in gathering data on the gist files.
Use to be notified of errors when connecting with github.
err: the github module error object that triggered this event
res: The github module response object. Might contain good data about the error.
Added gist object to file for meta data on the gist the file is from.
Changed database refresh to use merge rather than insert so items won't duplicate
Added check just before getRawFile and the add to database that checks if the file is in the db and if it is compares if the gist.updated_at of the new file is newer than that of the old file. This was can lower the number of calls to github and speed up the code a bit.
Changed github module to be my fork which supports since on the gist endpoints. Will change back once a new version of node-github is in NPM
Added since param to github calls, so we will only return gists added/edited since our last call.
config.local.savewas set to
All code not otherwise specified is Copyright 2016 Jonathan Nguyen and is released under the MIT License.
All code found in the node_modules directory is Copyrighted by its creators. Please see each module for further details.