@tsukiroku/gist
v1.0.73
Published
Asynchronous gist API wrapper
Readme
Gist API
npm i @tsukiroku/gistDocs
Initialize
Note: Account token required. See Docs
import Gist from '@tsukiroku/gist';
const gist = new Gist('token');Create Gist
| Parameter | Type |
| ------------- | ------------- |
| files | GistFile |
| description | string |
| options? | GistOptions |
GistFile
{ 'file name': { content: 'content' }, ... },
GistOptions
{ secret: boolean, ... }Note: secret default: true
return:
Promise<ReqRet<GistResponse>>
await gist
.create(
{
file_name: { content: 'File Content' },
file_name_2: { content: 'File Content 2' },
},
'test file'
// { secret: true }
)
.then((res) => console.log(`Gist created: ${res.data!.id}`))
.catch((err) => console.log(err));Get Gist
| Parameter | Type |
| --------- | -------- |
| id | number |
return:
Promise<ReqRet<GistResponse>>
await gist
.get('gist id')
.then((res) => console.log(`gist description: ${res.data!.description}`))
.catch((err) => console.log(err));Update Gist
| Parameter | Type |
| ------------- | ------------- |
| id | number |
| files | GistFile |
| description | string |
| options? | GistOptions |
return:
Promise<ReqRet<{}>>Note:
res.datais undefined.
await gist
.update(
'gist id',
{
file_name: { content: 'File Content' },
file_name_2: { content: 'File Content 2' },
file_name_3: { content: 'File Content 3' },
},
'test file - update'
// { secret: true }
)
.then((res) => console.log(`Gist updated: ${res.status.code}`))
.catch((err) => console.log(err));Delete Gist
| Parameter | Type |
| --------- | -------- |
| id | number |
return:
Promise<ReqRet<{}>>Note:
res.datais undefined.
await gist
.delete(gist_id)
.then((res) => console.log(`Gist deleted, status: ${res.status.code}`))
.catch((err) => console.log(err));Status codes
ref: http_status.ts
| Status code | Name | | ----------- | --------------------- | | 200 | OK | | 201 | CREATED | | 204 | NO_CONTENT | | 304 | NOT_MODIFIED | | 400 | BAD_REQUEST | | 401 | UNAUTHORIZED | | 403 | FORBIDDEN | | 404 | NOT_FOUND | | 409 | CONFLICT | | 422 | VAILDATION_FAILED | | 500 | INTERNAL_SERVER_ERROR | | 502 | BAD_GATEWAY | | 503 | SERVICE_UNAVAILABLE | | 504 | GATEWAY_TIMEOUT | | -1 | UNKNOWN |
Click here for more information on the github gists rest API.
