mirror of
https://github.com/RGBCube/GitHubWrapper
synced 2025-05-18 06:55:09 +00:00
change to _session for consistency
This commit is contained in:
parent
63fb8021ce
commit
ef4d46057e
4 changed files with 32 additions and 13 deletions
|
@ -86,11 +86,17 @@ class AlreadyStarted(APIError):
|
||||||
class NotStarted(APIError):
|
class NotStarted(APIError):
|
||||||
"""Raised when a call is made before start is called."""
|
"""Raised when a call is made before start is called."""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
msg = 'You must call `await <Github_instance>.start()` before making this call.'
|
msg = 'You must call `await <Github.GHClient_instance>.start()` before making this call.'
|
||||||
super().__init__(msg)
|
super().__init__(msg)
|
||||||
|
|
||||||
class RepositoryAlreadyExists(APIError):
|
class RepositoryAlreadyExists(APIError):
|
||||||
"""Raised when a repository already exists."""
|
"""Raised when a repository already exists."""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
msg = 'The repository you are trying to create already exists.'
|
msg = 'The repository you are trying to create already exists.'
|
||||||
|
super().__init__(msg)
|
||||||
|
|
||||||
|
class GistNotFound(APIError):
|
||||||
|
"""Raised when a gist is not found."""
|
||||||
|
def __init__(self):
|
||||||
|
msg = 'The gist you are trying to access does not exist.'
|
||||||
super().__init__(msg)
|
super().__init__(msg)
|
|
@ -8,7 +8,7 @@ import re
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from .exceptions import *
|
from .exceptions import *
|
||||||
from .exceptions import RepositoryAlreadyExists
|
from .exceptions import RepositoryAlreadyExists, GistNotFound
|
||||||
from .objects import *
|
from .objects import *
|
||||||
from .urls import *
|
from .urls import *
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ class Paginator:
|
||||||
raise WillExceedRatelimit(response, self.max_page)
|
raise WillExceedRatelimit(response, self.max_page)
|
||||||
self.bare_link = groups[0][0][:-1]
|
self.bare_link = groups[0][0][:-1]
|
||||||
|
|
||||||
GithubUserData = GithubRepoData = GithubIssueData = GithubOrgData = dict[str, str | int]
|
GithubUserData = GithubRepoData = GithubIssueData = GithubOrgData = GithubGistData = dict[str, str | int]
|
||||||
|
|
||||||
class http:
|
class http:
|
||||||
def __init__(self, headers: dict[str, str | int], auth: aiohttp.BasicAuth | None):
|
def __init__(self, headers: dict[str, str | int], auth: aiohttp.BasicAuth | None):
|
||||||
|
@ -176,6 +176,20 @@ class http:
|
||||||
return await result.json()
|
return await result.json()
|
||||||
raise IssueNotFound
|
raise IssueNotFound
|
||||||
|
|
||||||
|
async def get_org(self, org_name: str) -> GithubOrgData:
|
||||||
|
"""Returns an org's public data in JSON format."""
|
||||||
|
result = await self.session.get(ORG_URL.format(org_name))
|
||||||
|
if 200 <= result.status <= 299:
|
||||||
|
return await result.json()
|
||||||
|
raise OrganizationNotFound
|
||||||
|
|
||||||
|
async def get_gist(self, gist_id: int) -> GithubGistData:
|
||||||
|
"""Returns a gist's raw JSON from the given gist id."""
|
||||||
|
result = await self.session.get(GIST_URL.format(gist_id))
|
||||||
|
if 200 <= result.status <= 299:
|
||||||
|
return await result.json()
|
||||||
|
raise GistNotFound
|
||||||
|
|
||||||
async def create_repo(self, **kwargs: dict[str, str | bool]) -> GithubRepoData:
|
async def create_repo(self, **kwargs: dict[str, str | bool]) -> GithubRepoData:
|
||||||
"""Creates a repo for you with given data"""
|
"""Creates a repo for you with given data"""
|
||||||
data = {
|
data = {
|
||||||
|
@ -191,10 +205,3 @@ class http:
|
||||||
if result.status == 401:
|
if result.status == 401:
|
||||||
raise NoAuthProvided
|
raise NoAuthProvided
|
||||||
raise RepositoryAlreadyExists
|
raise RepositoryAlreadyExists
|
||||||
|
|
||||||
async def get_org(self, org_name: str) -> GithubOrgData:
|
|
||||||
"""Returns an org's public data in JSON format."""
|
|
||||||
result = await self.session.get(ORG_URL.format(org_name))
|
|
||||||
if 200 <= result.status <= 299:
|
|
||||||
return await result.json()
|
|
||||||
raise OrganizationNotFound
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ from getpass import getpass
|
||||||
|
|
||||||
from .http import http
|
from .http import http
|
||||||
from . import exceptions
|
from . import exceptions
|
||||||
from .objects import User, PartialUser, Repository, Organization, Issue
|
from .objects import User, PartialUser, Repository, Organization, Issue, Gist
|
||||||
from .cache import UserCache, RepoCache
|
from .cache import UserCache, RepoCache
|
||||||
|
|
||||||
class GHClient:
|
class GHClient:
|
||||||
|
@ -121,10 +121,14 @@ class GHClient:
|
||||||
|
|
||||||
async def create_repo(self, name: str, description: str, private: bool, gitignore_template: str) -> Repository:
|
async def create_repo(self, name: str, description: str, private: bool, gitignore_template: str) -> Repository:
|
||||||
"""Create a new Github repository."""
|
"""Create a new Github repository."""
|
||||||
return Repository(await self.http.make_repo(name, description, private, gitignore_template), self.http.session)
|
return Repository(await self.http.create_repo(name, description, private, gitignore_template), self.http.session)
|
||||||
|
|
||||||
async def get_org(self, org: str) -> Organization:
|
async def get_org(self, org: str) -> Organization:
|
||||||
"""Fetch a Github organization from it's name"""
|
"""Fetch a Github organization from it's name"""
|
||||||
return Organization(await http.get_org(org), self.http.session)
|
return Organization(await self.http.get_org(org), self.http.session)
|
||||||
|
|
||||||
|
async def get_gist(self, gist: int) -> Gist:
|
||||||
|
"""Fetch a Github gist from it's id"""
|
||||||
|
return Gist(await self.http.get_gist(gist), self.http.session)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,8 @@ REPO_URL = BASE_URL + '/repos/{0}/{1}' # a specific repo
|
||||||
|
|
||||||
REPO_ISSUE_URL = REPO_URL + '/issues/{2}' # a specific issue
|
REPO_ISSUE_URL = REPO_URL + '/issues/{2}' # a specific issue
|
||||||
|
|
||||||
|
#== gist urls ==#
|
||||||
|
GIST_URL = BASE_URL + '/gists/{0}' # specific gist
|
||||||
|
|
||||||
#== org urls ==#
|
#== org urls ==#
|
||||||
ORG_URL = BASE_URL + '/orgs/{0}'
|
ORG_URL = BASE_URL + '/orgs/{0}'
|
Loading…
Add table
Add a link
Reference in a new issue