Skip to content

Commit a2c737a

Browse files
committed
Start using helper for result codes
1 parent d70e545 commit a2c737a

File tree

1 file changed

+15
-42
lines changed

1 file changed

+15
-42
lines changed

src/vws/vws.py

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -82,51 +82,24 @@ def _target_api_request(
8282
return response
8383

8484

85-
class _ResultCodes(Enum):
86-
"""
87-
Constants representing various VWS result codes.
88-
89-
See
90-
https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API.html#How-To-Interperete-VWS-API-Result-Codes
91-
92-
Some codes here are not documented in the above link.
93-
"""
94-
95-
SUCCESS = 'Success'
96-
TARGET_CREATED = 'TargetCreated'
97-
AUTHENTICATION_FAILURE = 'AuthenticationFailure'
98-
REQUEST_TIME_TOO_SKEWED = 'RequestTimeTooSkewed'
99-
TARGET_NAME_EXIST = 'TargetNameExist'
100-
UNKNOWN_TARGET = 'UnknownTarget'
101-
BAD_IMAGE = 'BadImage'
102-
IMAGE_TOO_LARGE = 'ImageTooLarge'
103-
METADATA_TOO_LARGE = 'MetadataTooLarge'
104-
DATE_RANGE_ERROR = 'DateRangeError'
105-
FAIL = 'Fail'
106-
TARGET_STATUS_PROCESSING = 'TargetStatusProcessing'
107-
REQUEST_QUOTA_REACHED = 'RequestQuotaReached'
108-
TARGET_STATUS_NOT_SUCCESS = 'TargetStatusNotSuccess'
109-
PROJECT_INACTIVE = 'ProjectInactive'
110-
INACTIVE_PROJECT = 'InactiveProject'
111-
112-
11385
def _raise_for_result_code(
11486
response: Response,
115-
expected_result_code: _ResultCodes,
87+
expected_result_code: str,
11688
) -> None:
11789
"""
118-
Raise an appropriate exception if
90+
Raise an appropriate exception if the expected result code for a successful
91+
request is not returned.
11992
"""
120-
result_code = _ResultCodes(response.json()['result_code'])
93+
result_code = response.json()['result_code']
12194
if result_code == expected_result_code:
12295
return
12396

12497
exception = {
125-
_ResultCodes.IMAGE_TOO_LARGE: ImageTooLarge,
126-
_ResultCodes.METADATA_TOO_LARGE: MetadataTooLarge,
127-
_ResultCodes.TARGET_NAME_EXIST: TargetNameExist,
128-
_ResultCodes.TARGET_STATUS_PROCESSING: TargetStatusProcessing,
129-
_ResultCodes.UNKNOWN_TARGET: UnknownTarget,
98+
'ImageTooLarge': ImageTooLarge,
99+
'MetadataTooLarge': MetadataTooLarge,
100+
'TargetNameExist': TargetNameExist,
101+
'TargetStatusProcessing': TargetStatusProcessing,
102+
'UnknownTarget': UnknownTarget,
130103
}[result_code]
131104

132105
raise exception(response=response)
@@ -207,7 +180,7 @@ def add_target(
207180

208181
_raise_for_result_code(
209182
response=response,
210-
expected_result_code=_ResultCodes.TARGET_CREATED,
183+
expected_result_code='TargetCreated',
211184
)
212185

213186
return str(response.json()['target_id'])
@@ -236,7 +209,7 @@ def get_target_record(self, target_id: str) -> Dict[str, Union[str, int]]:
236209

237210
_raise_for_result_code(
238211
response=response,
239-
expected_result_code=_ResultCodes.SUCCESS,
212+
expected_result_code='Success',
240213
)
241214
return dict(response.json()['target_record'])
242215

@@ -284,7 +257,7 @@ def list_targets(self) -> List[str]:
284257

285258
_raise_for_result_code(
286259
response=response,
287-
expected_result_code=_ResultCodes.SUCCESS,
260+
expected_result_code='Success',
288261
)
289262
return list(response.json()['results'])
290263

@@ -315,7 +288,7 @@ def get_target_summary_report(
315288

316289
_raise_for_result_code(
317290
response=response,
318-
expected_result_code=_ResultCodes.SUCCESS,
291+
expected_result_code='Success',
319292
)
320293
return dict(response.json())
321294

@@ -340,7 +313,7 @@ def get_database_summary_report(self) -> Dict[str, Union[str, int]]:
340313

341314
_raise_for_result_code(
342315
response=response,
343-
expected_result_code=_ResultCodes.SUCCESS,
316+
expected_result_code='Success',
344317
)
345318

346319
return dict(response.json())
@@ -366,5 +339,5 @@ def delete_target(self, target_id: str) -> None:
366339

367340
_raise_for_result_code(
368341
response=response,
369-
expected_result_code=_ResultCodes.SUCCESS,
342+
expected_result_code='Success',
370343
)

0 commit comments

Comments
 (0)