|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. |
| 4 | + |
| 5 | +module Algolia |
| 6 | + class CompositionClient |
| 7 | + attr_accessor :api_client |
| 8 | + |
| 9 | + def initialize(config = nil) |
| 10 | + raise "`config` is missing." if config.nil? |
| 11 | + raise "`app_id` is missing." if config.app_id.nil? || config.app_id == "" |
| 12 | + raise "`api_key` is missing." if config.api_key.nil? || config.api_key == "" |
| 13 | + |
| 14 | + @api_client = Algolia::ApiClient.new(config) |
| 15 | + end |
| 16 | + |
| 17 | + def self.create(app_id, api_key, opts = {}) |
| 18 | + hosts = [] |
| 19 | + hosts << Transport::StatefulHost.new("#{app_id}-dsn.algolia.net", accept: CallType::READ) |
| 20 | + hosts << Transport::StatefulHost.new("#{app_id}.algolia.net", accept: CallType::WRITE) |
| 21 | + |
| 22 | + hosts += 1 |
| 23 | + .upto(3) |
| 24 | + .map do |i| |
| 25 | + Transport::StatefulHost.new("#{app_id}-#{i}.algolianet.com", accept: CallType::READ | CallType::WRITE) |
| 26 | + end |
| 27 | + .shuffle |
| 28 | + |
| 29 | + config = Algolia::Configuration.new(app_id, api_key, hosts, "Composition", opts) |
| 30 | + create_with_config(config) |
| 31 | + end |
| 32 | + |
| 33 | + def self.create_with_config(config) |
| 34 | + new(config) |
| 35 | + end |
| 36 | + |
| 37 | + # Helper method to switch the API key used to authenticate the requests. |
| 38 | + # |
| 39 | + # @param api_key [String] the new API key to use. |
| 40 | + # @return [void] |
| 41 | + def set_client_api_key(api_key) |
| 42 | + @api_client.set_client_api_key(api_key) |
| 43 | + |
| 44 | + self |
| 45 | + end |
| 46 | + |
| 47 | + def add_user_agent_segment(segment, version = nil) |
| 48 | + @api_client.config.add_user_agent_segment(segment, version) |
| 49 | + |
| 50 | + self |
| 51 | + end |
| 52 | + |
| 53 | + # Runs a query on a single composition and returns matching results. |
| 54 | + # |
| 55 | + # Required API Key ACLs: |
| 56 | + # - search |
| 57 | + # @param composition_id [String] Unique Composition ObjectID. (required) |
| 58 | + # @param request_body [RequestBody] (required) |
| 59 | + # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional) |
| 60 | + # @return [Http::Response] the response |
| 61 | + def search_with_http_info(composition_id, request_body, request_options = {}) |
| 62 | + # verify the required parameter 'composition_id' is set |
| 63 | + if @api_client.config.client_side_validation && composition_id.nil? |
| 64 | + raise ArgumentError, "Parameter `composition_id` is required when calling `search`." |
| 65 | + end |
| 66 | + # verify the required parameter 'request_body' is set |
| 67 | + if @api_client.config.client_side_validation && request_body.nil? |
| 68 | + raise ArgumentError, "Parameter `request_body` is required when calling `search`." |
| 69 | + end |
| 70 | + |
| 71 | + path = "/1/compositions/{compositionID}/run".sub( |
| 72 | + "{" + "compositionID" + "}", |
| 73 | + Transport.encode_uri(composition_id.to_s) |
| 74 | + ) |
| 75 | + query_params = {} |
| 76 | + query_params = query_params.merge(request_options[:query_params]) unless request_options[:query_params].nil? |
| 77 | + header_params = {} |
| 78 | + header_params = header_params.merge(request_options[:header_params]) unless request_options[:header_params].nil? |
| 79 | + |
| 80 | + post_body = request_options[:debug_body] || @api_client.object_to_http_body(request_body) |
| 81 | + |
| 82 | + new_options = request_options.merge( |
| 83 | + :operation => :"CompositionClient.search", |
| 84 | + :header_params => header_params, |
| 85 | + :query_params => query_params, |
| 86 | + :body => post_body, |
| 87 | + :use_read_transporter => true |
| 88 | + ) |
| 89 | + |
| 90 | + @api_client.call_api(:POST, path, new_options) |
| 91 | + end |
| 92 | + |
| 93 | + # Runs a query on a single composition and returns matching results. |
| 94 | + # |
| 95 | + # Required API Key ACLs: |
| 96 | + # - search |
| 97 | + # @param composition_id [String] Unique Composition ObjectID. (required) |
| 98 | + # @param request_body [RequestBody] (required) |
| 99 | + # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional) |
| 100 | + # @return [SearchResponse] |
| 101 | + def search(composition_id, request_body, request_options = {}) |
| 102 | + response = search_with_http_info(composition_id, request_body, request_options) |
| 103 | + @api_client.deserialize(response.body, request_options[:debug_return_type] || "Composition::SearchResponse") |
| 104 | + end |
| 105 | + |
| 106 | + # Searches for values of a specified facet attribute on the composition's main source's index. - By default, facet values are sorted by decreasing count. You can adjust this with the `sortFacetValueBy` parameter. - Searching for facet values doesn't work if you have **more than 65 searchable facets and searchable attributes combined**. |
| 107 | + # |
| 108 | + # Required API Key ACLs: |
| 109 | + # - search |
| 110 | + # @param composition_id [String] Unique Composition ObjectID. (required) |
| 111 | + # @param facet_name [String] Facet attribute in which to search for values. This attribute must be included in the `attributesForFaceting` index setting with the `searchable()` modifier. (required) |
| 112 | + # @param search_for_facet_values_request [SearchForFacetValuesRequest] |
| 113 | + # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional) |
| 114 | + # @return [Http::Response] the response |
| 115 | + def search_for_facet_values_with_http_info( |
| 116 | + composition_id, |
| 117 | + facet_name, |
| 118 | + search_for_facet_values_request = nil, |
| 119 | + request_options = {} |
| 120 | + ) |
| 121 | + # verify the required parameter 'composition_id' is set |
| 122 | + if @api_client.config.client_side_validation && composition_id.nil? |
| 123 | + raise ArgumentError, "Parameter `composition_id` is required when calling `search_for_facet_values`." |
| 124 | + end |
| 125 | + # verify the required parameter 'facet_name' is set |
| 126 | + if @api_client.config.client_side_validation && facet_name.nil? |
| 127 | + raise ArgumentError, "Parameter `facet_name` is required when calling `search_for_facet_values`." |
| 128 | + end |
| 129 | + |
| 130 | + path = "/1/compositions/{compositionID}/facets/{facetName}/query" |
| 131 | + .sub("{" + "compositionID" + "}", Transport.encode_uri(composition_id.to_s)) |
| 132 | + .sub("{" + "facetName" + "}", Transport.encode_uri(facet_name.to_s)) |
| 133 | + query_params = {} |
| 134 | + query_params = query_params.merge(request_options[:query_params]) unless request_options[:query_params].nil? |
| 135 | + header_params = {} |
| 136 | + header_params = header_params.merge(request_options[:header_params]) unless request_options[:header_params].nil? |
| 137 | + |
| 138 | + post_body = request_options[:debug_body] || @api_client.object_to_http_body(search_for_facet_values_request) |
| 139 | + |
| 140 | + new_options = request_options.merge( |
| 141 | + :operation => :"CompositionClient.search_for_facet_values", |
| 142 | + :header_params => header_params, |
| 143 | + :query_params => query_params, |
| 144 | + :body => post_body, |
| 145 | + :use_read_transporter => true |
| 146 | + ) |
| 147 | + |
| 148 | + @api_client.call_api(:POST, path, new_options) |
| 149 | + end |
| 150 | + |
| 151 | + # Searches for values of a specified facet attribute on the composition's main source's index. - By default, facet values are sorted by decreasing count. You can adjust this with the `sortFacetValueBy` parameter. - Searching for facet values doesn't work if you have **more than 65 searchable facets and searchable attributes combined**. |
| 152 | + # |
| 153 | + # Required API Key ACLs: |
| 154 | + # - search |
| 155 | + # @param composition_id [String] Unique Composition ObjectID. (required) |
| 156 | + # @param facet_name [String] Facet attribute in which to search for values. This attribute must be included in the `attributesForFaceting` index setting with the `searchable()` modifier. (required) |
| 157 | + # @param search_for_facet_values_request [SearchForFacetValuesRequest] |
| 158 | + # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional) |
| 159 | + # @return [SearchForFacetValuesResponse] |
| 160 | + def search_for_facet_values(composition_id, facet_name, search_for_facet_values_request = nil, request_options = {}) |
| 161 | + response = search_for_facet_values_with_http_info( |
| 162 | + composition_id, |
| 163 | + facet_name, |
| 164 | + search_for_facet_values_request, |
| 165 | + request_options |
| 166 | + ) |
| 167 | + @api_client.deserialize( |
| 168 | + response.body, |
| 169 | + request_options[:debug_return_type] || "Composition::SearchForFacetValuesResponse" |
| 170 | + ) |
| 171 | + end |
| 172 | + |
| 173 | + end |
| 174 | +end |
0 commit comments