simple-github-gist-api 2.0.0 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -18
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
<p>
|
|
4
4
|
<img alt="npm" src="https://img.shields.io/npm/dt/simple-github-gist-api">
|
|
5
|
+
<a href="https://www.npmjs.com/package/simple-github-gist-api">
|
|
6
|
+
<img alt="npm" src="https://img.shields.io/npm/v/simple-github-gist-api">
|
|
7
|
+
</a>
|
|
5
8
|
</p>
|
|
6
9
|
|
|
7
10
|
> This documentation is for v2 of the lib. v2 has a few breaking changes.
|
|
@@ -20,35 +23,39 @@ need to make those tedious HTTP requests.
|
|
|
20
23
|
> And you have an endpoint `/create-file`.
|
|
21
24
|
>
|
|
22
25
|
> Think multiple people making request at the same time:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
```
|
|
27
|
+
/create-file?name=1.json
|
|
28
|
+
/create-file?name=2.json
|
|
29
|
+
/create-file?name=3.json
|
|
30
|
+
...
|
|
31
|
+
```
|
|
32
|
+
|
|
28
33
|
> If this happens at the same time, then we cannot guarantee that the
|
|
29
34
|
> all the files will be saved. Maybe when creating both 2.json and 3.json,
|
|
30
35
|
> we are making use of the same commit-id. Both will work but 1 will over-write
|
|
31
36
|
> the other commit.
|
|
32
37
|
>
|
|
33
38
|
> But if you do:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
const file1 = gist.createFile('1.json', "{}")
|
|
42
|
+
const file2 = gist.createFile('2.json', "{}")
|
|
43
|
+
const file3 = gist.createFile('3.json', "{}")
|
|
44
|
+
|
|
45
|
+
await file1.save();
|
|
46
|
+
await file2.save();
|
|
47
|
+
await file3.save();
|
|
48
|
+
```
|
|
42
49
|
>
|
|
43
50
|
> this will work as the latest commit-id will be fetched when
|
|
44
51
|
> saving the next file.
|
|
45
52
|
>
|
|
46
|
-
>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
> Or
|
|
54
|
+
```ts
|
|
55
|
+
gist.save();
|
|
56
|
+
```
|
|
50
57
|
> this will work as well because all the changes will go in a single commit.
|
|
51
|
-
|
|
58
|
+
|
|
52
59
|
|
|
53
60
|
## Installation
|
|
54
61
|
|
|
@@ -166,3 +173,49 @@ await projectsFile.save();
|
|
|
166
173
|
await gist.save();
|
|
167
174
|
```
|
|
168
175
|
> Only files that have un-saved changes will be saved.
|
|
176
|
+
|
|
177
|
+
### Sample
|
|
178
|
+
```ts
|
|
179
|
+
import GithubGist from "./src";
|
|
180
|
+
|
|
181
|
+
const personalAccessToken = "";
|
|
182
|
+
|
|
183
|
+
const githubGist = new GithubGist({
|
|
184
|
+
appIdentifier: 'MyTestApp',
|
|
185
|
+
personalAccessToken,
|
|
186
|
+
cors: {
|
|
187
|
+
addPrefix: true,
|
|
188
|
+
customPrefix: (someURl) => `YourCustomPrefix` + someURl,
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
(async () => {
|
|
193
|
+
await githubGist.touch();
|
|
194
|
+
|
|
195
|
+
console.log("Gist ID", githubGist.id);
|
|
196
|
+
console.log("Github Username", githubGist.ownerUsername);
|
|
197
|
+
|
|
198
|
+
console.log("Original File names", githubGist.getFileNames());
|
|
199
|
+
|
|
200
|
+
const created = githubGist.createFile("projects.json", "{}");
|
|
201
|
+
if (created) {
|
|
202
|
+
console.log('Created new file in gist');
|
|
203
|
+
} else {
|
|
204
|
+
console.log('Updated existing file in gist');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Note: All the creates and updates happen in-memory. You have to
|
|
208
|
+
// explicitly invoke the `save` method on either the entire gist instance
|
|
209
|
+
// or the individual file instance.
|
|
210
|
+
|
|
211
|
+
// Saves all the files in the gist. Only the un-saved changes will be
|
|
212
|
+
// added to the payload.
|
|
213
|
+
await githubGist.save();
|
|
214
|
+
|
|
215
|
+
// Save individual file.
|
|
216
|
+
// const file = githubGist.getFile('projects.json');
|
|
217
|
+
// await file.save();
|
|
218
|
+
|
|
219
|
+
console.log("File names", githubGist.getFileNames());
|
|
220
|
+
})();
|
|
221
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simple-github-gist-api",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "A way to store data on Github Gist.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
],
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
|
-
"url": "git+ssh://git@github.com:
|
|
17
|
+
"url": "git+ssh://git@github.com:vighnesh153/simple-github-gist-api.git"
|
|
18
18
|
},
|
|
19
19
|
"keywords": [
|
|
20
20
|
"gist",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"author": "Vighnesh Raut",
|
|
28
28
|
"license": "GPL-3.0-or-later",
|
|
29
29
|
"bugs": {
|
|
30
|
-
"url": "https://github.com/
|
|
30
|
+
"url": "https://github.com/vighnesh153/simple-github-gist-api/issues"
|
|
31
31
|
},
|
|
32
|
-
"homepage": "https://github.com/
|
|
32
|
+
"homepage": "https://github.com/vighnesh153/simple-github-gist-api#readme",
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/jest": "^27.0.2",
|
|
35
35
|
"jest": "^27.3.0",
|