Repository: swiftype/swiftype-app-search-python

Issue:
Client should be able to get and create/update engine schema
The python client should have the ability to get the current schema of an engine, or create/update new schema fields on an engine using the follwing app search endpoints.

`GET /api/as/v1/engines/{ENGINE_NAME}/schema`
`POST /api/as/v1/engines/{ENGINE_NAME}/schema`

Discussion:
JasonStoltz: Hey @CorrosiveKid, thank you for the contribution. Before we can merge this, we require that you sign a CLA.
CorrosiveKid: > Hey @CorrosiveKid, thank you for the contribution. Before we can merge this, we require that you sign a CLA: https://www.elastic.co/contributor-agreement.

Done!

Patch:
diff --git a/README.md b/README.md
index 297cd83..5334f63 100644
--- a/README.md
+++ b/README.md
@@ -145,6 +145,26 @@ The client can be configured to use a managed deploy by adjusting the `base_endp
 [{'id': 'INscMGmhmX4','result': True}]
 ```
 
+### Get Schema
+
+```python
+>>> engine_name = 'favorite-videos'
+>>> client.get_schema(engine_name)
+{'name':'text', 'square_km': 'number', 'square_mi': 'text'}
+```
+
+### Create/Update Schema
+
+```python
+>>> engine_name = 'favorite-videos'
+>>> client.update_schema(engine_name, {'square_km': 'text'})
+{'square_km': 'text'}
+>>> client.update_schema(engine_name, {'square_mi': 'text'})
+{'square_km': 'text', 'square_mi': 'text'}
+>>> client.update_schema(engine_name, {'square_km': 'number'})
+{'square_km': 'number', 'square_mi': 'text'}
+```
+
 ### List Engines
 
 ```python
diff --git a/setup.py b/setup.py
index 9d422f4..3452647 100644
--- a/setup.py
+++ b/setup.py
@@ -18,6 +18,7 @@ setup(
     version=about['__version__'],
     description=about['__description__'],
     long_description=long_description,
+    long_description_content_type='text/markdown',
     url=about['__url__'],
     author=about['__author__'],
     author_email=about['__author_email__'],
diff --git a/swiftype_app_search/client.py b/swiftype_app_search/client.py
index 92e2dd7..7022a27 100644
--- a/swiftype_app_search/client.py
+++ b/swiftype_app_search/client.py
@@ -107,6 +107,28 @@ class Client:
         data = json.dumps(document_ids)
         return self.swiftype_session.request('delete', endpoint, data=data)
 
+    def get_schema(self, engine_name):
+        """
+        Get current schema for an engine.
+
+        :param engine_name: Name of engine.
+        :return: Schema.
+        """
+        endpoint = "engines/{}/schema".format(engine_name)
+        return self.swiftype_session.request('get', endpoint)
+
+    def update_schema(self, engine_name, schema):
+        """
+        Create new schema fields or update the fields if they already exists.
+
+        :param engine_name: Name of engine.
+        :param schema: Schema to be updated as dict.
+        :return: Updated schema.
+        """
+        endpoint = "engines/{}/schema".format(engine_name)
+        data = json.dumps(schema)
+        return self.swiftype_session.request('post', endpoint, data=data)
+
     def list_engines(self, current=1, size=20):
         """
         Lists engines that the api key has access to.


Test patch:
diff --git a/tests/test_client.py b/tests/test_client.py
index 66c9bfd..3babf11 100644
--- a/tests/test_client.py
+++ b/tests/test_client.py
@@ -136,6 +136,39 @@ class TestClient(TestCase):
             response = self.client.destroy_documents(self.engine_name, [id])
             self.assertEqual(response, expected_return)
 
+    def test_get_schema(self):
+        expected_return = {
+            'square_km': 'text'
+        }
+
+        with requests_mock.Mocker() as m:
+            url = "{}/engines/{}/schema".format(self.client.swiftype_session.base_url, self.engine_name)
+            m.register_uri('GET',
+                url,
+                json=expected_return,
+                status_code=200
+            )
+
+            response = self.client.get_schema(self.engine_name)
+            self.assertEqual(response, expected_return)
+
+    def test_update_schema(self):
+        expected_return = {
+            'square_mi': 'number',
+            'square_km': 'number'
+        }
+
+        with requests_mock.Mocker() as m:
+            url = "{}/engines/{}/schema".format(self.client.swiftype_session.base_url, self.engine_name)
+            m.register_uri('POST',
+                url,
+                json=expected_return,
+                status_code=200
+            )
+
+            response = self.client.update_schema(self.engine_name, expected_return)
+            self.assertEqual(response, expected_return)
+
     def test_list_engines(self):
         expected_return = [
             { 'name': 'myawesomeengine' }