Skip to content

Commit 3f47805

Browse files
algolia-bote-krebsshortcutsmillotp
committed
feat(specs): rename composition to composition-full (private) and add composition (public) (generated)
algolia/api-clients-automation#4357 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Emmanuel Krebs <[email protected]> Co-authored-by: shortcuts <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent a1294fd commit 3f47805

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+14911
-0
lines changed

lib/Api/CompositionClient.php

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
<?php
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+
namespace Algolia\AlgoliaSearch\Api;
6+
7+
use Algolia\AlgoliaSearch\Algolia;
8+
use Algolia\AlgoliaSearch\Configuration\CompositionConfig;
9+
use Algolia\AlgoliaSearch\Model\Composition\RequestBody;
10+
use Algolia\AlgoliaSearch\Model\Composition\SearchForFacetValuesRequest;
11+
use Algolia\AlgoliaSearch\ObjectSerializer;
12+
use Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper;
13+
use Algolia\AlgoliaSearch\RetryStrategy\ApiWrapperInterface;
14+
use Algolia\AlgoliaSearch\RetryStrategy\ClusterHosts;
15+
use GuzzleHttp\Psr7\Query;
16+
17+
/**
18+
* CompositionClient Class Doc Comment.
19+
*
20+
* @category Class
21+
*/
22+
class CompositionClient
23+
{
24+
public const VERSION = '4.12.0';
25+
26+
/**
27+
* @var ApiWrapperInterface
28+
*/
29+
protected $api;
30+
31+
/**
32+
* @var CompositionConfig
33+
*/
34+
protected $config;
35+
36+
public function __construct(ApiWrapperInterface $apiWrapper, CompositionConfig $config)
37+
{
38+
$this->config = $config;
39+
$this->api = $apiWrapper;
40+
}
41+
42+
/**
43+
* Instantiate the client with basic credentials.
44+
*
45+
* @param string $appId Application ID
46+
* @param string $apiKey Algolia API Key
47+
*/
48+
public static function create($appId = null, $apiKey = null)
49+
{
50+
return static::createWithConfig(CompositionConfig::create($appId, $apiKey));
51+
}
52+
53+
/**
54+
* Instantiate the client with configuration.
55+
*
56+
* @param CompositionConfig $config Configuration
57+
*/
58+
public static function createWithConfig(CompositionConfig $config)
59+
{
60+
$config = clone $config;
61+
62+
$apiWrapper = new ApiWrapper(
63+
Algolia::getHttpClient(),
64+
$config,
65+
self::getClusterHosts($config)
66+
);
67+
68+
return new static($apiWrapper, $config);
69+
}
70+
71+
/**
72+
* Gets the cluster hosts depending on the config.
73+
*
74+
* @return ClusterHosts
75+
*/
76+
public static function getClusterHosts(CompositionConfig $config)
77+
{
78+
$cacheKey = sprintf('%s-clusterHosts-%s', __CLASS__, $config->getAppId());
79+
80+
if ($hosts = $config->getHosts()) {
81+
// If a list of hosts was passed, we ignore the cache
82+
$clusterHosts = ClusterHosts::create($hosts);
83+
} elseif (false === ($clusterHosts = ClusterHosts::createFromCache($cacheKey))) {
84+
// We'll try to restore the ClusterHost from cache, if we cannot
85+
// we create a new instance and set the cache key
86+
$clusterHosts = ClusterHosts::createFromAppId($config->getAppId())
87+
->setCacheKey($cacheKey)
88+
;
89+
}
90+
91+
return $clusterHosts;
92+
}
93+
94+
/**
95+
* @return CompositionConfig
96+
*/
97+
public function getClientConfig()
98+
{
99+
return $this->config;
100+
}
101+
102+
/**
103+
* Stub method setting a new API key to authenticate requests.
104+
*
105+
* @param string $apiKey
106+
*/
107+
public function setClientApiKey($apiKey)
108+
{
109+
$this->config->setClientApiKey($apiKey);
110+
}
111+
112+
/**
113+
* Runs a query on a single composition and returns matching results.
114+
*
115+
* Required API Key ACLs:
116+
* - search
117+
*
118+
* @param string $compositionID Unique Composition ObjectID. (required)
119+
* @param array $requestBody requestBody (required)
120+
* - $requestBody['params'] => (array)
121+
*
122+
* @see RequestBody
123+
*
124+
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
125+
*
126+
* @return \Algolia\AlgoliaSearch\Model\Composition\SearchResponse|array<string, mixed>
127+
*/
128+
public function search($compositionID, $requestBody, $requestOptions = [])
129+
{
130+
// verify the required parameter 'compositionID' is set
131+
if (!isset($compositionID)) {
132+
throw new \InvalidArgumentException(
133+
'Parameter `compositionID` is required when calling `search`.'
134+
);
135+
}
136+
// verify the required parameter 'requestBody' is set
137+
if (!isset($requestBody)) {
138+
throw new \InvalidArgumentException(
139+
'Parameter `requestBody` is required when calling `search`.'
140+
);
141+
}
142+
143+
$resourcePath = '/1/compositions/{compositionID}/run';
144+
$queryParameters = [];
145+
$headers = [];
146+
$httpBody = $requestBody;
147+
148+
// path params
149+
if (null !== $compositionID) {
150+
$resourcePath = str_replace(
151+
'{compositionID}',
152+
ObjectSerializer::toPathValue($compositionID),
153+
$resourcePath
154+
);
155+
}
156+
157+
return $this->sendRequest('POST', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions, true);
158+
}
159+
160+
/**
161+
* 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**.
162+
*
163+
* Required API Key ACLs:
164+
* - search
165+
*
166+
* @param string $compositionID Unique Composition ObjectID. (required)
167+
* @param string $facetName Facet attribute in which to search for values. This attribute must be included in the `attributesForFaceting` index setting with the `searchable()` modifier. (required)
168+
* @param array $searchForFacetValuesRequest searchForFacetValuesRequest (optional)
169+
* - $searchForFacetValuesRequest['params'] => (array)
170+
*
171+
* @see SearchForFacetValuesRequest
172+
*
173+
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
174+
*
175+
* @return \Algolia\AlgoliaSearch\Model\Composition\SearchForFacetValuesResponse|array<string, mixed>
176+
*/
177+
public function searchForFacetValues($compositionID, $facetName, $searchForFacetValuesRequest = null, $requestOptions = [])
178+
{
179+
// verify the required parameter 'compositionID' is set
180+
if (!isset($compositionID)) {
181+
throw new \InvalidArgumentException(
182+
'Parameter `compositionID` is required when calling `searchForFacetValues`.'
183+
);
184+
}
185+
// verify the required parameter 'facetName' is set
186+
if (!isset($facetName)) {
187+
throw new \InvalidArgumentException(
188+
'Parameter `facetName` is required when calling `searchForFacetValues`.'
189+
);
190+
}
191+
192+
$resourcePath = '/1/compositions/{compositionID}/facets/{facetName}/query';
193+
$queryParameters = [];
194+
$headers = [];
195+
$httpBody = isset($searchForFacetValuesRequest) ? $searchForFacetValuesRequest : [];
196+
197+
// path params
198+
if (null !== $compositionID) {
199+
$resourcePath = str_replace(
200+
'{compositionID}',
201+
ObjectSerializer::toPathValue($compositionID),
202+
$resourcePath
203+
);
204+
}
205+
206+
// path params
207+
if (null !== $facetName) {
208+
$resourcePath = str_replace(
209+
'{facetName}',
210+
ObjectSerializer::toPathValue($facetName),
211+
$resourcePath
212+
);
213+
}
214+
215+
return $this->sendRequest('POST', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions, true);
216+
}
217+
218+
private function sendRequest($method, $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions, $useReadTransporter = false)
219+
{
220+
if (!isset($requestOptions['headers'])) {
221+
$requestOptions['headers'] = [];
222+
}
223+
if (!isset($requestOptions['queryParameters'])) {
224+
$requestOptions['queryParameters'] = [];
225+
}
226+
227+
$requestOptions['headers'] = array_merge($headers, $requestOptions['headers']);
228+
$requestOptions['queryParameters'] = array_merge($queryParameters, $requestOptions['queryParameters']);
229+
$query = Query::build($requestOptions['queryParameters']);
230+
231+
return $this->api->sendRequest(
232+
$method,
233+
$resourcePath.($query ? "?{$query}" : ''),
234+
$httpBody,
235+
$requestOptions,
236+
$useReadTransporter
237+
);
238+
}
239+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
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+
namespace Algolia\AlgoliaSearch\Configuration;
6+
7+
class CompositionConfig extends Configuration
8+
{
9+
protected $clientName = 'Composition';
10+
11+
public function getDefaultConfiguration()
12+
{
13+
return [
14+
'appId' => '',
15+
'apiKey' => '',
16+
'hosts' => null,
17+
'hasFullHosts' => false,
18+
'readTimeout' => 5,
19+
'writeTimeout' => 30,
20+
'connectTimeout' => 2,
21+
'defaultHeaders' => [],
22+
];
23+
}
24+
}

0 commit comments

Comments
 (0)