mirror of
https://github.com/RGBCube/GitHubWrapper
synced 2025-05-18 06:55:09 +00:00
Adding fetching orgs
This commit is contained in:
parent
6c8e5cec0e
commit
45db6d5120
4 changed files with 23 additions and 5 deletions
|
@ -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
|
||||
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
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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'<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}>'
|
||||
|
||||
@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)
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
#== org urls ==#
|
||||
ORG_URL = BASE_URL + '/orgs/{0}'
|
Loading…
Add table
Add a link
Reference in a new issue