Skip to content

Commit

Permalink
Change: Extend GitHub client API to allow posting binary content
Browse files Browse the repository at this point in the history
Allow to post binary content to GitHub and to set a content type.
  • Loading branch information
bjoernricks committed Oct 25, 2022
1 parent 9299ee3 commit 296c82e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pontos/github/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,13 @@ async def delete(
return await self._client.delete(url, params=params, headers=headers)

async def post(
self, api: str, *, params: Optional[Params] = None, data: Optional[JSON]
self,
api: str,
*,
data: Optional[JSON],
params: Optional[Params] = None,
content: Optional[str] = None,
content_type: Optional[str] = None,
) -> httpx.Response:
"""
Post request to a GitHub API
Expand All @@ -181,10 +187,10 @@ async def post(
params: Optional params to use for the post request
data: Optional data to include in the post request
"""
headers = self._request_headers()
headers = self._request_headers(content_type=content_type)
url = self._request_url(api)
return await self._client.post(
url, params=params, headers=headers, json=data
url, params=params, headers=headers, json=data, content=content
)

def stream(self, api: str) -> AsyncContextManager[httpx.Response]:
Expand Down
2 changes: 2 additions & 0 deletions tests/github/api/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ async def test_post(self):
},
json={"foo": "bar"},
params=None,
content=None,
)

async def test_post_url(self):
Expand All @@ -147,6 +148,7 @@ async def test_post_url(self):
},
json={"foo": "bar"},
params=None,
content=None,
)

def test_stream(self):
Expand Down

0 comments on commit 296c82e

Please sign in to comment.