コード例 #1
0
    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')
        )
コード例 #2
0
    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)
コード例 #3
0
    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)
コード例 #4
0
    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])
コード例 #5
0
    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])
コード例 #6
0
    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)
コード例 #7
0
    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)
コード例 #8
0
    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)
コード例 #9
0
    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])
コード例 #10
0
    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])
コード例 #11
0
    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)
コード例 #12
0
    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)
コード例 #13
0
    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
        )
コード例 #14
0
    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,
        )
コード例 #15
0
    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,
        )
コード例 #16
0
    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
        )
コード例 #17
0
    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
        )
コード例 #18
0
    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
        )
コード例 #19
0
    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])
コード例 #20
0
    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
        )
コード例 #21
0
    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,
        )
コード例 #22
0
    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])
コード例 #23
0
    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)
コード例 #24
0
    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)
コード例 #25
0
    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)
コード例 #26
0
    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"),
        )
コード例 #27
0
    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])
コード例 #28
0
    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
        )
コード例 #29
0
    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])
コード例 #30
0
    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
        )
コード例 #31
0
    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])
コード例 #32
0
    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])
コード例 #33
0
    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
        )
コード例 #34
0
    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
        )
コード例 #35
0
    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])
コード例 #36
0
    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
        )
コード例 #37
0
    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])
コード例 #38
0
    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])
コード例 #39
0
    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
        )
コード例 #40
0
    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)
コード例 #41
0
    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,
        )
コード例 #42
0
    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
        )
コード例 #43
0
    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)
コード例 #44
0
    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)
コード例 #45
0
    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])
コード例 #46
0
    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)
コード例 #47
0
    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])
コード例 #48
0
    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)
コード例 #49
0
    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])
コード例 #50
0
    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)
コード例 #51
0
    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])
コード例 #52
0
    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])