Skip to content

Commit b7eebf6

Browse files
jfrench9claude
andauthored
Add ledger entity API endpoints and supporting models (#71)
## Summary Introduces ledger entity support to the robosystems client library by adding new API endpoints for retrieving and updating ledger entities, along with their corresponding request/response models. Also includes a minor update to the existing `MaterializeRequest` class. ## Key Accomplishments ### New API Endpoints - **`get_ledger_entity`** – New endpoint for fetching ledger entity data from the API, with full support for both sync and async HTTP clients - **`update_ledger_entity`** – New endpoint for updating ledger entities, also supporting both sync and async execution patterns ### New Models - **`LedgerEntityResponse`** – Comprehensive response model (623 lines) for deserializing ledger entity data returned by the API - **`UpdateEntityRequest`** – Request model (498 lines) for constructing and validating ledger entity update payloads ### Updated Models - **`MaterializeRequest`** – Updated with additional field(s) to support new ledger entity functionality - **`models/__init__.py`** – Updated exports to include the newly added models ## Breaking Changes - The `MaterializeRequest` model has been modified with field changes. Consumers relying on the previous structure of this class should verify compatibility, though the change appears to be additive in nature (net +23 lines). ## Testing Notes - Verify `get_ledger_entity` returns properly deserialized `LedgerEntityResponse` objects for valid entity lookups - Verify `update_ledger_entity` correctly serializes `UpdateEntityRequest` payloads and handles success/error responses - Test both sync and async client paths for the new endpoints - Confirm the `MaterializeRequest` changes do not regress existing materialization workflows - Validate edge cases around optional/nullable fields in the new models ## Infrastructure Considerations - No new dependencies are introduced; the new code follows existing patterns in the client library - The new endpoints will require corresponding API availability on the server side — ensure the ledger entity API is deployed before rolling out client updates that depend on these features - The substantial size of the new models (~1,100 lines combined) suggests complex entity structures; documentation of the ledger entity schema may be beneficial for consumers --- 🤖 Generated with [Claude Code](https://claude.ai/code) **Branch Info:** - Source: `feature/ledger-entity` - Target: `main` - Type: feature Co-Authored-By: Claude <noreply@anthropic.com>
2 parents 7d20b36 + c940c62 commit b7eebf6

6 files changed

Lines changed: 1510 additions & 1 deletion

File tree

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
from http import HTTPStatus
2+
from typing import Any
3+
from urllib.parse import quote
4+
5+
import httpx
6+
7+
from ... import errors
8+
from ...client import AuthenticatedClient, Client
9+
from ...models.http_validation_error import HTTPValidationError
10+
from ...models.ledger_entity_response import LedgerEntityResponse
11+
from ...types import Response
12+
13+
14+
def _get_kwargs(
15+
graph_id: str,
16+
) -> dict[str, Any]:
17+
_kwargs: dict[str, Any] = {
18+
"method": "get",
19+
"url": "/v1/ledger/{graph_id}/entity".format(
20+
graph_id=quote(str(graph_id), safe=""),
21+
),
22+
}
23+
24+
return _kwargs
25+
26+
27+
def _parse_response(
28+
*, client: AuthenticatedClient | Client, response: httpx.Response
29+
) -> HTTPValidationError | LedgerEntityResponse | None:
30+
if response.status_code == 200:
31+
response_200 = LedgerEntityResponse.from_dict(response.json())
32+
33+
return response_200
34+
35+
if response.status_code == 422:
36+
response_422 = HTTPValidationError.from_dict(response.json())
37+
38+
return response_422
39+
40+
if client.raise_on_unexpected_status:
41+
raise errors.UnexpectedStatus(response.status_code, response.content)
42+
else:
43+
return None
44+
45+
46+
def _build_response(
47+
*, client: AuthenticatedClient | Client, response: httpx.Response
48+
) -> Response[HTTPValidationError | LedgerEntityResponse]:
49+
return Response(
50+
status_code=HTTPStatus(response.status_code),
51+
content=response.content,
52+
headers=response.headers,
53+
parsed=_parse_response(client=client, response=response),
54+
)
55+
56+
57+
def sync_detailed(
58+
graph_id: str,
59+
*,
60+
client: AuthenticatedClient,
61+
) -> Response[HTTPValidationError | LedgerEntityResponse]:
62+
"""Get Entity
63+
64+
Get the entity for this ledger graph.
65+
66+
Args:
67+
graph_id (str):
68+
69+
Raises:
70+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
71+
httpx.TimeoutException: If the request takes longer than Client.timeout.
72+
73+
Returns:
74+
Response[HTTPValidationError | LedgerEntityResponse]
75+
"""
76+
77+
kwargs = _get_kwargs(
78+
graph_id=graph_id,
79+
)
80+
81+
response = client.get_httpx_client().request(
82+
**kwargs,
83+
)
84+
85+
return _build_response(client=client, response=response)
86+
87+
88+
def sync(
89+
graph_id: str,
90+
*,
91+
client: AuthenticatedClient,
92+
) -> HTTPValidationError | LedgerEntityResponse | None:
93+
"""Get Entity
94+
95+
Get the entity for this ledger graph.
96+
97+
Args:
98+
graph_id (str):
99+
100+
Raises:
101+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
102+
httpx.TimeoutException: If the request takes longer than Client.timeout.
103+
104+
Returns:
105+
HTTPValidationError | LedgerEntityResponse
106+
"""
107+
108+
return sync_detailed(
109+
graph_id=graph_id,
110+
client=client,
111+
).parsed
112+
113+
114+
async def asyncio_detailed(
115+
graph_id: str,
116+
*,
117+
client: AuthenticatedClient,
118+
) -> Response[HTTPValidationError | LedgerEntityResponse]:
119+
"""Get Entity
120+
121+
Get the entity for this ledger graph.
122+
123+
Args:
124+
graph_id (str):
125+
126+
Raises:
127+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
128+
httpx.TimeoutException: If the request takes longer than Client.timeout.
129+
130+
Returns:
131+
Response[HTTPValidationError | LedgerEntityResponse]
132+
"""
133+
134+
kwargs = _get_kwargs(
135+
graph_id=graph_id,
136+
)
137+
138+
response = await client.get_async_httpx_client().request(**kwargs)
139+
140+
return _build_response(client=client, response=response)
141+
142+
143+
async def asyncio(
144+
graph_id: str,
145+
*,
146+
client: AuthenticatedClient,
147+
) -> HTTPValidationError | LedgerEntityResponse | None:
148+
"""Get Entity
149+
150+
Get the entity for this ledger graph.
151+
152+
Args:
153+
graph_id (str):
154+
155+
Raises:
156+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
157+
httpx.TimeoutException: If the request takes longer than Client.timeout.
158+
159+
Returns:
160+
HTTPValidationError | LedgerEntityResponse
161+
"""
162+
163+
return (
164+
await asyncio_detailed(
165+
graph_id=graph_id,
166+
client=client,
167+
)
168+
).parsed
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
from http import HTTPStatus
2+
from typing import Any
3+
from urllib.parse import quote
4+
5+
import httpx
6+
7+
from ... import errors
8+
from ...client import AuthenticatedClient, Client
9+
from ...models.http_validation_error import HTTPValidationError
10+
from ...models.ledger_entity_response import LedgerEntityResponse
11+
from ...models.update_entity_request import UpdateEntityRequest
12+
from ...types import Response
13+
14+
15+
def _get_kwargs(
16+
graph_id: str,
17+
*,
18+
body: UpdateEntityRequest,
19+
) -> dict[str, Any]:
20+
headers: dict[str, Any] = {}
21+
22+
_kwargs: dict[str, Any] = {
23+
"method": "put",
24+
"url": "/v1/ledger/{graph_id}/entity".format(
25+
graph_id=quote(str(graph_id), safe=""),
26+
),
27+
}
28+
29+
_kwargs["json"] = body.to_dict()
30+
31+
headers["Content-Type"] = "application/json"
32+
33+
_kwargs["headers"] = headers
34+
return _kwargs
35+
36+
37+
def _parse_response(
38+
*, client: AuthenticatedClient | Client, response: httpx.Response
39+
) -> HTTPValidationError | LedgerEntityResponse | None:
40+
if response.status_code == 200:
41+
response_200 = LedgerEntityResponse.from_dict(response.json())
42+
43+
return response_200
44+
45+
if response.status_code == 422:
46+
response_422 = HTTPValidationError.from_dict(response.json())
47+
48+
return response_422
49+
50+
if client.raise_on_unexpected_status:
51+
raise errors.UnexpectedStatus(response.status_code, response.content)
52+
else:
53+
return None
54+
55+
56+
def _build_response(
57+
*, client: AuthenticatedClient | Client, response: httpx.Response
58+
) -> Response[HTTPValidationError | LedgerEntityResponse]:
59+
return Response(
60+
status_code=HTTPStatus(response.status_code),
61+
content=response.content,
62+
headers=response.headers,
63+
parsed=_parse_response(client=client, response=response),
64+
)
65+
66+
67+
def sync_detailed(
68+
graph_id: str,
69+
*,
70+
client: AuthenticatedClient,
71+
body: UpdateEntityRequest,
72+
) -> Response[HTTPValidationError | LedgerEntityResponse]:
73+
"""Update Entity
74+
75+
Update entity details. Only provided (non-null) fields are updated.
76+
77+
Args:
78+
graph_id (str):
79+
body (UpdateEntityRequest): Request to update entity details. Only provided fields are
80+
updated.
81+
82+
Raises:
83+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
84+
httpx.TimeoutException: If the request takes longer than Client.timeout.
85+
86+
Returns:
87+
Response[HTTPValidationError | LedgerEntityResponse]
88+
"""
89+
90+
kwargs = _get_kwargs(
91+
graph_id=graph_id,
92+
body=body,
93+
)
94+
95+
response = client.get_httpx_client().request(
96+
**kwargs,
97+
)
98+
99+
return _build_response(client=client, response=response)
100+
101+
102+
def sync(
103+
graph_id: str,
104+
*,
105+
client: AuthenticatedClient,
106+
body: UpdateEntityRequest,
107+
) -> HTTPValidationError | LedgerEntityResponse | None:
108+
"""Update Entity
109+
110+
Update entity details. Only provided (non-null) fields are updated.
111+
112+
Args:
113+
graph_id (str):
114+
body (UpdateEntityRequest): Request to update entity details. Only provided fields are
115+
updated.
116+
117+
Raises:
118+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
119+
httpx.TimeoutException: If the request takes longer than Client.timeout.
120+
121+
Returns:
122+
HTTPValidationError | LedgerEntityResponse
123+
"""
124+
125+
return sync_detailed(
126+
graph_id=graph_id,
127+
client=client,
128+
body=body,
129+
).parsed
130+
131+
132+
async def asyncio_detailed(
133+
graph_id: str,
134+
*,
135+
client: AuthenticatedClient,
136+
body: UpdateEntityRequest,
137+
) -> Response[HTTPValidationError | LedgerEntityResponse]:
138+
"""Update Entity
139+
140+
Update entity details. Only provided (non-null) fields are updated.
141+
142+
Args:
143+
graph_id (str):
144+
body (UpdateEntityRequest): Request to update entity details. Only provided fields are
145+
updated.
146+
147+
Raises:
148+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
149+
httpx.TimeoutException: If the request takes longer than Client.timeout.
150+
151+
Returns:
152+
Response[HTTPValidationError | LedgerEntityResponse]
153+
"""
154+
155+
kwargs = _get_kwargs(
156+
graph_id=graph_id,
157+
body=body,
158+
)
159+
160+
response = await client.get_async_httpx_client().request(**kwargs)
161+
162+
return _build_response(client=client, response=response)
163+
164+
165+
async def asyncio(
166+
graph_id: str,
167+
*,
168+
client: AuthenticatedClient,
169+
body: UpdateEntityRequest,
170+
) -> HTTPValidationError | LedgerEntityResponse | None:
171+
"""Update Entity
172+
173+
Update entity details. Only provided (non-null) fields are updated.
174+
175+
Args:
176+
graph_id (str):
177+
body (UpdateEntityRequest): Request to update entity details. Only provided fields are
178+
updated.
179+
180+
Raises:
181+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
182+
httpx.TimeoutException: If the request takes longer than Client.timeout.
183+
184+
Returns:
185+
HTTPValidationError | LedgerEntityResponse
186+
"""
187+
188+
return (
189+
await asyncio_detailed(
190+
graph_id=graph_id,
191+
client=client,
192+
body=body,
193+
)
194+
).parsed

‎robosystems_client/models/__init__.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
from .invoice import Invoice
164164
from .invoice_line_item import InvoiceLineItem
165165
from .invoices_response import InvoicesResponse
166+
from .ledger_entity_response import LedgerEntityResponse
166167
from .ledger_entry_response import LedgerEntryResponse
167168
from .ledger_line_item_response import LedgerLineItemResponse
168169
from .ledger_summary_response import LedgerSummaryResponse
@@ -290,6 +291,7 @@
290291
from .trial_balance_row import TrialBalanceRow
291292
from .upcoming_invoice import UpcomingInvoice
292293
from .update_api_key_request import UpdateAPIKeyRequest
294+
from .update_entity_request import UpdateEntityRequest
293295
from .update_file_response_updatefile import UpdateFileResponseUpdatefile
294296
from .update_member_role_request import UpdateMemberRoleRequest
295297
from .update_org_request import UpdateOrgRequest
@@ -441,6 +443,7 @@
441443
"Invoice",
442444
"InvoiceLineItem",
443445
"InvoicesResponse",
446+
"LedgerEntityResponse",
444447
"LedgerEntryResponse",
445448
"LedgerLineItemResponse",
446449
"LedgerSummaryResponse",
@@ -552,6 +555,7 @@
552555
"TrialBalanceRow",
553556
"UpcomingInvoice",
554557
"UpdateAPIKeyRequest",
558+
"UpdateEntityRequest",
555559
"UpdateFileResponseUpdatefile",
556560
"UpdateMemberRoleRequest",
557561
"UpdateOrgRequest",

0 commit comments

Comments
 (0)