Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: forward kwargs to request method #50

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 45 additions & 25 deletions src/simple_github/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,27 @@ def close(self) -> BaseNone: ...
def request(self, method: str, query: str, **kwargs: Any) -> BaseResponse: ...

@abstractmethod
def get(self, query: str) -> BaseResponse: ...
def get(self, query: str, **kwargs: Any) -> BaseResponse: ...

@abstractmethod
def post(self, query: str, data: RequestData = None) -> BaseResponse: ...
def post(
self, query: str, data: RequestData = None, **kwargs: Any
) -> BaseResponse: ...

@abstractmethod
def put(self, query: str, data: RequestData = None) -> BaseResponse: ...
def put(
self, query: str, data: RequestData = None, **kwargs: Any
) -> BaseResponse: ...

@abstractmethod
def patch(self, query: str, data: RequestData = None) -> BaseResponse: ...
def patch(
self, query: str, data: RequestData = None, **kwargs: Any
) -> BaseResponse: ...

@abstractmethod
def delete(self, query: str, data: RequestData = None) -> BaseNone: ...
def delete(
self, query: str, data: RequestData = None, **kwargs: Any
) -> BaseNone: ...

@abstractmethod
def execute(self, query: str, variables: RequestData = None) -> BaseDict: ...
Expand Down Expand Up @@ -140,7 +148,7 @@ def request(self, method: str, query: str, **kwargs) -> RequestsResponse:
with session.request(method, url, **kwargs) as resp:
return resp

def get(self, query: str) -> RequestsResponse:
def get(self, query: str, **kwargs: Any) -> RequestsResponse:
"""Make a GET request to Github's REST API.

Args:
Expand All @@ -149,9 +157,11 @@ def get(self, query: str) -> RequestsResponse:
Returns:
Dict: The JSON result of the request.
"""
return self.request("GET", query)
return self.request("GET", query, **kwargs)

def post(self, query: str, data: RequestData = None) -> RequestsResponse:
def post(
self, query: str, data: RequestData = None, **kwargs: Any
) -> RequestsResponse:
"""Make a POST request to Github's REST API.

Args:
Expand All @@ -161,9 +171,11 @@ def post(self, query: str, data: RequestData = None) -> RequestsResponse:
Returns:
Dict: The JSON result of the request.
"""
return self.request("POST", query, data=json.dumps(data))
return self.request("POST", query, data=json.dumps(data), **kwargs)

def put(self, query: str, data: RequestData = None) -> RequestsResponse:
def put(
self, query: str, data: RequestData = None, **kwargs: Any
) -> RequestsResponse:
"""Make a PUT request to Github's REST API.

Args:
Expand All @@ -173,9 +185,11 @@ def put(self, query: str, data: RequestData = None) -> RequestsResponse:
Returns:
Dict: The JSON result of the request.
"""
return self.request("PUT", query, data=json.dumps(data))
return self.request("PUT", query, data=json.dumps(data), **kwargs)

def patch(self, query: str, data: RequestData = None) -> RequestsResponse:
def patch(
self, query: str, data: RequestData = None, **kwargs: Any
) -> RequestsResponse:
"""Make a PATCH request to Github's REST API.

Args:
Expand All @@ -185,16 +199,16 @@ def patch(self, query: str, data: RequestData = None) -> RequestsResponse:
Returns:
Dict: The JSON result of the request.
"""
return self.request("PATCH", query, data=json.dumps(data))
return self.request("PATCH", query, data=json.dumps(data), **kwargs)

def delete(self, query: str, data: RequestData = None) -> None:
def delete(self, query: str, data: RequestData = None, **kwargs: Any) -> None:
"""Make a DELETE request to Github's REST API.

Args:
query (str): The path segment of the request, e.g `/octocat`.
data (Dict): The data to send in the request (optional).
"""
self.request("DELETE", query, data=json.dumps(data))
self.request("DELETE", query, data=json.dumps(data), **kwargs)

def execute(self, query: str, variables: RequestData = None) -> Dict[str, Any]:
"""Execute a query against Github's GraphQL endpoint.
Expand Down Expand Up @@ -278,7 +292,7 @@ async def request(self, method: str, query: str, **kwargs: Any) -> ClientRespons
session = await self._get_aiohttp_session()
return await session.request(method, url, **kwargs)

async def get(self, query: str) -> ClientResponse:
async def get(self, query: str, **kwargs: Any) -> ClientResponse:
"""Make a GET request to Github's REST API.

Args:
Expand All @@ -287,9 +301,11 @@ async def get(self, query: str) -> ClientResponse:
Returns:
Dict: The JSON result of the request.
"""
return await self.request("GET", query)
return await self.request("GET", query, **kwargs)

async def post(self, query: str, data: RequestData = None) -> ClientResponse:
async def post(
self, query: str, data: RequestData = None, **kwargs: Any
) -> ClientResponse:
"""Make a POST request to Github's REST API.

Args:
Expand All @@ -299,9 +315,11 @@ async def post(self, query: str, data: RequestData = None) -> ClientResponse:
Returns:
Dict: The JSON result of the request.
"""
return await self.request("POST", query, data=json.dumps(data))
return await self.request("POST", query, data=json.dumps(data), **kwargs)

async def put(self, query: str, data: RequestData = None) -> ClientResponse:
async def put(
self, query: str, data: RequestData = None, **kwargs: Any
) -> ClientResponse:
"""Make a PUT request to Github's REST API.

Args:
Expand All @@ -311,9 +329,11 @@ async def put(self, query: str, data: RequestData = None) -> ClientResponse:
Returns:
Dict: The JSON result of the request.
"""
return await self.request("PUT", query, data=json.dumps(data))
return await self.request("PUT", query, data=json.dumps(data), **kwargs)

async def patch(self, query: str, data: RequestData = None) -> ClientResponse:
async def patch(
self, query: str, data: RequestData = None, **kwargs: Any
) -> ClientResponse:
"""Make a PATCH request to Github's REST API.

Args:
Expand All @@ -323,16 +343,16 @@ async def patch(self, query: str, data: RequestData = None) -> ClientResponse:
Returns:
Dict: The JSON result of the request.
"""
return await self.request("PATCH", query, data=json.dumps(data))
return await self.request("PATCH", query, data=json.dumps(data), **kwargs)

async def delete(self, query: str, data: RequestData = None) -> None:
async def delete(self, query: str, data: RequestData = None, **kwargs: Any) -> None:
"""Make a DELETE request to Github's REST API.

Args:
query (str): The path segment of the request, e.g `/octocat`.
data (Dict): The data to send in the request (optional).
"""
await self.request("DELETE", query, data=json.dumps(data))
await self.request("DELETE", query, data=json.dumps(data), **kwargs)

async def execute(
self, query: str, variables: RequestData = None
Expand Down
Loading