1+ - [ Gist API] ( ./README.md#gist-api )
2+ - [ Docs] ( ./README.md#docs )
3+ - [ Examples] ( ./README.md#example )
4+ - [ Status codes] ( ./README.md#status-codes )
5+
16# Gist API
27
38``` sh
@@ -12,7 +17,7 @@ npm i @tsukiroku/gist
1217
1318## Initialize
1419
15- > Account token required. See [ Docs] ( https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token )
20+ > ** Note: ** Account token required. See [ Docs] ( https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token )
1621
1722``` ts
1823import Gist from ' @tsukiroku/gist' ;
@@ -42,9 +47,9 @@ const gist = new Gist('token');
4247> { secret: boolean , ... }
4348> ` ` `
4449>
45- > **secret** default: true
50+ > **Note:** ** secret** default: true
4651
47- > **return:** [ ` Promise <GistResponse >` ](./src/types.ts)
52+ > **return:** [ ` Promise <ReqRet < GistResponse > >` ](./src/types.ts)
4853
4954` ` ` ts
5055await gist
@@ -57,7 +62,7 @@ await gist
5762 // { secret: true }
5863 )
5964 .then ((res ) => {
60- console .log (` Gist created: ${gist_id } ` );
65+ console .log (` Gist created: ${res . data ! . id } ` );
6166 })
6267 .catch ((err ) => console .log (err ));
6368```
@@ -70,12 +75,12 @@ await gist
7075| --------- | -------- |
7176| ` id ` | ` number ` |
7277
73- > ** return:** [ ` Promise<GistResponse> ` ] ( ./src/types.ts )
78+ > ** return:** [ ` Promise<ReqRet< GistResponse> > ` ] ( ./src/types.ts )
7479
7580``` ts
7681await gist
7782 .get (' gist id' )
78- .then ((res ) => console .log (` gist description: ${res .description } ` ))
83+ .then ((res ) => console .log (` gist description: ${res .data ! . description } ` ))
7984 .catch ((err ) => console .log (err ));
8085```
8186
@@ -87,11 +92,15 @@ await gist
8792| --------- | -------- |
8893| ` id ` | ` number ` |
8994
95+ > ** return:** [ ` Promise<ReqRet<{}>> ` ] ( ./src/types.ts )
96+ >
97+ > ** Note:** ` res.data ` is undefined.
98+
9099``` ts
91100await gist
92- .delete (' gist id ' )
93- .then ((_ ) => console .log (' deleted' ))
94- .catch (( err ) => console . log ( err ) );
101+ .delete (gist_id )
102+ .then ((res ) => console .log (` Gist deleted, status: ${ res . status . code } ` ))
103+ .catch (errHandler );
95104```
96105
97106<br >
@@ -105,34 +114,63 @@ await gist
105114``` ts
106115import Gist from ' @tsukiroku/gist' ;
107116
117+ const errHandler = (err : any ) => console .log (err );
118+
108119(async () => {
109120 const gist = new Gist (' token' );
110121
111122 let gist_id: string = ' ' ;
112123
113124 await gist
114125 .create (
115- {
116- ' index.ts' : { content: " console.log('Hello, World!');" },
117- ' main.rs' : { content: ' fn main() {}' },
118- },
119- ' test gist' ,
126+ { ' hello.ts' : { content: ' dd' }, ' hello.rs' : { content: ' ddd' } },
127+ ' a test file' ,
120128 { secret: true }
121129 )
122130 .then ((res ) => {
123- gist_id = res .id ;
131+ gist_id = res .data ! . id ;
124132 console .log (` Gist created: ${gist_id } ` );
125133 })
126- .catch (( err ) => console . log ( err ) );
134+ .catch (errHandler );
127135
128136 await gist
129137 .get (gist_id )
130- .then ((res ) => console .log (` gist description: ${res .description } ` ))
131- .catch ((err ) => console .log (err ));
138+ .then ((res ) =>
139+ console .log (` Gist description: ${res .data ! .description } ` )
140+ )
141+ .catch (errHandler );
132142
133143 await gist
134144 .delete (gist_id )
135- .then ((_ ) => console .log (' deleted' ))
136- .catch (( err ) => console . log ( err ) );
145+ .then ((res ) => console .log (` Gist deleted, status: ${ res . status . code } ` ))
146+ .catch (errHandler );
137147})();
138148```
149+
150+ # Status codes
151+
152+ > ** ref:** [ http_status.ts] ( ./src/structures/http_status.ts )
153+
154+ | Status code | Name |
155+ | ----------- | --------------------- |
156+ | 200 | OK |
157+ | 201 | CREATED |
158+ | 204 | NO_CONTENT |
159+ | 304 | NOT_MODIFIED |
160+ | 400 | BAD_REQUEST |
161+ | 401 | UNAUTHORIZED |
162+ | 403 | FORBIDDEN |
163+ | 404 | NOT_FOUND |
164+ | 409 | CONFLICT |
165+ | 422 | VAILDATION_FAILED |
166+ | 500 | INTERNAL_SERVER_ERROR |
167+ | 502 | BAD_GATEWAY |
168+ | 503 | SERVICE_UNAVAILABLE |
169+ | 504 | GATEWAY_TIMEOUT |
170+ | -1 | UNKNOWN |
171+
172+ ---
173+
174+ [ ** LICENSE: MIT** ] ( ./LICENSE )
175+
176+ > Click [ here] ( https://docs.github.com/en/rest/gists ) for more information on the github gists rest API.
0 commit comments