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

Commit 9f796f1

Browse files
authored
Merge pull request #3 from afoucret/update-package-name
Update package name
2 parents 9b1db0e + d41d2ba commit 9f796f1

File tree

11 files changed

+92
-92
lines changed

11 files changed

+92
-92
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
To install the client, use pip:
2323

2424
```python
25-
python -m pip install swiftype_app_search
25+
python -m pip install elastic-app-search
2626
```
2727

2828
You can also download the project source and run::
@@ -42,7 +42,7 @@ python setup.py install
4242
### Instantiating a client
4343

4444
```python
45-
>>> from swiftype_app_search import Client
45+
>>> from elastic_app_search import Client
4646
>>> host_identifier = 'host-c5s2mj'
4747
>>> api_key = 'private-mu75psc5egt9ppzuycnc2mc3'
4848
>>> client = Client(host_identifier, api_key)
@@ -53,7 +53,7 @@ python setup.py install
5353
The client can be configured to use a managed deploy by adjusting the `base_endpoint` and `use_https` parameters. Since managed deploys do not rely on a `host_identifier`, it can be omitted.
5454

5555
```python
56-
>>> from swiftype_app_search import Client
56+
>>> from elastic_app_search import Client
5757
>>> client = Client(
5858
api_key='private-mu75psc5egt9ppzuycnc2mc3',
5959
base_endpoint='localhost:3002/api/as/v1',
File renamed without changes.

elastic_app_search/__version__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
__title__ = 'elastic-app-search'
2+
__description__ = 'An API client for Elastic App Search'
3+
__url__ = 'https://github.com/elastic/app-search-python'
4+
__version__ = '0.6.0'
5+
__author__ = 'Elastic'
6+
__author_email__ = 'support@elastic.co'

swiftype_app_search/client.py renamed to elastic_app_search/client.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import json
22
import jwt
3-
from .swiftype_request_session import SwiftypeRequestSession
3+
from .request_session import RequestSession
44
from .exceptions import InvalidDocument
55

66

77
class Client:
88

9-
SWIFTYPE_APP_SEARCH_BASE_ENDPOINT = 'api.swiftype.com/api/as/v1'
9+
ELASTIC_APP_SEARCH_BASE_ENDPOINT = 'api.swiftype.com/api/as/v1'
1010
SIGNED_SEARCH_TOKEN_JWT_ALGORITHM = 'HS256'
1111

1212
def __init__(self, host_identifier='', api_key='',
13-
base_endpoint=SWIFTYPE_APP_SEARCH_BASE_ENDPOINT,
13+
base_endpoint=ELASTIC_APP_SEARCH_BASE_ENDPOINT,
1414
use_https=True,
1515
account_host_key='' # Deprecated - use host_identifier instead
1616
):
@@ -21,7 +21,7 @@ def __init__(self, host_identifier='', api_key='',
2121
uri_scheme = 'https' if use_https else 'http'
2222
host_prefix = host_identifier + '.' if host_identifier else ''
2323
base_url = "{}://{}{}".format(uri_scheme, host_prefix, base_endpoint)
24-
self.swiftype_session = SwiftypeRequestSession(self.api_key, base_url)
24+
self.session = RequestSession(self.api_key, base_url)
2525

2626
def get_documents(self, engine_name, document_ids):
2727
"""
@@ -33,7 +33,7 @@ def get_documents(self, engine_name, document_ids):
3333
"""
3434
endpoint = "engines/{}/documents".format(engine_name)
3535
data = json.dumps(document_ids)
36-
return self.swiftype_session.request('get', endpoint, data=data)
36+
return self.session.request('get', endpoint, data=data)
3737

3838
def list_documents(self, engine_name, current=1, size=20):
3939
"""
@@ -44,12 +44,12 @@ def list_documents(self, engine_name, current=1, size=20):
4444
:return: List of documemts.
4545
"""
4646
data = { 'page': { 'current': current, 'size': size } }
47-
return self.swiftype_session.request('get', "engines/{}/documents/list".format(engine_name), json=data)
47+
return self.session.request('get', "engines/{}/documents/list".format(engine_name), json=data)
4848

4949
def index_document(self, engine_name, document):
5050
"""
5151
Create or update a document for an engine. Raises
52-
:class:`~swiftype_app_search.exceptions.InvalidDocument` when the document
52+
:class:`~elastic_app_search.exceptions.InvalidDocument` when the document
5353
has processing errors
5454
5555
:param engine_name: Name of engine to index documents into.
@@ -79,7 +79,7 @@ def index_documents(self, engine_name, documents):
7979
endpoint = "engines/{}/documents".format(engine_name)
8080
data = json.dumps(documents)
8181

82-
return self.swiftype_session.request('post', endpoint, data=data)
82+
return self.session.request('post', endpoint, data=data)
8383

8484
def update_documents(self, engine_name, documents):
8585
"""
@@ -93,7 +93,7 @@ def update_documents(self, engine_name, documents):
9393
endpoint = "engines/{}/documents".format(engine_name)
9494
data = json.dumps(documents)
9595

96-
return self.swiftype_session.request('patch', endpoint, data=data)
96+
return self.session.request('patch', endpoint, data=data)
9797

9898
def destroy_documents(self, engine_name, document_ids):
9999
"""
@@ -105,7 +105,7 @@ def destroy_documents(self, engine_name, document_ids):
105105
"""
106106
endpoint = "engines/{}/documents".format(engine_name)
107107
data = json.dumps(document_ids)
108-
return self.swiftype_session.request('delete', endpoint, data=data)
108+
return self.session.request('delete', endpoint, data=data)
109109

110110
def get_schema(self, engine_name):
111111
"""
@@ -115,7 +115,7 @@ def get_schema(self, engine_name):
115115
:return: Schema.
116116
"""
117117
endpoint = "engines/{}/schema".format(engine_name)
118-
return self.swiftype_session.request('get', endpoint)
118+
return self.session.request('get', endpoint)
119119

120120
def update_schema(self, engine_name, schema):
121121
"""
@@ -127,7 +127,7 @@ def update_schema(self, engine_name, schema):
127127
"""
128128
endpoint = "engines/{}/schema".format(engine_name)
129129
data = json.dumps(schema)
130-
return self.swiftype_session.request('post', endpoint, data=data)
130+
return self.session.request('post', endpoint, data=data)
131131

132132
def list_engines(self, current=1, size=20):
133133
"""
@@ -139,15 +139,15 @@ def list_engines(self, current=1, size=20):
139139
name of the engine.
140140
"""
141141
data = { 'page': { 'current': current, 'size': size } }
142-
return self.swiftype_session.request('get', 'engines', json=data)
142+
return self.session.request('get', 'engines', json=data)
143143

144144
def get_engine(self, engine_name):
145145
"""
146146
Retrieves an engine by name.
147147
:param engine_name: Name of an existing engine.
148148
:return: A dictionary corresponding to the name of the engine.
149149
"""
150-
return self.swiftype_session.request('get', "engines/{}".format(engine_name))
150+
return self.session.request('get', "engines/{}".format(engine_name))
151151

152152
def create_engine(self, engine_name, language=None):
153153
"""
@@ -159,7 +159,7 @@ def create_engine(self, engine_name, language=None):
159159
data = { 'name': engine_name }
160160
if language is not None:
161161
data['language'] = language
162-
return self.swiftype_session.request('post', 'engines', json=data)
162+
return self.session.request('post', 'engines', json=data)
163163

164164
def destroy_engine(self, engine_name):
165165
"""
@@ -168,7 +168,7 @@ def destroy_engine(self, engine_name):
168168
:return: A dictionary with a single key of `deleted` and a value of
169169
True or False.
170170
"""
171-
return self.swiftype_session.request('delete', "engines/{}".format(engine_name))
171+
return self.session.request('delete', "engines/{}".format(engine_name))
172172

173173
def search(self, engine_name, query, options=None):
174174
"""
@@ -182,7 +182,7 @@ def search(self, engine_name, query, options=None):
182182
endpoint = "engines/{}/search".format(engine_name)
183183
options = options or {}
184184
options['query'] = query
185-
return self.swiftype_session.request('get', endpoint, json=options)
185+
return self.session.request('get', endpoint, json=options)
186186

187187
def multi_search(self, engine_name, searches=None):
188188
"""
@@ -206,7 +206,7 @@ def build_options_from_search(search):
206206
options = {
207207
'queries': list(map(build_options_from_search, searches))
208208
}
209-
return self.swiftype_session.request('get', endpoint, json=options)
209+
return self.session.request('get', endpoint, json=options)
210210

211211
def query_suggestion(self, engine_name, query, options=None):
212212
"""
@@ -220,19 +220,19 @@ def query_suggestion(self, engine_name, query, options=None):
220220
endpoint = "engines/{}/query_suggestion".format(engine_name)
221221
options = options or {}
222222
options['query'] = query
223-
return self.swiftype_session.request('get', endpoint, json=options)
223+
return self.session.request('get', endpoint, json=options)
224224

225225
def click(self, engine_name, options):
226226
"""
227-
Sends a click event to the Swiftype App Search Api, to track a click-through event.
227+
Sends a click event to the Elastic App Search Api, to track a click-through event.
228228
See https://swiftype.com/documentation/app-search/ for more details
229229
on options and return values.
230230
231231
:param engine_name: Name of engine to search over.
232232
:param options: Dict of search options.
233233
"""
234234
endpoint = "engines/{}/click".format(engine_name)
235-
return self.swiftype_session.request_ignore_response('post', endpoint, json=options)
235+
return self.session.request_ignore_response('post', endpoint, json=options)
236236

237237

238238
@staticmethod

elastic_app_search/exceptions.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""Exceptions raised by Elastic App Search Client."""
2+
3+
class ElasticAppSearchError(Exception):
4+
"""Base class for all Elastic App Search errors."""
5+
6+
class InvalidCredentials(ElasticAppSearchError):
7+
"""Raised when request cannot authenticate"""
8+
9+
class NonExistentRecord(ElasticAppSearchError):
10+
"""Raised when record does not exist"""
11+
12+
class RecordAlreadyExists(ElasticAppSearchError):
13+
"""Raised when record already exists"""
14+
15+
class BadRequest(ElasticAppSearchError):
16+
"""Raised when bad request"""
17+
18+
class Forbidden(ElasticAppSearchError):
19+
"""Raised when http forbidden"""
20+
21+
class SynchronousDocumentIndexingFailed(ElasticAppSearchError):
22+
"""Raised when synchronous indexing of documents takes too long"""
23+
24+
class InvalidDocument(ElasticAppSearchError):
25+
"""When a document has a non-accepted field or is missing a required field"""
26+
27+
def __init__(self, message, document):
28+
super(ElasticAppSearchError, self).__init__(message)
29+
self.document = document

swiftype_app_search/swiftype_request_session.py renamed to elastic_app_search/request_session.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import requests
2-
import swiftype_app_search
2+
import elastic_app_search
33
from .exceptions import InvalidCredentials, NonExistentRecord, RecordAlreadyExists, BadRequest, Forbidden
44

55

6-
class SwiftypeRequestSession:
6+
class RequestSession:
77

88
def __init__(self, api_key, base_url):
99
self.api_key = api_key
@@ -12,8 +12,8 @@ def __init__(self, api_key, base_url):
1212

1313
headers = {
1414
'Authorization': "Bearer {}".format(api_key),
15-
'X-Swiftype-Client': 'swiftype-app-search-python',
16-
'X-Swiftype-Client-Version': swiftype_app_search.__version__,
15+
'X-Swiftype-Client': 'elastic-app-search-python',
16+
'X-Swiftype-Client-Version': elastic_app_search.__version__,
1717
'content-type': 'application/json; charset=utf8'
1818
}
1919
self.session.headers.update(headers)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
here = path.abspath(path.dirname(__file__))
1212
about = {}
13-
with open(path.join(here, 'swiftype_app_search', '__version__.py'), 'r', 'utf-8') as f:
13+
with open(path.join(here, 'elastic_app_search', '__version__.py'), 'r', 'utf-8') as f:
1414
exec(f.read(), about)
1515

1616
setup(
@@ -35,7 +35,7 @@
3535
'Programming Language :: Python :: 3.5',
3636
'Programming Language :: Python :: 3.6',
3737
],
38-
keywords='swiftype elastic app search api',
38+
keywords='elastic app search api',
3939
packages=find_packages(exclude=['contrib', 'docs', 'tests']),
4040
install_requires=[
4141
'requests',

swiftype_app_search/__version__.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

swiftype_app_search/exceptions.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)