// @flow
'use strict';

const gist = require('gh-got');

const endpoint = 'https://api.github.com/gists';

const createGist = (token: string, packages: Object): Promise<Object> => {
  return new Promise((resolve, reject) => {
    gist(endpoint, {
      token: token,
      method: 'POST',
      body: { files: {
        'modules.json': {
          content: packages
        }
      }}
    }).then(result => {
      resolve(result.body);
    }).catch(err => {
      reject(err);
    });
  });
};

const updateGist = (token: string, gistId: string, packages: Object): Promise<Object> => {
  return new Promise((resolve, reject) => {
    gist(`${endpoint}/${gistId}`, {
      token: token,
      method: 'PATCH',
      body: { files: {
        'modules.json': {
          content: packages
        }
      }}
    }).then(result => {
      resolve(result.body);
    }).catch(err => {
      reject(err);
    });
  });
};

const readGist = (token: string, gistId: string): Promise<Object> => {
  return new Promise((resolve, reject) => {
    gist(`${endpoint}/${gistId}`, {
      token: token,
      method: 'GET'
    }).then(result => {
      resolve(result.body);
    }).catch(err => {
      reject(err);
    });
  });
};

module.exports = {
  create: createGist,
  update: updateGist,
  read: readGist
};

@@ -96,24 +96,255 @@
 om/gists';%0A%0A
+/**%0A * Creates a private gist containing a single JSON file%0A * @public%0A * @param %7Bstring%7D token - GitHub access token%0A * @param %7BObject%7D packages - Object of NPM packages%0A * @returns %7BPromise.%3CObject%3E%7D - Returns Promise Object%0A */%0A
 const create
@@ -716,24 +716,276 @@
 ;%0A  %7D);%0A%7D;%0A%0A
+/**%0A * Updates an existing gist%0A * @public%0A * @param %7Bstring%7D token - GitHub access token%0A * @param %7Bstring%7D gistId - ID of gist to update%0A * @param %7BObject%7D packages - Object of NPM packages%0A * @returns %7BPromise.%3CObject%3E%7D - Returns Promise Object%0A */%0A
 const update
@@ -1393,16 +1393,222 @@
 %7D);%0A%7D;%0A%0A
+/**%0A * Read the contents of a given gist%0A * @public%0A * @param %7Bstring%7D token - GitHub access token%0A * @param %7Bstring%7D gistId - ID of gist to read%0A * @returns %7BPromise.%3CObject%3E%7D - Returns Promise Object%0A */%0A
 const re

Add JSDoc cooments in gist module