diff --git a/Github/cache.py b/Github/cache.py index 32b379b..3f976a3 100644 --- a/Github/cache.py +++ b/Github/cache.py @@ -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 diff --git a/Github/main.py b/Github/main.py index 48a455d..7dc7f6e 100644 --- a/Github/main.py +++ b/Github/main.py @@ -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 diff --git a/Github/objects/__init__.py b/Github/objects/__init__.py index d771569..fede911 100644 --- a/Github/objects/__init__.py +++ b/Github/objects/__init__.py @@ -2,4 +2,5 @@ from .objects import * from .user import * -from .repo import * \ No newline at end of file +from .repo import * +from .org import * \ No newline at end of file diff --git a/Github/objects/org.py b/Github/objects/org.py index e69de29..8ae33f2 100644 --- a/Github/objects/org.py +++ b/Github/objects/org.py @@ -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'' +