Skip to content

Commit

Permalink
Client.get_gist() no longer requires a valid access token
Browse files Browse the repository at this point in the history
  • Loading branch information
WitherredAway committed Apr 11, 2022
1 parent c08f3e2 commit eb5bf14
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
16 changes: 13 additions & 3 deletions gists/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions gists/gist.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import typing


__all__ = ("Gist",)


class Gist:
def __init__(self, data: typing.Dict, client: "Client"):
self.data = data
Expand Down

0 comments on commit eb5bf14

Please sign in to comment.