Skip to content
This repository was archived by the owner on Sep 1, 2021. It is now read-only.

Commit de04594

Browse files
authored
Merge pull request #15 from swiftype/configurable-client
Release 0.4.0 - Updated Python client for Managed deploys
2 parents 5094318 + d151faf commit de04594

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

README.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,21 @@ Instantiating a client
4343
4444
>>> from swiftype_app_search import Client
4545
>>> host_identifier = 'host-c5s2mj'
46-
>>> api_key = 'api-mu75psc5egt9ppzuycnc2mc3'
46+
>>> api_key = 'private-mu75psc5egt9ppzuycnc2mc3'
4747
>>> client = Client(host_identifier, api_key)
4848
49+
Using with App Search Managed Deploys
50+
-------------------------------------
51+
52+
The client can be configured to use a managed deploy by adjusting the
53+
`base_endpoint` and `use_https` parameters. Since managed deploys do not
54+
rely on a `host_identifier`, it can be omitted.
55+
56+
.. code-block:: python
57+
58+
>>> from swiftype_app_search import Client
59+
>>> client = Client(api_key='private-mu75psc5egt9ppzuycnc2mc3', base_endpoint='localhost:3002/api/as/v1', use_https=False)
60+
4961
Index document
5062
--------------
5163

@@ -160,7 +172,7 @@ Creating a search key that will only search over the body field.
160172

161173
.. code-block:: python
162174
163-
>>> api_key = 'api-mu75psc5egt9ppzuycnc2mc3'
175+
>>> api_key = 'private-mu75psc5egt9ppzuycnc2mc3'
164176
>>> api_key_name = 'my-api-token'
165177
>>> signed_search_key = Client.create_signed_search_key(api_key, api_key_name, {'search_fields': { 'body': {}}})
166178
>>> client = Client(host_identifier, signed_search_key)

swiftype_app_search/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__title__ = 'swiftype_app_search'
22
__description__ = 'An API client for Swiftype App Search'
33
__url__ = 'https://github.com/swiftype/swiftype-app-search-python'
4-
__version__ = '0.3.0'
4+
__version__ = '0.4.0'
55
__author__ = 'Swiftype'
66
__author_email__ = 'eng@swiftype.com'

swiftype_app_search/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def __init__(self, host_identifier='', api_key='',
1919
self.api_key = api_key
2020

2121
uri_scheme = 'https' if use_https else 'http'
22-
base_url = "{}://{}.{}".format(uri_scheme, host_identifier, base_endpoint)
22+
host_prefix = host_identifier + '.' if host_identifier else ''
23+
base_url = "{}://{}{}".format(uri_scheme, host_prefix, base_endpoint)
2324
self.swiftype_session = SwiftypeRequestSession(self.api_key, base_url)
2425

2526
def get_documents(self, engine_name, document_ids):

tests/test_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ def test_deprecated_init_support_with_positional(self):
2727
self.client = Client('host_identifier', 'api_key', 'example.com', False)
2828
self.assertEqual(self.client.account_host_key, 'host_identifier')
2929

30+
def test_host_identifier_is_optional(self):
31+
client = Client('', 'api_key', 'localhost:3002/api/as/v1', False)
32+
query = 'query'
33+
34+
with requests_mock.Mocker() as m:
35+
url = "http://localhost:3002/api/as/v1/engines/some-engine-name/search"
36+
m.register_uri('GET', url, json={}, status_code=200)
37+
client.search(self.engine_name, query, {})
38+
3039
def test_index_document_processing_error(self):
3140
invalid_document = {'id': 'something', 'bad': {'no': 'nested'}}
3241
error = 'some processing error'

0 commit comments

Comments
 (0)