Skip to content

Commit 3360105

Browse files
committed
Progress
1 parent 7ff6e96 commit 3360105

File tree

4 files changed

+51
-18
lines changed

4 files changed

+51
-18
lines changed

src/vws/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"""
44

55
from ._version import get_versions
6-
from .vws import VWS
76
from .query import CloudRecoService
7+
from .vws import VWS
88

99
__all__ = [
1010
'CloudRecoService',

src/vws/query.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
import io
2+
from urllib.parse import urljoin
3+
4+
import requests
5+
from urllib3.filepost import encode_multipart_formdata
6+
7+
from ._authorization import authorization_header, rfc_1123_date
8+
29

310
class CloudRecoService:
411
"""
@@ -9,8 +16,8 @@ def __init__(
916
self,
1017
client_access_key: str,
1118
client_secret_key: str,
12-
# TODO - instead use vwq URL
13-
base_vws_url: str = 'https://vws.vuforia.com',
19+
# TODO - instead use/call this vwq URL
20+
base_vws_url: str = 'https://cloudreco.vuforia.com',
1421
) -> None:
1522
"""
1623
Args:
@@ -29,4 +36,37 @@ def query(
2936
"""
3037
TODO docstring
3138
"""
32-
pass
39+
image_content = image.getvalue()
40+
body = {'image': ('image.jpeg', image_content, 'image/jpeg')}
41+
date = rfc_1123_date()
42+
request_path = '/v1/query'
43+
content, content_type_header = encode_multipart_formdata(body)
44+
method = 'POST'
45+
46+
authorization_string = authorization_header(
47+
access_key=self._client_access_key,
48+
secret_key=self._client_secret_key,
49+
method=method,
50+
content=content,
51+
# Note that this is not the actual Content-Type header value sent.
52+
content_type='multipart/form-data',
53+
date=date,
54+
request_path=request_path,
55+
)
56+
57+
headers = {
58+
'Authorization': authorization_string,
59+
'Date': date,
60+
'Content-Type': content_type_header,
61+
}
62+
63+
response = requests.request(
64+
method=method,
65+
url=urljoin(base=self._base_vws_url, url=request_path),
66+
headers=headers,
67+
data=content,
68+
)
69+
70+
return response.json()['results']
71+
import pdb; pdb.set_trace()
72+
return response

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from mock_vws import MockVWS
99
from mock_vws.database import VuforiaDatabase
1010

11-
from vws import VWS
11+
from vws import CloudRecoService, VWS
1212

1313
pytest_plugins = [ # pylint: disable=invalid-name
1414
'tests.fixtures.images',

tests/test_query.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@
33
"""
44

55
import io
6-
from typing import Optional
76

8-
import pytest
9-
from mock_vws import MockVWS
10-
from mock_vws.database import VuforiaDatabase
11-
12-
from vws import CloudRecoService, VWS
13-
from vws.exceptions import TargetProcessingTimeout
7+
from vws import VWS, CloudRecoService
148

159

1610
class TestQuery:
@@ -20,21 +14,20 @@ class TestQuery:
2014

2115
def test_query(
2216
self,
23-
client: VWS,
17+
cloud_reco_client: CloudRecoService,
2418
high_quality_image: io.BytesIO,
2519
) -> None:
2620
"""
2721
TODO docstring
2822
"""
29-
cloud_reco_client = CloudRecoService(
30-
client_access_key='foo',
31-
client_secret_key='bar',
32-
)
3323
result = cloud_reco_client.query(image=high_quality_image)
3424
assert result == []
3525

26+
3627
# TODO test custom base URL
3728
# TODO test bad credentials
3829
# TODO test no results
3930
# TODO test some results
40-
# TODO do we give an image type? Infer it? What happens if we just always give jpeg?
31+
32+
# TODO do we give an image type? Infer it?
33+
# What happens if we just always give jpeg?

0 commit comments

Comments
 (0)