Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
use private properties
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 committed Nov 7, 2024
1 parent 522467b commit 084fdde
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
16 changes: 8 additions & 8 deletions cads_api_client/catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def collection_ids(self) -> list[str]:
------
list[str]
"""
return [collection["id"] for collection in self.json_dict["collections"]]
return [collection["id"] for collection in self._json_dict["collections"]]


@attrs.define
Expand All @@ -54,7 +54,7 @@ def begin_datetime(self) -> datetime.datetime | None:
-------
datetime.datetime or None
"""
if (value := self.json_dict["extent"]["temporal"]["interval"][0][0]) is None:
if (value := self._json_dict["extent"]["temporal"]["interval"][0][0]) is None:
return value
return datetime.datetime.fromisoformat(value.replace("Z", "+00:00"))

Expand All @@ -66,7 +66,7 @@ def end_datetime(self) -> datetime.datetime | None:
-------
datetime.datetime or None
"""
if (value := self.json_dict["extent"]["temporal"]["interval"][0][1]) is None:
if (value := self._json_dict["extent"]["temporal"]["interval"][0][1]) is None:
return value
return datetime.datetime.fromisoformat(value.replace("Z", "+00:00"))

Expand All @@ -78,7 +78,7 @@ def bbox(self) -> tuple[float, float, float, float]:
-------
tuple[float,float,float,float]
"""
return tuple(self.json_dict["extent"]["spatial"]["bbox"][0])
return tuple(self._json_dict["extent"]["spatial"]["bbox"][0])

@property
def id(self) -> str:
Expand All @@ -88,7 +88,7 @@ def id(self) -> str:
-------
str
"""
return str(self.json_dict["id"])
return str(self._json_dict["id"])

@property
def process(self) -> cads_api_client.Process:
Expand All @@ -114,7 +114,7 @@ def form(self) -> list[dict[str, Any]]:
url = f"{self.url}/form.json"
return ApiResponse.from_request(
"get", url, log_messages=False, **self._request_kwargs
).json_list
)._json_list

@property
def constraints(self) -> list[dict[str, Any]]:
Expand All @@ -128,7 +128,7 @@ def constraints(self) -> list[dict[str, Any]]:
url = f"{self.url}/constraints.json"
return ApiResponse.from_request(
"get", url, log_messages=False, **self._request_kwargs
).json_list
)._json_list

def submit(self, **request: Any) -> cads_api_client.Remote:
warnings.warn(
Expand Down Expand Up @@ -184,7 +184,7 @@ def get_licenses(self, **params: Any) -> dict[str, Any]:
response = ApiResponse.from_request(
"get", url, params=params, **self._request_kwargs
)
return response.json_dict
return response._json_dict

@property
def messages(self) -> ApiResponse:
Expand Down
2 changes: 1 addition & 1 deletion cads_api_client/legacy_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def workflow(self, code, *args, **kwargs):

def status(self, context: Any = None) -> dict[str, list[str]]:
status = collections.defaultdict(list)
messages = self.client._catalogue_api.messages.json_dict.get("messages", [])
messages = self.client._catalogue_api.messages._json_dict.get("messages", [])
for message in messages:
status[message["severity"]].append(message["content"])
return dict(status)
Expand Down
30 changes: 15 additions & 15 deletions cads_api_client/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,23 +212,23 @@ def json(self) -> Any:
return self.response.json()

@property
def json_dict(self) -> dict[str, Any]:
def _json_dict(self) -> dict[str, Any]:
assert isinstance(content := self.json, dict)
return content

@property
def json_list(self) -> list[dict[str, Any]]:
def _json_list(self) -> list[dict[str, Any]]:
assert isinstance(content := self.json, list)
return content

def log_messages(self) -> None:
if message_str := self.json_dict.get("message"):
if message_str := self._json_dict.get("message"):
level, message_str = get_level_and_message(message_str)
self.log(level, message_str)

messages = self.json_dict.get("messages", [])
messages = self._json_dict.get("messages", [])
dataset_messages = (
self.json_dict.get("metadata", {})
self._json_dict.get("metadata", {})
.get("datasetMetadata", {})
.get("messages", [])
)
Expand All @@ -243,7 +243,7 @@ def log_messages(self) -> None:

def _get_links(self, rel: str | None = None) -> list[dict[str, str]]:
links = []
for link in self.json_dict.get("links", []):
for link in self._json_dict.get("links", []):
if rel is not None and link.get("rel") == rel:
links.append(link)
return links
Expand Down Expand Up @@ -316,7 +316,7 @@ def process_ids(self) -> list[str]:
-------
list[str]
"""
return [proc["id"] for proc in self.json_dict["processes"]]
return [proc["id"] for proc in self._json_dict["processes"]]


