harbor run -t openthoughts/tasktrove-exp-flat25-pseudocode-v2-5k-pseudocode-4860harbor download openthoughts/tasktrove-exp-flat25-pseudocode-v2-5k-pseudocode-4860PSEUDOCODE
CLASS UpdateableAPIResource CLASS_ATTRIBUTE OBJECT_NAME: String
CLASS_METHOD construct_from(data: Map<String, Any>, api_key: String) -> UpdateableAPIResource instance ← new UpdateableAPIResource instance._data ← deep_copy(data) instance._original ← deep_copy(data) instance._api_key ← api_key instance._octane_version ← None instance.last_response ← None RETURN instance
CLASS_METHOD retrieve(id: String, api_key: String, octane_version: Optional = None) -> UpdateableAPIResource path ← "/v1/" + OBJECT_NAME + "s/" + id headers ← { "Authorization": "Bearer " + api_key } IF octane_version IS NOT None THEN headers["Octane-Version"] ← octane_version ENDIF response ← HTTP_GET(path, headers) payload ← response.json() inst ← UpdateableAPIResource.construct_from(payload, api_key) inst._id ← id inst._octane_version ← octane_version inst.last_response ← response RETURN inst
CONSTRUCTOR INITIALIZE _data AS empty_map INITIALIZE _original AS empty_map INITIALIZE _api_key AS empty_string INITIALIZE _octane_version AS None INITIALIZE _id AS None last_response ← None
METHOD save(idempotency_key: Optional = None) -> UpdateableAPIResource changes ← _compute_changes(_original, _data) IF changes IS empty THEN RETURN self ENDIF
path ← "/v1/" + OBJECT_NAME + "s/" + _id
headers ← { "Authorization": "Bearer " + _api_key }
IF idempotency_key IS NOT None THEN
headers["Idempotency-Key"] ← idempotency_key
ENDIF
IF _octane_version IS NOT None THEN
headers["Octane-Version"] ← _octane_version
ENDIF
response ← HTTP_POST(path, payload: changes, headers)
payload_resp ← response.json()
// Update in-memory state from server response
_data ← deep_copy(payload_resp)
_original ← deep_copy(payload_resp)
// Remove keys not present in server response
previous_keys ← keys_of_previous_state_before_update
response_keys ← keys_of(payload_resp)
FOR key IN previous_keys DO
IF key NOT IN response_keys THEN
DELETE _data[key]
ENDIF
ENDFOR
last_response ← response
RETURN self
METHOD _compute_changes(original: Map<String, Any>, current: Map<String, Any>) -> Map<String, Any> // Returns payload containing only changed data, following rules: // - Scalars: include if different from original // - Dicts: // - If current[key] is a scalar: include current[key] directly // - If current[key] is a dict: // - Recurse into nested keys // - If a nested key disappears in current, emit "" for that nested key (to indicate clearing) // - If the entire nested object is replaced with an empty dict, emit all known nested keys with "" values // - Lists inside dicts (nested structures): // - Represent as map indexed by string indices when server expects map form // - For each index, emit changed fields; unchanged indices may be {} or omitted as required by tests // - If current contains a field not present in original, include it (and its subtree) // Implementation SHOULD produce exactly the payload shapes asserted by tests
RETURN result_of_recursive_diff(original, current)
METHOD getattr(name: String) -> Any // Access data fields as attributes IF name IN _data THEN RETURN _data[name] ELSE RAISE AttributeError(name) ENDIF
METHOD setattr(name: String, value: Any) // Allow setting top-level or nested fields into internal _data structure IF name IN {"_data", "_original", "_api_key", "_octane_version", "_id", "last_response", "OBJECT_NAME"} THEN SET attribute normally ELSE _data[name] ← value ENDIF
PROPERTY last_response: HTTPResponse
// Internal helpers (not externally visible) FUNCTION deep_copy(obj: Any) -> Any // Deep copy utility
FUNCTION keys_of(map_or_obj: Any) -> Set // Return the set of keys if map; if scalar, return empty set
FUNCTION HTTP_GET(path: String, headers: Map<String, String>) -> HTTPResponse // Use project’s request mechanism to perform GET
FUNCTION HTTP_POST(path: String, payload: Map<String, Any>, headers: Map<String, String>) -> HTTPResponse // Use project’s request mechanism to perform POST
END CLASS
Notes