Skip to content

JS module for data storage & retrieval on Github's Gists

License

Notifications You must be signed in to change notification settings

corbin-c/datagists

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DataGists

DataGists is a project by Clément Corbin. Feel free to contribute.

DataGists is a JS module for data storage & retrieval on Github's Gists. It makes use of Github's API v3.

To run DataGists, import it first:

import { DataGists } from "https://corbin-c.github.io/datagists/DataGists.js";

Once imported, a DataGists object can be created from an Auth Token, obtained from https://github.com/settings/tokens or through OAuth.

let myGists = new DataGists(auth_token);

As this module fetches Github's API, you might want to wait for it being done before doing something else, with await operator. Once created, DataGists object has to be initialized, this will check the auth token:

await myGists.init();

If you don't know which Gists are available, you can simply call:

myGists.listGists();

Once your target Gist is identified, you can start working with it:

let currentGist = await myGists.useGist(gist);

The above gist variable is meant to be an object providing either an ID or a description: (ID is prioritary over description)

gist = {id:id_string,description:gist_description};
//you also could've done it this way:
gist = {id:id_string};
//or maybe this way
gist = {description:gist_description};

Now, getting a file raw content can be achieved easily:

currentGist.getContent(file_name);

Similarly, putting content to a file is done as follow:

currentGist.putContent(file_name,content,[prepend]);

The optional [prepend] parameter is a boolean flag. If set to true, content will be added at the beginning the file instead of overwriting it.

In case you want to create a Gist instead of using an existing one, you can do:

myGists.createGist(file_name,content,[description],[is_public]);

This function returns the created Gist ID so you can later use it with useGist();