Repository navigation
Conversation
473c5dc to
87a82bc
Compare
|
does this replace #348 ? |
@dmitry-mukhin Oops, actually I missed this and don't know that Denis has been already working on this. Otherwise, my implementation closer to what we want and more match to OAuth specification scopes (https://github.com/uploadcare/auth-server/pull/1) |
|
|
||
|
|
||
| class UploadsFeature(Entity): | ||
| # In bytes, a multiple of a megabyte. `None` means the plan's maximum. |
There was a problem hiding this comment.
not clear should I pass 1 or 1000^2 to set one MB.
If it's 1000^2 and we only accept multiples, why not make it easier and accept MBs, not Bs.
There was a problem hiding this comment.
Values in the model are now explicitly defined in megabytes; they are converted to bytes before being sent to the API, and converted back to megabytes in the response. Users works with megabytes.
Using 10^6 instead of 1e-6 because of backend logic
| # In bytes, a multiple of a megabyte. `None` means the plan's maximum. | ||
| filesize_limit: Optional[int] = Field(default=None, ge=0) | ||
| autostore: Optional[bool] = None | ||
| # In pixels, a multiple of 10^6. `None` means the default value. |
There was a problem hiding this comment.
Values in the model are now explicitly defined in megapixels; they are converted to pixels before being sent to the API, and converted back to megapixels in the response. Users works with megapixels.
| def _utc_date(name: str, value: datetime) -> date: | ||
| # The server counts days in UTC. | ||
| try: | ||
| aware = ensure_aware_datetime(value) | ||
| except ValueError: | ||
| raise InvalidParamError( | ||
| f"`{name}` must be a timezone-aware datetime, got {value!r}" | ||
| ) from None | ||
| return aware.astimezone(timezone.utc).date() | ||
|
|
||
|
|
||
| def _to_date(name: str, value: DateLike) -> date: | ||
| # `datetime` is a subclass of `date`, so check it first. | ||
| if isinstance(value, datetime): | ||
| return _utc_date(name, value) | ||
| if isinstance(value, date): | ||
| return value | ||
| try: | ||
| return date.fromisoformat(value) | ||
| except (TypeError, ValueError): | ||
| raise InvalidParamError( | ||
| f"`{name}` must be a date or an ISO 8601 date string " | ||
| f"(YYYY-MM-DD), got {value!r}" | ||
| ) |
There was a problem hiding this comment.
it looks like it's accidental that this lives under project_api, not more broad helpers. we already have some date helpers there.
There was a problem hiding this comment.
Reworked with using common helpers. Now accept datetime aware only (neither plain date type or string)
| They are an exception to the 7.0 rule that rejects plain `date` objects, which covers inputs | ||
| that mean a point in time. A `datetime` there must be timezone-aware, as everywhere else, and | ||
| is converted to its UTC date. |
There was a problem hiding this comment.
Agree, this is useless information, removed this block
| Project API | ||
| ----------- |
There was a problem hiding this comment.
it looks like time to move it to a separate project_api doc.
There was a problem hiding this comment.
Good point, moved it to dedicated page
Account-level APIs such as the Project API have no project key, which would otherwise show up as `PyUploadcare/<version>/None`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ProjectAPIClient lists, counts, gets, creates, updates and deletes the projects of an account. It is authorized with the OAuth access token from UPLOADCARE_OAUTH_TOKEN by default; the public key goes in the URL. Updates are partial: models send only explicitly set, writable fields, since the server rejects any non-empty feature object the owner's plan does not include. Request data and public keys are validated before a request is made. Tests run the real HTTP client stack against a mocked transport. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`get_usage()` returns daily traffic, storage and operations, and `get_usage_metric()` one of them. The dates take a day: a `date` or a YYYY-MM-DD string. A datetime must be timezone-aware and becomes its UTC date, since the server counts days in UTC. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`get_moderation_thresholds()` and `set_moderation_thresholds()`, which replaces all thresholds of a project. Thresholds are validated locally: 0 to 100 with up to two decimal places, unique per category and file type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`list_mime_types()` gives the values `mime_type_filtering` accepts, and `list_moderation_categories()` the category ids moderation thresholds take. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the Project API to HISTORY under 7.1.0 and bump the version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cea05eb to
d191bc8
Compare
|



Scope
pass.
Out of scope
/projects/{pub_key}/secrets/)./oauth/authorize/).ucareCLI commands and Django integration for the Project API.Checklist