def test_endpoint(self): self.assertEqual( '', endpoint('') ) self.assertEqual( '/1/indexes/test/settings', endpoint('/1/indexes/test/settings') ) self.assertEqual( '/1/indexes/test/task/123', endpoint('/1/indexes/test/task/{}', 123) ) self.assertEqual( '/1/indexes/index%23name/task/1234', endpoint('/1/indexes/{}/task/{}', 'index#name', 1234) ) self.assertEqual( '/1/indexes/%23index%20name_42%23%2523/batch', endpoint('/1/indexes/{}/batch', '#index name_42#%23') )
def delete_api_key(self, key, request_options=None): # type: (str, Optional[Union[dict, RequestOptions]]) -> DeleteApiKeyResponse # noqa: E501 raw_response = self._transporter.write(Verb.DELETE, endpoint("1/keys/{}", key), None, request_options) return DeleteApiKeyResponse(self, raw_response, key)
def get_synonym(self, object_id, request_options=None): # type: (str, Optional[Union[dict, RequestOptions]]) -> dict return self._transporter.read( Verb.GET, endpoint('1/indexes/{}/synonyms/{}', self._name, object_id), None, request_options)
def set_settings(self, settings, request_options=None): # type: (dict, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501 raw_response = self._transporter.write( Verb.PUT, endpoint('1/indexes/{}/settings', self._name), settings, request_options) return IndexingResponse(self, [raw_response])
def delete_by(self, filters, request_options=None): # type: (dict, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501 raw_response = self._transporter.write( Verb.POST, endpoint('1/indexes/{}/deleteByQuery', self._name), filters, request_options) return IndexingResponse(self, [raw_response])
def get_task(self, task_id, request_options=None): # type: (int, Optional[Union[dict, RequestOptions]]) -> dict assert task_id, 'task_id cannot be empty.' return self._transporter.read( 'GET', endpoint('1/indexes/{}/task/{}', self._name, task_id), None, request_options)
def delete_ab_test(self, ab_test_id, request_options=None): # type: (int, Optional[Union[Dict[str, Any], RequestOptions]]) -> dict assert ab_test_id, 'ab_test_id cannot be empty.' return self._transporter.write(Verb.DELETE, endpoint('2/abtests/{}', ab_test_id), None, request_options)
def get_ab_test(self, ab_test_id, request_options=None): # type: (str, Optional[Union[Dict[str, Any], RequestOptions]]) -> dict assert ab_test_id, 'ab_test_id cannot be empty.' return self._transporter.read(Verb.GET, endpoint('2/abtests/{}', ab_test_id), None, request_options)
def clear_objects(self, request_options=None): # type: (Optional[Union[dict, RequestOptions]]) -> IndexingResponse raw_response = self._transporter.write( Verb.POST, endpoint("1/indexes/{}/clear", self._name), None, request_options ) return IndexingResponse(self, [raw_response])
def delete(self, request_options=None): # type: (Optional[Union[dict, RequestOptions]]) -> Response raw_response = self._transporter.write( Verb.DELETE, endpoint("1/indexes/{}", self._name), None, request_options ) return IndexingResponse(self, [raw_response])
def restore_api_key(self, key, request_options=None): # type: (str, Optional[Union[dict, RequestOptions]]) -> RestoreApiKeyResponse # noqa: E501 raw_response = self._transporter.write( Verb.POST, endpoint("1/keys/{}/restore", key), None, request_options) return RestoreApiKeyResponse(self, raw_response, key)
def stop_ab_test(self, ab_test_id, request_options=None): # type: (int, Optional[Union[Dict[str, Any], RequestOptions]]) -> dict assert ab_test_id, "ab_test_id cannot be empty." return self._transporter.write( Verb.POST, endpoint("2/abtests/{}/stop", ab_test_id), None, request_options)
def get_user_id(self, user_id, request_options=None): # type: (str, Optional[Union[dict, RequestOptions]]) -> dict return self._transporter.read( Verb.GET, endpoint('1/clusters/mapping/{}', user_id), None, request_options )
def _raw_batch(self, requests, request_options): # type: (Union[List[dict], Iterator[dict]], Optional[Union[dict, RequestOptions]]) -> dict # noqa: E501 return self._transporter.write( Verb.POST, endpoint("1/indexes/{}/batch", self._name), {"requests": list(requests)}, request_options, )
def search_rules(self, query, request_options=None): # type: (str, Optional[Union[dict, RequestOptions]]) -> dict # noqa: E501 return self._transporter.read( Verb.POST, endpoint("1/indexes/{}/rules/search", self._name), {"query": str(query)}, request_options, )
def get_rule(self, object_id, request_options=None): # type: (str, Optional[Union[dict, RequestOptions]]) -> dict return self._transporter.read( Verb.GET, endpoint('1/indexes/{}/rules/{}', self._name, object_id), None, request_options )
def get_api_key(self, key, request_options=None): # type: (str, Optional[Union[dict, RequestOptions]]) -> dict return self._transporter.read( Verb.GET, endpoint('1/keys/{}', key), None, request_options )
def delete_rule(self, object_id, request_options=None): # type: (str, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501 raw_response = self._transporter.write( Verb.DELETE, endpoint('1/indexes/{}/rules/{}', self._name, object_id), None, request_options) return IndexingResponse(self, [raw_response])
def search_for_facet_values(self, facet_name, facet_query, request_options=None): # type: (str, str, Optional[Union[dict, RequestOptions]]) -> dict # noqa: E501 return self._transporter.read( Verb.POST, endpoint("1/indexes/{}/facets/{}/query", self._name, facet_name), {"facetQuery": facet_query}, request_options, )
def copy_to(self, name, request_options=None): # type: (str, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501 raw_response = self._transporter.write( Verb.POST, endpoint('1/indexes/{}/operation', self._name), { 'operation': 'copy', 'destination': name }, request_options) return IndexingResponse(self, [raw_response])
def get_settings_async(self, request_options=None): # type: ignore # type: (Optional[Union[dict, RequestOptions]]) -> dict params = {'getVersion': 2} raw_response = yield from self._transporter_async.read( Verb.GET, endpoint('1/indexes/{}/settings', self._name), params, request_options) return SettingsDeserializer.deserialize(raw_response)
def get_settings(self, request_options=None): # type: (Optional[Union[dict, RequestOptions]]) -> dict # noqa: E501 params = {'getVersion': 2} raw_response = self._transporter.read( Verb.GET, endpoint('1/indexes/{}/settings', self._name), params, request_options) return SettingsDeserializer.deserialize(raw_response)
def delete_api_key(self, key, request_options=None): # type: (str, Optional[Union[dict, RequestOptions]]) -> DeleteApiKeyResponse # noqa: E501 raw_response = self._transporter.write( Verb.DELETE, endpoint('1/keys/{}', key), None, request_options ) return DeleteApiKeyResponse(self, raw_response, key)
def test_endpoint(self): self.assertEqual("", endpoint("")) self.assertEqual("/1/indexes/test/settings", endpoint("/1/indexes/test/settings")) self.assertEqual("/1/indexes/test/task/123", endpoint("/1/indexes/test/task/{}", 123)) self.assertEqual( "/1/indexes/index%23name/task/1234", endpoint("/1/indexes/{}/task/{}", "index#name", 1234), ) self.assertEqual( "/1/indexes/%23index%20name_42%23%2523/batch", endpoint("/1/indexes/{}/batch", "#index name_42#%23"), )
def set_settings(self, settings, request_options=None): # type: (dict, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501 raw_response = self._transporter.write( Verb.PUT, endpoint('1/indexes/{}/settings', self._name), settings, request_options ) return IndexingResponse(self, [raw_response])
def _raw_batch(self, requests, request_options): # type: (Union[List[dict], Iterator[dict]], Optional[Union[dict, RequestOptions]]) -> dict # noqa: E501 return self._transporter.write( Verb.POST, endpoint('1/indexes/{}/batch', self._name), { 'requests': list(requests) }, request_options )
def delete(self, request_options=None): # type: (Optional[Union[dict, RequestOptions]]) -> Response raw_response = self._transporter.write( Verb.DELETE, endpoint('1/indexes/{}', self._name), None, request_options ) return IndexingResponse(self, [raw_response])
def get_task(self, task_id, request_options=None): # type: (int, Optional[Union[dict, RequestOptions]]) -> dict assert task_id, 'task_id cannot be empty.' return self._transporter.read( 'GET', endpoint('1/indexes/{}/task/{}', self._name, task_id), None, request_options )
def clear_rules(self, request_options=None): # type: (Optional[Union[dict, RequestOptions]]) -> IndexingResponse raw_response = self._transporter.write( Verb.POST, endpoint('1/indexes/{}/rules/clear', self._name), None, request_options ) return IndexingResponse(self, [raw_response])
def delete_rule(self, object_id, request_options=None): # type: (str, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501 raw_response = self._transporter.write( Verb.DELETE, endpoint('1/indexes/{}/rules/{}', self._name, object_id), None, request_options ) return IndexingResponse(self, [raw_response])
def search_rules(self, query, request_options=None): # type: (str, Optional[Union[dict, RequestOptions]]) -> dict # noqa: E501 return self._transporter.read( Verb.POST, endpoint('1/indexes/{}/rules/search', self._name), { 'query': str(query) }, request_options )
def delete_ab_test(self, ab_test_id, request_options=None): # type: (int, Optional[Union[Dict[str, Any], RequestOptions]]) -> dict assert ab_test_id, 'ab_test_id cannot be empty.' return self._transporter.write( Verb.DELETE, endpoint('2/abtests/{}', ab_test_id), None, request_options )
def move_index(self, src_index_name, dst_index_name, request_options=None): # type: (str, str, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501 raw_response = self._transporter.write( Verb.POST, endpoint('1/indexes/{}/operation', src_index_name), { 'operation': 'move', 'destination': dst_index_name }, request_options) return IndexingResponse(self.init_index(src_index_name), [raw_response])
def get_ab_test(self, ab_test_id, request_options=None): # type: (str, Optional[Union[Dict[str, Any], RequestOptions]]) -> dict assert ab_test_id, 'ab_test_id cannot be empty.' return self._transporter.read( Verb.GET, endpoint('2/abtests/{}', ab_test_id), None, request_options )
def move_to(self, name, request_options=None): # type: (str, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501 raw_response = self._transporter.write( Verb.POST, endpoint("1/indexes/{}/operation", self._name), {"operation": "move", "destination": name}, request_options, ) return IndexingResponse(self, [raw_response])
def delete_by(self, filters, request_options=None): # type: (dict, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501 raw_response = self._transporter.write( Verb.POST, endpoint('1/indexes/{}/deleteByQuery', self._name), filters, request_options ) return IndexingResponse(self, [raw_response])
def search_synonyms(self, query, request_options=None): # type: (str, Optional[Union[dict, RequestOptions]]) -> dict # noqa: E501 return self._transporter.read( Verb.POST, endpoint('1/indexes/{}/synonyms/search', self._name), { 'query': str(query) }, request_options )
def restore_api_key(self, key, request_options=None): # type: (str, Optional[Union[dict, RequestOptions]]) -> RestoreApiKeyResponse # noqa: E501 raw_response = self._transporter.write( Verb.POST, endpoint('1/keys/{}/restore', key), None, request_options ) return RestoreApiKeyResponse(self, raw_response, key)
def search_dictionary_entries(self, dictionary, query, request_options=None): # type: (str, str, Optional[Union[dict, RequestOptions]]) -> dict return self._transporter.read( Verb.POST, endpoint("1/dictionaries/{}/search", dictionary), {"query": query}, request_options, )
def search_for_facet_values(self, facet_name, facet_query, request_options=None): # type: (str, str, Optional[Union[dict, RequestOptions]]) -> dict # noqa: E501 return self._transporter.read( Verb.POST, endpoint('1/indexes/{}/facets/{}/query', self._name, facet_name), { 'facetQuery': facet_query }, request_options )
def update_api_key(self, key, request_options=None): # type: (str, Optional[Union[dict, RequestOptions]]) -> UpdateApiKeyResponse # noqa: E501 if not isinstance(request_options, RequestOptions): request_options = RequestOptions.create(self._config, request_options) raw_response = self._transporter.write(Verb.PUT, endpoint("1/keys/{}", key), {}, request_options) return UpdateApiKeyResponse(self, raw_response, request_options)
def get_settings(self, request_options=None): # type: (Optional[Union[dict, RequestOptions]]) -> dict # noqa: E501 params = {'getVersion': 2} raw_response = self._transporter.read( Verb.GET, endpoint('1/indexes/{}/settings', self._name), params, request_options ) return SettingsDeserializer.deserialize(raw_response)
def save_rules(self, rules, request_options=None): # type: (Union[List[dict], Iterator[dict]], Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501 if not rules: return IndexingResponse(self, []) assert_object_id(rules) raw_response = self._transporter.write( Verb.POST, endpoint('1/indexes/{}/rules/batch', self._name), list(rules), request_options) return IndexingResponse(self, [raw_response])
def get_settings_async(self, request_options=None): # type: ignore # type: (Optional[Union[dict, RequestOptions]]) -> dict params = {'getVersion': 2} raw_response = yield from self._transporter_async.read( Verb.GET, endpoint('1/indexes/{}/settings', self._name), params, request_options ) return SettingsDeserializer.deserialize(raw_response)
def copy_to(self, name, request_options=None): # type: (str, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501 raw_response = self._transporter.write( Verb.POST, endpoint('1/indexes/{}/operation', self._name), { 'operation': 'copy', 'destination': name }, request_options ) return IndexingResponse(self, [raw_response])
def get_settings_async(self, request_options=None): # type: ignore # type: (Optional[Union[dict, RequestOptions]]) -> dict if request_options is None or isinstance(request_options, dict): request_options = RequestOptions.create(self._config, request_options) request_options.query_parameters['getVersion'] = 2 raw_response = yield from self._transporter_async.read( Verb.GET, endpoint('1/indexes/{}/settings', self._name), None, request_options) return SettingsDeserializer.deserialize(raw_response)
def move_index(self, src_index_name, dst_index_name, request_options=None): # type: (str, str, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501 raw_response = self._transporter.write( Verb.POST, endpoint('1/indexes/{}/operation', src_index_name), { 'operation': 'move', 'destination': dst_index_name }, request_options ) return IndexingResponse(self.init_index(src_index_name), [raw_response])
def update_api_key(self, key, request_options=None): # type: (str, Optional[Union[dict, RequestOptions]]) -> UpdateApiKeyResponse # noqa: E501 if not isinstance(request_options, RequestOptions): request_options = RequestOptions.create(self._config, request_options) raw_response = self._transporter.write( Verb.PUT, endpoint('1/keys/{}', key), {}, request_options ) return UpdateApiKeyResponse(self, raw_response, request_options)
def copy_index(self, src_index_name, dst_index_name, request_options=None): # type: (str, str, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501 raw_response = self._transporter.write( Verb.POST, endpoint("1/indexes/{}/operation", src_index_name), { "operation": "copy", "destination": dst_index_name }, request_options, ) return IndexingResponse(self.init_index(src_index_name), [raw_response])
def save_rules(self, rules, request_options=None): # type: (Union[List[dict], Iterator[dict]], Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501 if not rules: return IndexingResponse(self, []) assert_object_id(rules) raw_response = self._transporter.write( Verb.POST, endpoint('1/indexes/{}/rules/batch', self._name), list(rules), request_options ) return IndexingResponse(self, [raw_response])