mirror of
https://github.com/RGBCube/GitHubWrapper
synced 2025-05-31 04:58:12 +00:00
Added create_gist and related File objects
This commit is contained in:
parent
353977c4b2
commit
6450ee6092
3 changed files with 57 additions and 6 deletions
|
@ -1,11 +1,17 @@
|
|||
#== http.py ==#
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
import json
|
||||
import re
|
||||
from collections import namedtuple
|
||||
from datetime import datetime
|
||||
from types import SimpleNamespace
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .main import File
|
||||
|
||||
import aiohttp
|
||||
|
||||
|
@ -213,6 +219,29 @@ class http:
|
|||
return await result.json()
|
||||
raise GistNotFound
|
||||
|
||||
async def create_gist(
|
||||
self,
|
||||
*,
|
||||
files: list['File'] = [],
|
||||
description: str = 'Default description',
|
||||
public: bool = False
|
||||
) -> GithubGistData:
|
||||
data = {}
|
||||
data['description'] = description
|
||||
data['public'] = public
|
||||
data['files'] = {}
|
||||
for file in files:
|
||||
data['files'][file.filename] = {
|
||||
'content': file.read()
|
||||
}
|
||||
data = json.dumps(data)
|
||||
_headers = self.session.headers
|
||||
result = self.session.post(CREATE_GIST_URL, data=data, headers=_headers|{'Accept': 'application/vnd.github.v3+json'})
|
||||
if 201 == result.status:
|
||||
return await result.json()
|
||||
raise InvalidToken
|
||||
|
||||
|
||||
async def create_repo(self, **kwargs: dict[str, str | bool]) -> GithubRepoData:
|
||||
"""Creates a repo for you with given data"""
|
||||
data = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue