1
Fork 0
mirror of https://github.com/RGBCube/GitHubWrapper synced 2025-05-28 03:35:09 +00:00

Adding orgs

This commit is contained in:
VarMonke 2022-03-28 22:42:10 +05:30
parent b95f3b314a
commit f46eada1bb
4 changed files with 65 additions and 5 deletions

View file

@ -7,7 +7,7 @@ __all__ = (
)
from collections import deque
from .objects import APIOBJECT, User, Repository
from .objects import APIOBJECT, User, Repository, Organization
class _BaseCache(dict):
@ -72,4 +72,18 @@ class RepoCache(_BaseCache):
self[key] = value
class OrgCache(_BaseCache):
pass
def __getitem__(self, __k: str) -> Organization:
target = self._lru_keys.pop(self._lru_keys.index(__k))
self._lru_keys.appendleft(target)
return super().__getitem__(__k)
def __setitem__(self, __k: str, __v: Organization) -> None:
if len(self) == self._max_size:
to_pop = self._lru_keys.pop(-1)
del self[to_pop]
self._lru_keys.appendleft(__k)
return super().__setitem__(__k, __v)
def update(self, *args, **kwargs) -> None:
for key, value in dict(*args, **kwargs).iteritems():
self[key] = value

View file

@ -10,7 +10,7 @@ import asyncio
from . import http
from . import exceptions
from .objects import User, Repository
from .objects import User, Repository, Organization
class GHClient:
_auth = None
@ -83,7 +83,7 @@ class GHClient:
"""Fetch aGithub repository from it's name."""
return Repository(await http.get_repo_from_name(self.session, owner, repo_name), self.session)
async def get_org(self, org_name: str) -> 'Org':
async def get_org(self, org_name: str) -> Organization:
"""Fetch a Github organization from it's name"""
pass

View file

@ -3,3 +3,4 @@
from .objects import *
from .user import *
from .repo import *
from .org import *

View file

@ -0,0 +1,45 @@
#== org.py ==#
import aiohttp
from .objects import APIOBJECT, dt_formatter
from . import PartialUser
from .. import http
__all__ = (
'Organization',
)
class Organization(APIOBJECT):
__slots__ = (
'login',
'id',
'html_url',
'is_verified',
'public_repos',
'public_gists',
'followers',
'following',
'created_at',
#will add
)
def __init__(self, response: dict, session: aiohttp.ClientSession) -> None:
super().__init__(response, session)
tmp = self.__slots__ + APIOBJECT.__slots__
keys = {key: value for key,value in self._response.items() if key in tmp}
for key, value in keys.items():
if key == 'login':
setattr(self, key, value)
continue
if '_at' in key and value is not None:
setattr(self, key, dt_formatter(value))
continue
else:
setattr(self, key, value)
continue
def __repr__(self):
return f'<Organization; login: {self.login}, id: {self.id}, html_url: {self.html_url}, is_verified: {self.is_verified}, public_repos: {self.public_repos}, public_gists: {self.public_gists}, created_at: {self.created_at}>'