Skip to content

Commit

Permalink
Merge pull request #63 from CLIMB-TRE/development
Browse files Browse the repository at this point in the history
`--scope` parameter removed, updated `projects` and `fields` outputs with new actions information, `--summarise` CLI argument change
  • Loading branch information
tombch authored Feb 15, 2024
2 parents f25e682 + 38c1b0e commit 667a9fe
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 372 deletions.
72 changes: 22 additions & 50 deletions onyx/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,10 @@ def projects(self) -> requests.Response:
)
return response

def fields(
self,
project: str,
scope: Union[List[str], str, None] = None,
) -> requests.Response:
def fields(self, project: str) -> requests.Response:
response = self._request(
method="get",
url=OnyxClient.ENDPOINTS["fields"](self.config.domain, project),
params={"scope": scope},
)
return response

Expand All @@ -414,12 +409,11 @@ def get(
climb_id: str,
include: Union[List[str], str, None] = None,
exclude: Union[List[str], str, None] = None,
scope: Union[List[str], str, None] = None,
) -> requests.Response:
response = self._request(
method="get",
url=OnyxClient.ENDPOINTS["get"](self.config.domain, project, climb_id),
params={"include": include, "exclude": exclude, "scope": scope},
params={"include": include, "exclude": exclude},
)
return response

Expand All @@ -429,7 +423,6 @@ def filter(
fields: Optional[Dict[str, Any]] = None,
include: Union[List[str], str, None] = None,
exclude: Union[List[str], str, None] = None,
scope: Union[List[str], str, None] = None,
summarise: Union[List[str], str, None] = None,
) -> Generator[requests.Response, Any, None]:
if fields is None:
Expand All @@ -438,7 +431,6 @@ def filter(
fields = fields | {
"include": include,
"exclude": exclude,
"scope": scope,
"summarise": summarise,
}
_next = OnyxClient.ENDPOINTS["filter"](self.config.domain, project)
Expand All @@ -463,7 +455,6 @@ def query(
query: Optional[OnyxField] = None,
include: Union[List[str], str, None] = None,
exclude: Union[List[str], str, None] = None,
scope: Union[List[str], str, None] = None,
summarise: Union[List[str], str, None] = None,
) -> Generator[requests.Response, Any, None]:
if query:
Expand All @@ -479,7 +470,6 @@ def query(
fields = {
"include": include,
"exclude": exclude,
"scope": scope,
"summarise": summarise,
}
_next = OnyxClient.ENDPOINTS["query"](self.config.domain, project)
Expand Down Expand Up @@ -870,14 +860,25 @@ def projects(self) -> List[Dict[str, str]]:
>>> projects
[
{
"project": "project",
"action": "add",
"scope": "base",
"project": "project_1",
"scope": "admin",
"actions": [
"get",
"list",
"filter",
"add",
"change",
"delete",
],
},
{
"project": "project",
"action": "view",
"scope": "base",
"project": "project_2",
"scope": "analyst",
"actions": [
"get",
"list",
"filter",
],
},
]
```
Expand All @@ -888,17 +889,12 @@ def projects(self) -> List[Dict[str, str]]:
return response.json()["data"]

@onyx_errors
def fields(
self,
project: str,
scope: Union[List[str], str, None] = None,
) -> Dict[str, Any]:
def fields(self, project: str) -> Dict[str, Any]:
"""
View fields for a project.
Args:
project: Name of the project.
scope: Additional named group(s) of fields to include in the output.
Returns:
Dict of fields.
Expand Down Expand Up @@ -947,7 +943,7 @@ def fields(
```
"""

response = super().fields(project, scope=scope)
response = super().fields(project)
response.raise_for_status()
return response.json()["data"]

Expand Down Expand Up @@ -994,7 +990,6 @@ def get(
fields: Optional[Dict[str, Any]] = None,
include: Union[List[str], str, None] = None,
exclude: Union[List[str], str, None] = None,
scope: Union[List[str], str, None] = None,
) -> Dict[str, Any]:
"""
Get a record from a project.
Expand All @@ -1005,7 +1000,6 @@ def get(
fields: Series of conditions on fields, used to filter the data.
include: Fields to include in the output.
exclude: Fields to exclude from the output.
scope: Additional named group(s) of fields to include in the output.
Returns:
Dict containing the record.
Expand Down Expand Up @@ -1063,7 +1057,7 @@ def get(
}
```
The `include`, `exclude`, and `scope` arguments can be used to control the fields returned:
The `include` and `exclude` arguments can be used to control the fields returned:
```python
import os
from onyx import OnyxConfig, OnyxEnv, OnyxClient
Expand All @@ -1084,11 +1078,6 @@ def get(
climb_id="C-1234567890",
exclude=["field2"],
)
record_v3 = client.get(
"project",
climb_id="C-1234567890",
scope="extra_fields",
)
```
```python
>>> record_v1
Expand All @@ -1102,15 +1091,6 @@ def get(
"published_date": "2023-01-01",
"field1": "value1",
}
>>> record_v3
{
"climb_id": "C-1234567890",
"published_date": "2023-01-01",
"field1": "value1",
"field2": "value2",
"extra_field1": "extra_value1",
"extra_field2": "extra_value2",
}
```
Tips:
Expand All @@ -1129,7 +1109,6 @@ def get(
climb_id,
include=include,
exclude=exclude,
scope=scope,
)
response.raise_for_status()
return response.json()["data"]
Expand All @@ -1139,7 +1118,6 @@ def get(
fields=fields,
include=include,
exclude=exclude,
scope=scope,
)
response = next(responses, None)
if response is None:
Expand All @@ -1163,7 +1141,6 @@ def filter(
fields: Optional[Dict[str, Any]] = None,
include: Union[List[str], str, None] = None,
exclude: Union[List[str], str, None] = None,
scope: Union[List[str], str, None] = None,
summarise: Union[List[str], str, None] = None,
) -> Generator[Dict[str, Any], Any, None]:
"""
Expand All @@ -1174,7 +1151,6 @@ def filter(
fields: Series of conditions on fields, used to filter the data.
include: Fields to include in the output.
exclude: Fields to exclude from the output.
scope: Additional named group(s) of fields to include in the output.
summarise: For a given field (or group of fields), return the frequency of each unique value (or unique group of values).
Returns:
Expand Down Expand Up @@ -1293,7 +1269,6 @@ def filter(
fields=fields,
include=include,
exclude=exclude,
scope=scope,
summarise=summarise,
)
for response in responses:
Expand All @@ -1308,7 +1283,6 @@ def query(
query: Optional[OnyxField] = None,
include: Union[List[str], str, None] = None,
exclude: Union[List[str], str, None] = None,
scope: Union[List[str], str, None] = None,
summarise: Union[List[str], str, None] = None,
) -> Generator[Dict[str, Any], Any, None]:
"""
Expand All @@ -1319,7 +1293,6 @@ def query(
query: OnyxField object representing the query being made.
include: Fields to include in the output.
exclude: Fields to exclude from the output.
scope: Additional named group(s) of fields to include in the output.
summarise: For a given field (or group of fields), return the frequency of each unique value (or unique group of values).
Returns:
Expand Down Expand Up @@ -1376,7 +1349,6 @@ def query(
query=query,
include=include,
exclude=exclude,
scope=scope,
summarise=summarise,
)
for response in responses:
Expand Down
Loading

0 comments on commit 667a9fe

Please sign in to comment.