1
Fork 0
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:
sudosnok 2022-04-10 20:26:49 +01:00
parent 353977c4b2
commit 6450ee6092
3 changed files with 57 additions and 6 deletions

View file

@ -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 = {