Skip to content

Commit 4cf28fc

Browse files
Merge pull request #2329 from VWS-Python/make-request-content-type
Expose content type parameter on VWS.make_request
2 parents e7d37e9 + 26603a6 commit 4cf28fc

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/vws/vws.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def _get_image_data(image: _ImageType) -> bytes:
6464

6565
@beartype
6666
def _target_api_request(
67+
*,
68+
content_type: str,
6769
server_access_key: str,
6870
server_secret_key: str,
6971
method: str,
@@ -75,9 +77,9 @@ def _target_api_request(
7577
Make a request to the Vuforia Target API.
7678
7779
This uses `requests` to make a request against https://vws.vuforia.com.
78-
The content type of the request will be `application/json`.
7980
8081
Args:
82+
content_type: The content type of the request.
8183
server_access_key: A VWS server access key.
8284
server_secret_key: A VWS server secret key.
8385
method: The HTTP method which will be used in the request.
@@ -90,7 +92,6 @@ def _target_api_request(
9092
The response to the request made by `requests`.
9193
"""
9294
date_string = rfc_1123_date()
93-
content_type = "application/json"
9495

9596
signature_string = authorization_header(
9697
access_key=server_access_key,
@@ -152,16 +153,17 @@ def __init__(
152153

153154
def make_request(
154155
self,
156+
*,
155157
method: str,
156158
data: bytes,
157159
request_path: str,
158160
expected_result_code: str,
161+
content_type: str,
159162
) -> Response:
160163
"""
161164
Make a request to the Vuforia Target API.
162165
163166
This uses `requests` to make a request against Vuforia.
164-
The content type of the request will be `application/json`.
165167
166168
Args:
167169
method: The HTTP method which will be used in the request.
@@ -170,6 +172,7 @@ def make_request(
170172
request.
171173
expected_result_code: See "VWS API Result Codes" on
172174
https://developer.vuforia.com/library/web-api/cloud-targets-web-services-api.
175+
content_type: The content type of the request.
173176
174177
Returns:
175178
The response to the request made by `requests`.
@@ -190,6 +193,7 @@ def make_request(
190193
server.
191194
"""
192195
response = _target_api_request(
196+
content_type=content_type,
193197
server_access_key=self._server_access_key,
194198
server_secret_key=self._server_secret_key,
195199
method=method,
@@ -316,6 +320,7 @@ def add_target(
316320
data=content,
317321
request_path="/targets",
318322
expected_result_code="TargetCreated",
323+
content_type="application/json",
319324
)
320325

321326
return str(json.loads(s=response.text)["target_id"])
@@ -353,6 +358,7 @@ def get_target_record(self, target_id: str) -> TargetStatusAndRecord:
353358
data=b"",
354359
request_path=f"/targets/{target_id}",
355360
expected_result_code="Success",
361+
content_type="application/json",
356362
)
357363

358364
result_data = json.loads(s=response.text)
@@ -449,6 +455,7 @@ def list_targets(self) -> list[str]:
449455
data=b"",
450456
request_path="/targets",
451457
expected_result_code="Success",
458+
content_type="application/json",
452459
)
453460

454461
return list(json.loads(s=response.text)["results"])
@@ -486,6 +493,7 @@ def get_target_summary_report(self, target_id: str) -> TargetSummaryReport:
486493
data=b"",
487494
request_path=f"/summary/{target_id}",
488495
expected_result_code="Success",
496+
content_type="application/json",
489497
)
490498

491499
result_data = dict(json.loads(s=response.text))
@@ -529,6 +537,7 @@ def get_database_summary_report(self) -> DatabaseSummaryReport:
529537
data=b"",
530538
request_path="/summary",
531539
expected_result_code="Success",
540+
content_type="application/json",
532541
)
533542

534543
response_data = dict(json.loads(s=response.text))
@@ -579,6 +588,7 @@ def delete_target(self, target_id: str) -> None:
579588
data=b"",
580589
request_path=f"/targets/{target_id}",
581590
expected_result_code="Success",
591+
content_type="application/json",
582592
)
583593

584594
def get_duplicate_targets(self, target_id: str) -> list[str]:
@@ -616,6 +626,7 @@ def get_duplicate_targets(self, target_id: str) -> list[str]:
616626
data=b"",
617627
request_path=f"/duplicates/{target_id}",
618628
expected_result_code="Success",
629+
content_type="application/json",
619630
)
620631

621632
return list(json.loads(s=response.text)["similar_targets"])
@@ -702,4 +713,5 @@ def update_target(
702713
data=content,
703714
request_path=f"/targets/{target_id}",
704715
expected_result_code="Success",
716+
content_type="application/json",
705717
)

0 commit comments

Comments
 (0)