-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upstream reference: c51bfc533f681ae2c21d20b35faff28340a4003e
- Loading branch information
Showing
161 changed files
with
18,217 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Upload Python Package to PyPI when a Release is Created | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
pypi-publish: | ||
name: Publish release to PyPI | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: pypi | ||
url: https://pypi.org/p/derapi | ||
permissions: | ||
id-token: write | ||
contents: read | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: pypa/hatch@install | ||
- run: hatch build | ||
- uses: pypa/gh-action-pypi-publish@release/v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# changelog | ||
|
||
## [0.1.0] - 2024-11-08 | ||
|
||
### Added | ||
|
||
- Initialized the API client code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License | ||
|
||
Copyright (c) 2024-present Derapi (https://derapi.com) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# derapi | ||
|
||
The `derapi` Python SDK provides access to the Derapi API for Python | ||
applications -- fully typed with async support. | ||
|
||
[](https://pypi.org/project/derapi) | ||
[](https://pypi.org/project/derapi) | ||
|
||
----- | ||
|
||
## Table of Contents | ||
|
||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [License](#license) | ||
|
||
## Installation | ||
|
||
```shell | ||
pip install derapi | ||
``` | ||
|
||
## Usage | ||
|
||
Client initialization: | ||
|
||
```python | ||
import os | ||
|
||
import httpx | ||
from derapi import AuthenticatedClient | ||
|
||
def init_client() -> AuthenticatedClient: | ||
token_resp = httpx.post( | ||
"https://auth.derapi.com/oauth2/token", | ||
auth=(os.environ["DERAPI_CLIENT_ID"], os.environ["DERAPI_CLIENT_SECRET"]), | ||
data={"grant_type": "client_credentials"}, | ||
) | ||
token_resp.raise_for_status() | ||
token = token_resp.json()["access_token"] | ||
return AuthenticatedClient( | ||
base_url="https//api.derapi.com", | ||
raise_on_unexpected_status=True, | ||
token=token, | ||
) | ||
``` | ||
|
||
Usage: | ||
|
||
```python | ||
... | ||
|
||
from derapi.api import list_sites | ||
|
||
client = init_client() | ||
|
||
for site in list_sites.sync_depaginated(client=client): | ||
print(site.id) | ||
``` | ||
|
||
## License | ||
|
||
`derapi` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"""A client library for accessing Derapi API Reference""" | ||
|
||
from .client import AuthenticatedClient, Client | ||
|
||
__all__ = ( | ||
"AuthenticatedClient", | ||
"Client", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Contains methods for accessing the API""" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
from http import HTTPStatus | ||
from typing import Any, Dict, Optional, Union | ||
|
||
import httpx | ||
|
||
from ... import errors | ||
from ...client import AuthenticatedClient, Client | ||
from ...models.get_battery_response import GetBatteryResponse | ||
from ...types import Response | ||
|
||
|
||
def _get_kwargs( | ||
id: str, | ||
) -> Dict[str, Any]: | ||
_kwargs: Dict[str, Any] = { | ||
"method": "get", | ||
"url": f"/batteries/{id}", | ||
} | ||
|
||
return _kwargs | ||
|
||
|
||
def _parse_response( | ||
*, client: Union[AuthenticatedClient, Client], response: httpx.Response | ||
) -> Optional[GetBatteryResponse]: | ||
if response.status_code == 200: | ||
response_200 = GetBatteryResponse.from_dict(response.json()) | ||
|
||
return response_200 | ||
if client.raise_on_unexpected_status: | ||
raise errors.UnexpectedStatus(response.status_code, response.content) | ||
else: | ||
return None | ||
|
||
|
||
def _build_response( | ||
*, client: Union[AuthenticatedClient, Client], response: httpx.Response | ||
) -> Response[GetBatteryResponse]: | ||
return Response( | ||
status_code=HTTPStatus(response.status_code), | ||
content=response.content, | ||
headers=response.headers, | ||
parsed=_parse_response(client=client, response=response), | ||
) | ||
|
||
|
||
def sync_detailed( | ||
id: str, | ||
*, | ||
client: Union[AuthenticatedClient, Client], | ||
) -> Response[GetBatteryResponse]: | ||
"""Returns Battery details | ||
Returns details for a single Battery | ||
Args: | ||
id (str): Battery id | ||
Raises: | ||
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
Returns: | ||
Response[GetBatteryResponse] | ||
""" | ||
|
||
kwargs = _get_kwargs( | ||
id=id, | ||
) | ||
|
||
response = client.get_httpx_client().request( | ||
**kwargs, | ||
) | ||
|
||
return _build_response(client=client, response=response) | ||
|
||
|
||
def sync( | ||
id: str, | ||
*, | ||
client: Union[AuthenticatedClient, Client], | ||
) -> Optional[GetBatteryResponse]: | ||
"""Returns Battery details | ||
Returns details for a single Battery | ||
Args: | ||
id (str): Battery id | ||
Raises: | ||
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
Returns: | ||
GetBatteryResponse | ||
""" | ||
|
||
return sync_detailed( | ||
id=id, | ||
client=client, | ||
).parsed | ||
|
||
|
||
async def asyncio_detailed( | ||
id: str, | ||
*, | ||
client: Union[AuthenticatedClient, Client], | ||
) -> Response[GetBatteryResponse]: | ||
"""Returns Battery details | ||
Returns details for a single Battery | ||
Args: | ||
id (str): Battery id | ||
Raises: | ||
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
Returns: | ||
Response[GetBatteryResponse] | ||
""" | ||
|
||
kwargs = _get_kwargs( | ||
id=id, | ||
) | ||
|
||
response = await client.get_async_httpx_client().request(**kwargs) | ||
|
||
return _build_response(client=client, response=response) | ||
|
||
|
||
async def asyncio( | ||
id: str, | ||
*, | ||
client: Union[AuthenticatedClient, Client], | ||
) -> Optional[GetBatteryResponse]: | ||
"""Returns Battery details | ||
Returns details for a single Battery | ||
Args: | ||
id (str): Battery id | ||
Raises: | ||
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
Returns: | ||
GetBatteryResponse | ||
""" | ||
|
||
return ( | ||
await asyncio_detailed( | ||
id=id, | ||
client=client, | ||
) | ||
).parsed |
Oops, something went wrong.