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

Commit 8da324c

Browse files
authored
Merge pull request #8 from swiftype/updates-naming
Updates naming
2 parents 5abb9ad + 7bc93a3 commit 8da324c

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ Instantiating a client
3939
.. code-block:: python
4040
4141
>>> from swiftype_app_search import Client
42-
>>> account_host_key = 'host-c5s2mj'
42+
>>> host_identifier = 'host-c5s2mj'
4343
>>> api_key = 'api-mu75psc5egt9ppzuycnc2mc3'
44-
>>> client = Client(account_host_key, api_key)
44+
>>> client = Client(host_identifier, api_key)
4545
4646
Index document
4747
--------------
@@ -160,4 +160,4 @@ Creating a search key that will only search over the body field.
160160
>>> api_key = 'api-mu75psc5egt9ppzuycnc2mc3'
161161
>>> api_key_name = 'my-api-token'
162162
>>> signed_search_key = Client.create_signed_search_key(api_key, api_key_name, {'search_fields': { 'body': {}}})
163-
>>> client = Client(account_host_key, signed_search_key)
163+
>>> client = Client(host_identifier, signed_search_key)

swiftype_app_search/client.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ class Client:
99
SWIFTYPE_APP_SEARCH_BASE_ENDPOINT = 'api.swiftype.com/api/as/v1'
1010
SIGNED_SEARCH_TOKEN_JWT_ALGORITHM = 'HS256'
1111

12-
def __init__(self, account_host_key, api_key,
12+
def __init__(self, host_identifier='', api_key='',
1313
base_endpoint=SWIFTYPE_APP_SEARCH_BASE_ENDPOINT,
14-
use_https=True):
15-
self.account_host_key = account_host_key
14+
use_https=True,
15+
account_host_key='' # Deprecated - use host_identifier instead
16+
):
17+
self.host_identifier = host_identifier or account_host_key
18+
self.account_host_key = self.host_identifier # Deprecated
1619
self.api_key = api_key
1720

1821
uri_scheme = 'https' if use_https else 'http'
19-
base_url = "{}://{}.{}".format(uri_scheme, account_host_key, base_endpoint)
22+
base_url = "{}://{}.{}".format(uri_scheme, host_identifier, base_endpoint)
2023
self.swiftype_session = SwiftypeRequestSession(self.api_key, base_url)
2124

2225
def get_documents(self, engine_name, document_ids):

tests/test_client.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,25 @@ class TestClient(TestCase):
88

99
def setUp(self):
1010
self.engine_name = 'some-engine-name'
11-
self.client = Client('account_host_key', 'api_key')
11+
self.client = Client('host_identifier', 'api_key')
1212

1313
self.document_index_url = "{}/{}".format(
1414
self.client.swiftype_session.base_url,
1515
"engines/{}/documents".format(self.engine_name)
1616
)
1717

18+
def test_deprecated_init_support_with_old_names(self):
19+
self.client = Client(account_host_key='host_identifier', api_key='api_key')
20+
self.assertEqual(self.client.account_host_key, 'host_identifier')
21+
22+
def test_deprecated_init_support_with_new_names(self):
23+
self.client = Client(host_identifier='host_identifier', api_key='api_key')
24+
self.assertEqual(self.client.account_host_key, 'host_identifier')
25+
26+
def test_deprecated_init_support_with_positional(self):
27+
self.client = Client('host_identifier', 'api_key', 'example.com', False)
28+
self.assertEqual(self.client.account_host_key, 'host_identifier')
29+
1830
def test_index_document_processing_error(self):
1931
invalid_document = {'id': 'something', 'bad': {'no': 'nested'}}
2032
error = 'some processing error'

0 commit comments

Comments
 (0)