From eb5bf143f92b70cb620fc0d384ecb2d63c8cd534 Mon Sep 17 00:00:00 2001 From: WitherredAway Date: Mon, 11 Apr 2022 22:26:49 +0000 Subject: [PATCH] Client.get_gist() no longer requires a valid access token --- gists/client.py | 16 +++++++++++++--- gists/gist.py | 3 +++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/gists/client.py b/gists/client.py index 0f2645b..dfea7d6 100644 --- a/gists/client.py +++ b/gists/client.py @@ -22,15 +22,23 @@ def __init__(self, access_token: str): self.user_agent = f"Gists.py (https://github.com/witherredaway/gists.py) Python/{sys.version_info[0]}.{sys.version_info[1]} aiohttp/{aiohttp.__version__}" async def request( - self, method: str, url: str, *, params=None, data=None, headers=None + self, + method: str, + url: str, + *, + params=None, + data=None, + headers=None, + authorization: bool = True, ) -> typing.Dict: """The method to make asynchronous requests to the GitHub API""" hdrs = { "Accept": "application/vnd.github.v3+json", "User-Agent": self.user_agent, - "Authorization": "token %s" % self.access_token, } + if authorization: + hdrs["Authorization"] = "token %s" % self.access_token request_url = yarl.URL(API_URL) / url @@ -81,7 +89,9 @@ async def fetch_user(self) -> typing.Dict: async def fetch_data(self, gist_id: str) -> typing.Dict: """Fetch data of a Gist""" - gist_data: typing.Dict = await self.request("GET", "gists/%s" % gist_id) + gist_data: typing.Dict = await self.request( + "GET", "gists/%s" % gist_id, authorization=False + ) return gist_data async def get_gist(self, gist_id: str) -> Gist: diff --git a/gists/gist.py b/gists/gist.py index 79eecfa..6d6d14b 100644 --- a/gists/gist.py +++ b/gists/gist.py @@ -1,6 +1,9 @@ import typing +__all__ = ("Gist",) + + class Gist: def __init__(self, data: typing.Dict, client: "Client"): self.data = data