Skip to content

Commit d7a803d

Browse files
authored
Wrapperクラスにget_editor_annotation_or_none関数を追加 (#455)
* get_editor_annotation_or_none * updat version
1 parent 8be34a3 commit d7a803d

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

annofabapi/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.57.0"
1+
__version__ = "0.58.0"

annofabapi/wrapper.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,32 @@ def _download(self, url: str, dest_path: Union[str, Path]) -> requests.Response:
228228
#########################################
229229
# Public Method : Annotation
230230
#########################################
231+
def get_editor_annotation_or_none(
232+
self, project_id: str, task_id: str, input_data_id: str, *, query_params: Optional[Dict[str, Any]] = None
233+
) -> Optional[Dict[str, Any]]:
234+
"""
235+
アノテーションを取得する。
236+
存在しない場合(HTTP 404 Error)はNoneを返します。
237+
238+
Args:
239+
project_id: プロジェクトID
240+
task_id: タスクID
241+
input_data_id: 入力データID
242+
243+
Returns:
244+
アノテーション
245+
"""
246+
content, response = self.api.get_editor_annotation(
247+
project_id, task_id, input_data_id, query_params=query_params, raise_for_status=False
248+
)
249+
250+
if response.status_code == requests.codes.not_found:
251+
return None
252+
else:
253+
_log_error_response(logger, response)
254+
_raise_for_status(response)
255+
return content
256+
231257
def download_annotation_archive(self, project_id: str, dest_path: Union[str, Path]) -> str:
232258
"""
233259
simpleアノテーションZIPをダウンロードする。

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "annofabapi"
3-
version = "0.57.0"
3+
version = "0.58.0"
44
description = "Python Clinet Library of AnnoFab WebAPI (https://annofab.com/docs/api/)"
55
authors = ["yuji38kwmt"]
66
license = "MIT"

tests/test_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,14 @@ def test_get_task_histories_or_none(self):
666666

667667
assert wrapper.get_task_histories_or_none("not-exists", task_id) is None
668668

669+
def test_get_task_histories_or_none(self):
670+
actual = wrapper.get_editor_annotation_or_none(project_id, task_id, self.input_data_id)
671+
assert actual["task_id"] == task_id
672+
assert actual["input_data_id"] == self.input_data_id
673+
674+
assert wrapper.get_editor_annotation_or_none(project_id, task_id, "not-exists") is None
675+
assert wrapper.get_editor_annotation_or_none(project_id, "not-exists", "not-exists") is None
676+
669677

670678
class TestProtectedMethod:
671679
@classmethod

0 commit comments

Comments
 (0)