Skip to content

Expand APIResponse to capture additional HTTP response metadata#11

Merged
stevevanhooser merged 3 commits into
claude/add-python-porting-guide-emxajfrom
claude/align-python-api-response-fUucA
Mar 11, 2026
Merged

Expand APIResponse to capture additional HTTP response metadata#11
stevevanhooser merged 3 commits into
claude/add-python-porting-guide-emxajfrom
claude/align-python-api-response-fUucA

Conversation

@stevevanhooser
Copy link
Copy Markdown
Contributor

Summary

Enhanced the APIResponse class to capture and expose additional HTTP response metadata, providing callers with more detailed information about API responses.

Key Changes

  • Extended APIResponse attributes: Added four new fields to __slots__:

    • headers: Response headers as a dict-like object
    • reason: HTTP reason phrase (e.g., "OK", "Not Found")
    • elapsed: Time elapsed between request and response (as datetime.timedelta)
    • http_response: Reference to the raw requests.Response object
  • Updated __init__ method: Added corresponding parameters with sensible defaults:

    • headers defaults to empty dict if not provided
    • reason defaults to empty string
    • elapsed and http_response default to None
  • Enhanced __repr__ method: Improved string representation to conditionally include:

    • HTTP reason phrase when available
    • Elapsed time when available
    • Maintains backward compatibility with existing format
  • Updated _request method: Modified to populate new fields when constructing APIResponse from actual HTTP responses:

    • Passes resp.headers, resp.reason, resp.elapsed, and the response object itself
    • Uses getattr() with defaults for optional attributes

Implementation Details

  • The changes maintain backward compatibility; all new parameters are optional with sensible defaults
  • Locally-constructed APIResponse instances (e.g., for paginated aggregations) can omit the new fields
  • The __repr__ method gracefully handles missing optional fields to avoid cluttering output

https://claude.ai/code/session_01Y9G6ysXeXzrXRsZGe2Pe3G

claude added 3 commits March 11, 2026 11:26
Aligns Python's APIResponse with the richer structure returned by MATLAB's
ndi.cloud.api apiResponse output argument. All new fields use safe defaults
so existing call-sites (including manually-constructed APIResponse instances
in pagination helpers) are fully backward-compatible.

https://claude.ai/code/session_01Y9G6ysXeXzrXRsZGe2Pe3G
…source of truth

Renames (with backward-compatible aliases):
- download.downloadFullDataset → download.dataset
- filehandler.rewrite_file_info_for_cloud → filehandler.updateFileInfoForRemoteFiles
- sync._delete_local_docs → sync.deleteLocalDocuments (now public)
- sync._download_docs_by_ids → sync.downloadNdiDocuments (now public)

New functions ported from MATLAB:
- download.datasetDocuments — per-document download with mode handling
- download.downloadGenericFiles — download generic_file docs with extensions
- download.setFileInfo — set file_info for local/hybrid modes
- download.structsToNdiDocuments — alias for jsons2documents
- upload.uploadToNDICloud — legacy upload entry point
- upload.scanForUpload — moved from orchestration to match MATLAB location
- filehandler.updateFileInfoForLocalFiles — update file_info for local files
- internal.duplicateDocuments — find/remove duplicate cloud documents

Test cleanup:
- Add module-scoped autouse fixture to sweep up any leftover NDI_PYTEST_*
  datasets after all tests complete, preventing stale dataset accumulation.

https://claude.ai/code/session_01Y9G6ysXeXzrXRsZGe2Pe3G
The safety-net fixture now prints a warnings.warn with the names and
IDs of every leftover dataset it deletes, making silent teardown
failures visible in CI logs.

https://claude.ai/code/session_01Y9G6ysXeXzrXRsZGe2Pe3G
@stevevanhooser stevevanhooser merged commit 11f5c44 into claude/add-python-porting-guide-emxaj Mar 11, 2026
@stevevanhooser stevevanhooser deleted the claude/align-python-api-response-fUucA branch March 11, 2026 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants