UNPKG

7.02 kBSource Map (JSON)View Raw
1{"version":3,"names":[],"mappings":"","sources":["Gist.js"],"sourcesContent":["/**\n * @file\n * @copyright 2013 Michael Aufreiter (Development Seed) and 2016 Yahoo Inc.\n * @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.\n * Github.js is freely distributable.\n */\n\nimport Requestable from './Requestable';\n\n/**\n * A Gist can retrieve and modify gists.\n */\nclass Gist extends Requestable {\n /**\n * Create a Gist.\n * @param {string} id - the id of the gist (not required when creating a gist)\n * @param {Requestable.auth} [auth] - information required to authenticate to Github\n * @param {string} [apiBase=https://api.github.com] - the base Github API URL\n */\n constructor(id, auth, apiBase) {\n super(auth, apiBase);\n this.__id = id;\n }\n\n /**\n * Fetch a gist.\n * @see https://developer.github.com/v3/gists/#get-a-single-gist\n * @param {Requestable.callback} [cb] - will receive the gist\n * @return {Promise} - the Promise for the http request\n */\n read(cb) {\n return this._request('GET', `/gists/${this.__id}`, null, cb);\n }\n\n /**\n * Create a new gist.\n * @see https://developer.github.com/v3/gists/#create-a-gist\n * @param {Object} gist - the data for the new gist\n * @param {Requestable.callback} [cb] - will receive the new gist upon creation\n * @return {Promise} - the Promise for the http request\n */\n create(gist, cb) {\n return this._request('POST', '/gists', gist, cb)\n .then((response) => {\n this.__id = response.data.id;\n return response;\n });\n }\n\n /**\n * Delete a gist.\n * @see https://developer.github.com/v3/gists/#delete-a-gist\n * @param {Requestable.callback} [cb] - will receive true if the request succeeds\n * @return {Promise} - the Promise for the http request\n */\n delete(cb) {\n return this._request('DELETE', `/gists/${this.__id}`, null, cb);\n }\n\n /**\n * Fork a gist.\n * @see https://developer.github.com/v3/gists/#fork-a-gist\n * @param {Requestable.callback} [cb] - the function that will receive the gist\n * @return {Promise} - the Promise for the http request\n */\n fork(cb) {\n return this._request('POST', `/gists/${this.__id}/forks`, null, cb);\n }\n\n /**\n * Update a gist.\n * @see https://developer.github.com/v3/gists/#edit-a-gist\n * @param {Object} gist - the new data for the gist\n * @param {Requestable.callback} [cb] - the function that receives the API result\n * @return {Promise} - the Promise for the http request\n */\n update(gist, cb) {\n return this._request('PATCH', `/gists/${this.__id}`, gist, cb);\n }\n\n /**\n * Star a gist.\n * @see https://developer.github.com/v3/gists/#star-a-gist\n * @param {Requestable.callback} [cb] - will receive true if the request is successful\n * @return {Promise} - the Promise for the http request\n */\n star(cb) {\n return this._request('PUT', `/gists/${this.__id}/star`, null, cb);\n }\n\n /**\n * Unstar a gist.\n * @see https://developer.github.com/v3/gists/#unstar-a-gist\n * @param {Requestable.callback} [cb] - will receive true if the request is successful\n * @return {Promise} - the Promise for the http request\n */\n unstar(cb) {\n return this._request('DELETE', `/gists/${this.__id}/star`, null, cb);\n }\n\n /**\n * Check if a gist is starred by the user.\n * @see https://developer.github.com/v3/gists/#check-if-a-gist-is-starred\n * @param {Requestable.callback} [cb] - will receive true if the gist is starred and false if the gist is not starred\n * @return {Promise} - the Promise for the http request\n */\n isStarred(cb) {\n return this._request204or404(`/gists/${this.__id}/star`, null, cb);\n }\n\n /**\n * List the gist's commits\n * @see https://developer.github.com/v3/gists/#list-gist-commits\n * @param {Requestable.callback} [cb] - will receive the array of commits\n * @return {Promise} - the Promise for the http request\n */\n listCommits(cb) {\n return this._requestAllPages(`/gists/${this.__id}/commits`, null, cb);\n }\n\n /**\n * Fetch one of the gist's revision.\n * @see https://developer.github.com/v3/gists/#get-a-specific-revision-of-a-gist\n * @param {string} revision - the id of the revision\n * @param {Requestable.callback} [cb] - will receive the revision\n * @return {Promise} - the Promise for the http request\n */\n getRevision(revision, cb) {\n return this._request('GET', `/gists/${this.__id}/${revision}`, null, cb);\n }\n\n /**\n * List the gist's comments\n * @see https://developer.github.com/v3/gists/comments/#list-comments-on-a-gist\n * @param {Requestable.callback} [cb] - will receive the array of comments\n * @return {Promise} - the promise for the http request\n */\n listComments(cb) {\n return this._requestAllPages(`/gists/${this.__id}/comments`, null, cb);\n }\n\n /**\n * Fetch one of the gist's comments\n * @see https://developer.github.com/v3/gists/comments/#get-a-single-comment\n * @param {number} comment - the id of the comment\n * @param {Requestable.callback} [cb] - will receive the comment\n * @return {Promise} - the Promise for the http request\n */\n getComment(comment, cb) {\n return this._request('GET', `/gists/${this.__id}/comments/${comment}`, null, cb);\n }\n\n /**\n * Comment on a gist\n * @see https://developer.github.com/v3/gists/comments/#create-a-comment\n * @param {string} comment - the comment to add\n * @param {Requestable.callback} [cb] - the function that receives the API result\n * @return {Promise} - the Promise for the http request\n */\n createComment(comment, cb) {\n return this._request('POST', `/gists/${this.__id}/comments`, {body: comment}, cb);\n }\n\n /**\n * Edit a comment on the gist\n * @see https://developer.github.com/v3/gists/comments/#edit-a-comment\n * @param {number} comment - the id of the comment\n * @param {string} body - the new comment\n * @param {Requestable.callback} [cb] - will receive the modified comment\n * @return {Promise} - the promise for the http request\n */\n editComment(comment, body, cb) {\n return this._request('PATCH', `/gists/${this.__id}/comments/${comment}`, {body: body}, cb);\n }\n\n /**\n * Delete a comment on the gist.\n * @see https://developer.github.com/v3/gists/comments/#delete-a-comment\n * @param {number} comment - the id of the comment\n * @param {Requestable.callback} [cb] - will receive true if the request succeeds\n * @return {Promise} - the Promise for the http request\n */\n deleteComment(comment, cb) {\n return this._request('DELETE', `/gists/${this.__id}/comments/${comment}`, null, cb);\n }\n}\n\nmodule.exports = Gist;\n"],"file":"Gist.js"}
\No newline at end of file