diff --git a/Github/http.py b/Github/http.py index eba65bf..2c65860 100644 --- a/Github/http.py +++ b/Github/http.py @@ -128,4 +128,13 @@ async def get_repo_from_name(session: aiohttp.ClientSession, owner: str, repo_na result = await session.get(REPO_URL.format(owner, repo_name)) if result.status == 200: return await result.json() - raise RepositoryNotFound \ No newline at end of file + raise RepositoryNotFound + +# org-related functions / utils + +async def get_org(session: aiohttp.ClientSession, org_name: str): + """Returns an org's public data in JSON format.""" + result = await session.get(ORG_URL.format(org_name)) + if result.status == 200: + return await result.json() + raise OrganizationNotFound \ No newline at end of file diff --git a/Github/main.py b/Github/main.py index 7dc7f6e..cc95d51 100644 --- a/Github/main.py +++ b/Github/main.py @@ -85,5 +85,5 @@ class GHClient: async def get_org(self, org_name: str) -> Organization: """Fetch a Github organization from it's name""" - pass + return Organization(await http.get_org(self.session, org_name), self.session) diff --git a/Github/objects/org.py b/Github/objects/org.py index 8ae33f2..1a51f8f 100644 --- a/Github/objects/org.py +++ b/Github/objects/org.py @@ -21,7 +21,7 @@ class Organization(APIOBJECT): 'followers', 'following', 'created_at', - #will add + 'avatar_url', ) def __init__(self, response: dict, session: aiohttp.ClientSession) -> None: @@ -43,3 +43,10 @@ class Organization(APIOBJECT): def __repr__(self): return f'' + @classmethod + async def from_name(cls, session: aiohttp.ClientSession, org: str) -> 'Organization': + """Fetch a repository from its name.""" + response = await http.get_repo_from_name(session, org) + return Organization(response, session) + + diff --git a/Github/urls.py b/Github/urls.py index e66d083..a52d03e 100644 --- a/Github/urls.py +++ b/Github/urls.py @@ -24,6 +24,8 @@ USER_FOLLOWING_URL = USERS_URL + '/following' #== repo urls ==# REPOS_URL = BASE_URL + '/repos/{0}' # repos of a user -#REPO_URL = REPOS_URL + '/{1}' # a specific repo +REPO_URL = BASE_URL + '/repos/{0}/{1}' # a specific repo -REPO_URL = BASE_URL + '/repos/{0}/{1}' # a specific repo \ No newline at end of file + +#== org urls ==# +ORG_URL = BASE_URL + '/orgs/{0}' \ No newline at end of file