-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgist.py
45 lines (38 loc) · 1.5 KB
/
gist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import requests
class GistApi:
def __init__(self, token):
self.auth = 'token ' + token
def create(self, files, description):
return requests.post("https://api.github.com/gists", json={
'files': files,
'description': description
}, headers={
'Authorization': self.auth,
'Accept': 'application/vnd.github.v3+json'
})
def list(self):
return requests.get("https://api.github.com/gists?per_page=100", headers={
'Authorization': self.auth,
'Accept': 'application/vnd.github.v3+json'
})
def get(self, gist_id):
return requests.get("https://api.github.com/gists/" + gist_id, headers={
'Authorization': self.auth,
'Accept': 'application/vnd.github.v3+json'
})
def upsert_file(self, gist_id, file_name, file_content):
return requests.patch("https://api.github.com/gists/" + gist_id, json={
'files': {
file_name: {
'content': file_content
}
}
}, headers={
'Authorization': self.auth,
'Accept': 'application/vnd.github.v3+json'
})
def fetch_file(self, gist_id, file_id):
return requests.get("https://gist.githubusercontent.com/raw/" + gist_id + "/" + file_id, headers={
'Authorization': self.auth,
'Accept': 'application/vnd.github.v3+json'
})