@attrs.define
Expand All @@ -331,7 +331,7 @@ def id(self) -> str:
-------
str
"""
process_id: str = self.json_dict["id"]
process_id: str = self._json_dict["id"]
return process_id

def submit(self, **request: Any) -> cads_api_client.Remote:
Expand Down Expand Up @@ -373,7 +373,7 @@ def apply_constraints(self, **request: Any) -> dict[str, Any]:
json={"inputs": request},
**self._request_kwargs,
)
return response.json_dict
return response._json_dict

def estimate_costs(self, **request: Any) -> dict[str, Any]:
"""Estimate costs of the parameters in a request.
Expand All @@ -394,7 +394,7 @@ def estimate_costs(self, **request: Any) -> dict[str, Any]:
json={"inputs": request},
**self._request_kwargs,
)
return response.json_dict
return response._json_dict


@attrs.define(slots=False)
Expand Down Expand Up @@ -461,7 +461,7 @@ def json(self) -> dict[str, Any]:
params = {"log": True, "request": True}
if self.log_start_time:
params["logStartTime"] = self.log_start_time
return self._get_api_response("get", params=params).json_dict
return self._get_api_response("get", params=params)._json_dict

@property
def collection_id(self) -> str:
Expand Down Expand Up @@ -554,7 +554,7 @@ def results_ready(self) -> bool:
return False
if status == "failed":
results = self.make_results(wait=False)
raise ProcessingFailedError(error_json_to_message(results.json_dict))
raise ProcessingFailedError(error_json_to_message(results._json_dict))
if status in ("dismissed", "deleted"):
raise ProcessingFailedError(f"API state {status!r}")
raise ProcessingFailedError(f"Unknown API state {status!r}")
Expand Down Expand Up @@ -596,7 +596,7 @@ def delete(self) -> dict[str, Any]:
"""
response = self._get_api_response("delete")
self.cleanup = False
return response.json_dict
return response._json_dict

def _warn(self) -> None:
message = (
Expand Down Expand Up @@ -681,7 +681,7 @@ def request_uids(self) -> list[str]:
-------
list[str]
"""
return [job["jobID"] for job in self.json_dict["jobs"]]
return [job["jobID"] for job in self._json_dict["jobs"]]

@property
def job_ids(self) -> list[str]:
Expand Down Expand Up @@ -711,7 +711,7 @@ def asset(self) -> dict[str, Any]:
-------
dict[str,Any]
"""
return dict(self.json_dict["asset"]["value"])
return dict(self._json_dict["asset"]["value"])

def _download(self, url: str, target: str) -> requests.Response:
download_options = {"stream": True, "resume_transfers": True}
Expand Down
8 changes: 5 additions & 3 deletions cads_api_client/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ def _get_api_response(

def accept_licence(self, licence_id: str, revision: int) -> dict[str, Any]:
url = f"{self.url}/account/licences/{licence_id}"
return self._get_api_response("put", url, json={"revision": revision}).json_dict
return self._get_api_response(
"put", url, json={"revision": revision}
)._json_dict

def accepted_licences(self, **params: Any) -> dict[str, Any]:
url = f"{self.url}/account/licences"
return self._get_api_response("get", url, params=params).json_dict
return self._get_api_response("get", url, params=params)._json_dict

def check_authentication(self) -> dict[str, Any]:
url = f"{self.url}/account/verification/pat"
return self._get_api_response("post", url).json_dict
return self._get_api_response("post", url)._json_dict

0 comments on commit 084fdde

Please sign in to comment.