Skip to content

Commit

Permalink
Improve doc strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Hallett committed Oct 4, 2023
1 parent 0a4a885 commit 0d88715
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* To regenerate a client (and to prevent accidental overrides) you must now pass `--regen t` or `-r t` to the `generate` command. This is automatically added to the line in `MANIFEST.md` to help.
* Clientele will now automatically run [black](https://black.readthedocs.io/en/stable/) code formatter once a client is generated or regenerated.
* Clientele will now generate absolute paths to refer to adjacent files in the generated client, instead of relative paths. This assumes you are running the `clientele` command in the root directory of your project.
* A lot of documentation and docs strings updates so that code in the generated client is easier to understand.

## 0.6.3

Expand Down
10 changes: 7 additions & 3 deletions clientele/templates/async_methods.jinja2
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@


async def get(url: str, headers: typing.Optional[dict] = None) -> httpx.Response:
""" Issue an HTTP GET request """
return await client.get(parse_url(url), headers=headers)

async def post(url: str, data: dict, headers: typing.Optional[dict] = None) -> httpx.Response:
""" Issue an HTTP POST request """
return await client.post(parse_url(url), json=data, headers=headers)

async def delete(url: str, headers: typing.Optional[dict] = None) -> httpx.Response:
return await client.delete(parse_url(url), headers=headers)

async def put(url: str, data: dict, headers: typing.Optional[dict] = None) -> httpx.Response:
""" Issue an HTTP PUT request """
return await client.put(parse_url(url), json=data, headers=headers)

async def delete(url: str, headers: typing.Optional[dict] = None) -> httpx.Response:
""" Issue an HTTP DELETE request """
return await client.delete(parse_url(url), headers=headers)
8 changes: 5 additions & 3 deletions clientele/templates/http_py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class APIException(Exception):
def parse_url(url: str) -> str:
"""
Returns the full URL from a string.
Will omit any optional query parameters passed.

Will filter out any optional query parameters if they are None.
"""
api_url = f"{c.api_base_url()}{url}"
url_parts = urlparse(url=api_url)
Expand All @@ -46,8 +47,9 @@ def parse_url(url: str) -> str:

def handle_response(func, response):
"""
Returns a response that matches the data neatly for a function
If it can't - raises an error with details of the response.
Returns a schema object that matches the JSON data from the response.

If it can't find a matching schema it will raise an error with details of the response.
"""
status_code = response.status_code
# Get the response types
Expand Down
4 changes: 4 additions & 0 deletions clientele/templates/sync_methods.jinja2
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@


def get(url: str, headers: typing.Optional[dict] = None) -> httpx.Response:
""" Issue an HTTP GET request """
return client.get(parse_url(url), headers=headers)

def post(url: str, data: dict, headers: typing.Optional[dict] = None) -> httpx.Response:
""" Issue an HTTP POST request """
return client.post(parse_url(url), json=data, headers=headers)

def put(url: str, data: dict, headers: typing.Optional[dict] = None) -> httpx.Response:
""" Issue an HTTP PUT request """
return client.put(parse_url(url), json=data, headers=headers)

def delete(url: str, headers: typing.Optional[dict] = None) -> httpx.Response:
""" Issue an HTTP DELETE request """
return client.delete(parse_url(url), headers=headers)
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* To regenerate a client (and to prevent accidental overrides) you must now pass `--regen t` or `-r t` to the `generate` command. This is automatically added to the line in `MANIFEST.md` to help.
* Clientele will now automatically run [black](https://black.readthedocs.io/en/stable/) code formatter once a client is generated or regenerated.
* Clientele will now generate absolute paths to refer to adjacent files in the generated client, instead of relative paths. This assumes you are running the `clientele` command in the root directory of your project.
* A lot of documentation and docs strings updates so that code in the generated client is easier to understand.

## 0.6.3

Expand Down
20 changes: 13 additions & 7 deletions tests/async_test_client/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def __init__(self, response: httpx.Response, reason: str, *args: object) -> None
def parse_url(url: str) -> str:
"""
Returns the full URL from a string.
Will omit any optional query parameters passed.
Will filter out any optional query parameters if they are None.
"""
api_url = f"{c.api_base_url()}{url}"
url_parts = urlparse(url=api_url)
Expand All @@ -45,8 +46,9 @@ def parse_url(url: str) -> str:

def handle_response(func, response):
"""
Returns a response that matches the data neatly for a function
If it can't - raises an error with details of the response.
Returns a schema object that matches the JSON data from the response.
If it can't find a matching schema it will raise an error with details of the response.
"""
status_code = response.status_code
# Get the response types
Expand Down Expand Up @@ -122,20 +124,24 @@ def handle_response(func, response):


async def get(url: str, headers: typing.Optional[dict] = None) -> httpx.Response:
"""Issue an HTTP GET request"""
return await client.get(parse_url(url), headers=headers)


async def post(
url: str, data: dict, headers: typing.Optional[dict] = None
) -> httpx.Response:
"""Issue an HTTP POST request"""
return await client.post(parse_url(url), json=data, headers=headers)


async def delete(url: str, headers: typing.Optional[dict] = None) -> httpx.Response:
return await client.delete(parse_url(url), headers=headers)


async def put(
url: str, data: dict, headers: typing.Optional[dict] = None
) -> httpx.Response:
"""Issue an HTTP PUT request"""
return await client.put(parse_url(url), json=data, headers=headers)


async def delete(url: str, headers: typing.Optional[dict] = None) -> httpx.Response:
"""Issue an HTTP DELETE request"""
return await client.delete(parse_url(url), headers=headers)
12 changes: 9 additions & 3 deletions tests/test_client/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def __init__(self, response: httpx.Response, reason: str, *args: object) -> None
def parse_url(url: str) -> str:
"""
Returns the full URL from a string.
Will omit any optional query parameters passed.
Will filter out any optional query parameters if they are None.
"""
api_url = f"{c.api_base_url()}{url}"
url_parts = urlparse(url=api_url)
Expand All @@ -45,8 +46,9 @@ def parse_url(url: str) -> str:

def handle_response(func, response):
"""
Returns a response that matches the data neatly for a function
If it can't - raises an error with details of the response.
Returns a schema object that matches the JSON data from the response.
If it can't find a matching schema it will raise an error with details of the response.
"""
status_code = response.status_code
# Get the response types
Expand Down Expand Up @@ -122,16 +124,20 @@ def handle_response(func, response):


def get(url: str, headers: typing.Optional[dict] = None) -> httpx.Response:
"""Issue an HTTP GET request"""
return client.get(parse_url(url), headers=headers)


def post(url: str, data: dict, headers: typing.Optional[dict] = None) -> httpx.Response:
"""Issue an HTTP POST request"""
return client.post(parse_url(url), json=data, headers=headers)


def put(url: str, data: dict, headers: typing.Optional[dict] = None) -> httpx.Response:
"""Issue an HTTP PUT request"""
return client.put(parse_url(url), json=data, headers=headers)


def delete(url: str, headers: typing.Optional[dict] = None) -> httpx.Response:
"""Issue an HTTP DELETE request"""
return client.delete(parse_url(url), headers=headers)

0 comments on commit 0d88715

Please sign in to comment.