Skip to content

Commit 76b86e8

Browse files
committed
Create README.md
1 parent 0e39916 commit 76b86e8

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

README.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Gist API
2+
3+
```sh
4+
npm i @tsukiroku/gist
5+
```
6+
7+
---
8+
9+
# Docs
10+
11+
<br>
12+
13+
## Initialize
14+
15+
> Account token required. See [Docs](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)
16+
17+
```ts
18+
import Gist from "@tsukiroku/gist";
19+
20+
const gist = new Gist("token");
21+
```
22+
23+
<br>
24+
25+
## Create Gist
26+
27+
| Parameter | Type |
28+
| ------------- | ----------- |
29+
| `files` | GistFile |
30+
| `description` | string |
31+
| `options` | GistOptions |
32+
33+
> **GistFile**
34+
>
35+
> ```ts
36+
> { 'file name': { content: 'content' }, ... },
37+
> ```
38+
39+
> **GistOptions**
40+
>
41+
> ```ts
42+
> { secret: boolean, ... }
43+
> ```
44+
>
45+
> **secret** default: true
46+
47+
> **return:** [`Promise<GistResponse>`](./src/types.ts)
48+
49+
```ts
50+
await gist
51+
.create(
52+
{
53+
file_name: { content: "File Content" },
54+
file_name_2: { content: "File Content 2" },
55+
},
56+
"test file"
57+
// { secret: true }
58+
)
59+
.then((res) => {
60+
console.log(`Gist created: ${gist_id}`);
61+
})
62+
.catch((err) => console.log(err));
63+
```
64+
65+
<br>
66+
67+
## Get Gist
68+
69+
| Parameter | Type |
70+
| --------- | ------ |
71+
| `id` | number |
72+
73+
> **return:** [`Promise<GistResponse>`](./src/types.ts)
74+
75+
```ts
76+
await gist
77+
.get("gist id")
78+
.then((res) => console.log(`gist description: ${res.description}`))
79+
.catch((err) => console.log(err));
80+
```
81+
82+
<br>
83+
84+
## Delete Gist
85+
86+
| Parameter | Type |
87+
| --------- | ------ |
88+
| `id` | number |
89+
90+
```ts
91+
await gist
92+
.delete("gist id")
93+
.then((_) => console.log("deleted"))
94+
.catch((err) => console.log(err));
95+
```
96+
97+
<br>
98+
99+
---
100+
101+
<br>
102+
103+
# Example
104+
105+
```ts
106+
import Gist from "./index";
107+
108+
(async () => {
109+
const gist = new Gist("token");
110+
111+
let gist_id: string = "";
112+
113+
await gist
114+
.create(
115+
{
116+
"index.ts": { content: "console.log('Hello, World!');" },
117+
"main.rs": { content: "fn main() {}" },
118+
},
119+
"test gist",
120+
{ secret: true }
121+
)
122+
.then((res) => {
123+
gist_id = res.id;
124+
console.log(`Gist created: ${gist_id}`);
125+
})
126+
.catch((err) => console.log(err));
127+
128+
await gist
129+
.get(gist_id)
130+
.then((res) => console.log(`gist description: ${res.description}`))
131+
.catch((err) => console.log(err));
132+
133+
await gist
134+
.delete(gist_id)
135+
.then((_) => console.log("deleted"))
136+
.catch((err) => console.log(err));
137+
})();
138+
```

0 commit comments

Comments
 (0)