From ba8c827bc102b91338685d7c58db62e5acf17552 Mon Sep 17 00:00:00 2001 From: RGBCube <78925721+RGBCube@users.noreply.github.com> Date: Tue, 28 Jun 2022 16:05:01 +0300 Subject: [PATCH] Finish all user routes --- github/internals/http.py | 169 +++++++++++++++++++++++++++++++++++++- tools/output.py | 29 +++++-- tools/source.json | 170 +++++++++++++++++++++++++++++++-------- 3 files changed, 327 insertions(+), 41 deletions(-) diff --git a/github/internals/http.py b/github/internals/http.py index afe8d97..dd5aece 100644 --- a/github/internals/http.py +++ b/github/internals/http.py @@ -99,7 +99,7 @@ class RateLimits(NamedTuple): # SCIM # Search # Teams -# Users DONE(1st part) +# Users DONE # Webhooks @@ -282,6 +282,171 @@ class HTTPClient: return await self.request("GET", f"/users/{username}/hovercard", params=params) + async def list_blocked_users_for_authenticated_user(self): + return await self.request("GET", "/user/blocks") + + async def check_user_blocked_for_authenticated_user(self, *, username: str): + return await self.request("GET", f"/user/blocks/{username}") + + async def block_user(self, *, username: str): + return await self.request("PUT", f"/user/blocks/{username}") + + async def unblock_user(self, *, username: str): + return await self.request("DELETE", f"/user/blocks/{username}") + + async def set_primary_email_visibility_for_authenticated_user(self, *, visibility: Literal["public", "private"]): + return await self.request("PATCH", "/user/email/visibility", json={"visibility": visibility}) + + async def list_email_addresses_for_the_authenticated_user(self, *, per_page: Optional[int] = None, page: Optional[int] = None): + params = {} + + if per_page: + params["per_page"] = per_page + if page: + params["page"] = page + + return await self.request("GET", "/user/emails", params=params) + + async def add_email_addresses_for_the_authenticated_user(self, *, emails: List[str]): + return await self.request("POST", "/user/emails", json={"email": emails}) + + async def delete_email_addresses_for_the_authenticated_user(self, *, emails: List[str]): + return await self.request("DELETE", "/user/emails", json={"email": emails}) + + async def list_public_email_addresses_for_the_authenticated_user(self,* , per_page: Optional[int] = None, page: Optional[int] = None): + params = {} + + if per_page: + params["per_page"] = per_page + if page: + params["page"] = page + + return await self.request("GET", "/user/emails/public", params=params) + + async def list_followers_of_the_authenticated_user(self, *, per_page: Optional[int] = None, page: Optional[int] = None): + params = {} + + if per_page: + params["per_page"] = per_page + if page: + params["page"] = page + + return await self.request("GET", "/user/followers", params=params) + + async def list_following_for_the_authenticated_user(self, *, per_page: Optional[int] = None, page: Optional[int] = None): + params = {} + + if per_page: + params["per_page"] = per_page + if page: + params["page"] = page + + return await self.request("GET", "/user/following", params=params) + + async def check_person_followed_by_authenticated_user(self, *, username: str): + return await self.request("GET", f"/user/following/{username}") + + async def follow_user(self, *, username: str): + return await self.request("PUT", f"/user/following/{username}") + + async def unfollow_user(self, *, username: str): + return await self.request("DELETE", f"/user/following/{username}") + + async def list_followers_for_user(self, *, username: str, per_page: Optional[int] = None, page: Optional[int] = None): + params = {} + + if per_page: + params["per_page"] = per_page + if page: + params["page"] = page + + return await self.request("GET", f"/users/{username}/followers", params=params) + + async def list_following_for_user(self, *, username: str, per_page: Optional[int] = None, page: Optional[int] = None): + params = {} + + if per_page: + params["per_page"] = per_page + if page: + params["page"] = page + + return await self.request("GET", f"/users/{username}/following", params=params) + + async def check_user_follows_another_user(self, *, username: str, target_user: str): + return await self.request("GET", f"/users/{username}/following/{target_user}") + + async def list_gpg_keys_for_authenticated_user(self, *, per_page: Optional[int] = None, page: Optional[int] = None): + params = {} + + if per_page: + params["per_page"] = per_page + if page: + params["page"] = page + + return await self.request("GET", "/user/gpg_keys", params=params) + + async def create_gpg_key_for_authenticated_user(self, *, name: Optional[str] = None, armored_public_key: str): + data = { + "armored_public_key": armored_public_key, + } + + if name: + data["name"] = name + + return await self.request("POST", "/user/gpg_keys", json=data) + + async def get_gpg_key_for_authenticated_user(self, *, gpg_key_id: int): + return await self.request("GET", f"/user/gpg_keys/{gpg_key_id}") + + async def delete_gpg_key_for_authenticated_user(self, *, gpg_key_id: int): + return await self.request("DELETE", f"/user/gpg_keys/{gpg_key_id}") + + async def list_gpg_keys_for_user(self, *, username: str, per_page: Optional[int] = None, page: Optional[int] = None): + params = {} + + if per_page: + params["per_page"] = per_page + if page: + params["page"] = page + + return await self.request("GET", f"/users/{username}/gpg_keys", params=params) + + async def list_public_ssh_keys_for_authenticated_user(self, *, per_page: Optional[int] = None, page: Optional[int] = None): + params = {} + + if per_page: + params["per_page"] = per_page + if page: + params["page"] = page + + return await self.request("GET", "/user/keys", params=params) + + async def create_public_ssh_key_for_authenticated_user(self, *, title: Optional[str] = None, key: str): + data = { + "key": key, + } + + if title: + data["title"] = title + + return await self.request("POST", "/user/keys", json=data) + + async def get_public_ssh_key_for_authenticated_user(self, *, key_id: int): + return await self.request("GET", f"/user/keys/{key_id}") + + async def delete_public_ssh_key_for_authenticated_user(self, *, key_id: int): + return await self.request("DELETE", f"/user/keys/{key_id}") + + async def list_public_ssh_keys_for_user(self, *, username: str, per_page: Optional[int] = None, page: Optional[int] = None): + params = {} + + if per_page: + params["per_page"] = per_page + if page: + params["page"] = page + + return await self.request("GET", f"/users/{username}/keys", params=params) + # === REPOS === # async def list_org_repos( @@ -1011,7 +1176,7 @@ class HTTPClient: async def fork_gist(self, *, gist_id: str): return await self.request("POST", f"/gists/{gist_id}/forks") - async def check_gist_is_starred(self, *, gist_id: str): + async def check_gist_starred(self, *, gist_id: str): return await self.request("GET", f"/gists/{gist_id}/star") async def star_gist(self, *, gist_id: str): diff --git a/tools/output.py b/tools/output.py index 38fd4ff..97eccf1 100644 --- a/tools/output.py +++ b/tools/output.py @@ -6,13 +6,28 @@ if TYPE_CHECKING: from typing_extensions import NotRequired -class LicenseSimple(TypedDict): - key: str - name: str - url: Optional[str] - spdx_id: Optional[str] +class SimpleUser(TypedDict): + name: NotRequired[Optional[str]] + email: NotRequired[Optional[str]] + login: str + id: int node_id: str - html_url: NotRequired[str] + avatar_url: str + gravatar_id: Optional[str] + url: str + html_url: str + followers_url: str + following_url: str + gists_url: str + starred_url: str + subscriptions_url: str + organizations_url: str + repos_url: str + events_url: str + received_events_url: str + type: str + site_admin: bool + starred_at: NotRequired[str] -GeneratedObjectResult = List[LicenseSimple] +GeneratedObject = List[SimpleUser] diff --git a/tools/source.json b/tools/source.json index 14a5784..2779a00 100644 --- a/tools/source.json +++ b/tools/source.json @@ -1,58 +1,164 @@ { "type": "array", "items": { - "title": "License Simple", - "description": "License Simple", + "title": "Simple User", + "description": "Simple User", "type": "object", "properties": { - "key": { - "type": "string", - "examples": [ - "mit" - ] - }, "name": { + "type": [ + "string", + "null" + ] + }, + "email": { + "type": [ + "string", + "null" + ] + }, + "login": { "type": "string", "examples": [ - "MIT License" + "octocat" ] }, - "url": { - "type": [ - "string", - "null" - ], - "format": "uri", + "id": { + "type": "integer", "examples": [ - "https://api.github.com/licenses/mit" - ] - }, - "spdx_id": { - "type": [ - "string", - "null" - ], - "examples": [ - "MIT" + 1 ] }, "node_id": { "type": "string", "examples": [ - "MDc6TGljZW5zZW1pdA==" + "MDQ6VXNlcjE=" + ] + }, + "avatar_url": { + "type": "string", + "format": "uri", + "examples": [ + "https://github.com/images/error/octocat_happy.gif" + ] + }, + "gravatar_id": { + "type": [ + "string", + "null" + ], + "examples": [ + "41d064eb2195891e12d0413f63227ea7" + ] + }, + "url": { + "type": "string", + "format": "uri", + "examples": [ + "https://api.github.com/users/octocat" ] }, "html_url": { "type": "string", - "format": "uri" + "format": "uri", + "examples": [ + "https://github.com/octocat" + ] + }, + "followers_url": { + "type": "string", + "format": "uri", + "examples": [ + "https://api.github.com/users/octocat/followers" + ] + }, + "following_url": { + "type": "string", + "examples": [ + "https://api.github.com/users/octocat/following{/other_user}" + ] + }, + "gists_url": { + "type": "string", + "examples": [ + "https://api.github.com/users/octocat/gists{/gist_id}" + ] + }, + "starred_url": { + "type": "string", + "examples": [ + "https://api.github.com/users/octocat/starred{/owner}{/repo}" + ] + }, + "subscriptions_url": { + "type": "string", + "format": "uri", + "examples": [ + "https://api.github.com/users/octocat/subscriptions" + ] + }, + "organizations_url": { + "type": "string", + "format": "uri", + "examples": [ + "https://api.github.com/users/octocat/orgs" + ] + }, + "repos_url": { + "type": "string", + "format": "uri", + "examples": [ + "https://api.github.com/users/octocat/repos" + ] + }, + "events_url": { + "type": "string", + "examples": [ + "https://api.github.com/users/octocat/events{/privacy}" + ] + }, + "received_events_url": { + "type": "string", + "format": "uri", + "examples": [ + "https://api.github.com/users/octocat/received_events" + ] + }, + "type": { + "type": "string", + "examples": [ + "User" + ] + }, + "site_admin": { + "type": "boolean" + }, + "starred_at": { + "type": "string", + "examples": [ + "\"2020-07-09T00:17:55Z\"" + ] } }, "required": [ - "key", - "name", - "url", - "spdx_id", - "node_id" + "avatar_url", + "events_url", + "followers_url", + "following_url", + "gists_url", + "gravatar_id", + "html_url", + "id", + "node_id", + "login", + "organizations_url", + "received_events_url", + "repos_url", + "site_admin", + "starred_url", + "subscriptions_url", + "type", + "url" ] } } \ No newline at end of file