-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoostsGet.php
More file actions
64 lines (62 loc) · 2.73 KB
/
BoostsGet.php
File metadata and controls
64 lines (62 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace Silverstripe\Search\Client\Endpoint;
class BoostsGet extends \Silverstripe\Search\Client\Runtime\Client\BaseEndpoint implements \Silverstripe\Search\Client\Runtime\Client\Endpoint
{
protected $field_name;
protected $engine_name;
/**
* Get all boosts for a field.
* @param string $fieldName Name of the field to get boosts for
* @param string $engineName
*/
public function __construct(string $fieldName, string $engineName)
{
$this->field_name = $fieldName;
$this->engine_name = $engineName;
}
use \Silverstripe\Search\Client\Runtime\Client\EndpointTrait;
public function getMethod(): string
{
return 'GET';
}
public function getUri(): string
{
return str_replace(['{field_name}', '{engine_name}'], [$this->field_name, $this->engine_name], '/{engine_name}/field/{field_name}/boosts');
}
public function getBody(\Symfony\Component\Serializer\SerializerInterface $serializer, $streamFactory = null): array
{
return [[], null];
}
public function getExtraHeaders(): array
{
return ['Accept' => ['application/json']];
}
/**
* {@inheritdoc}
*
* @throws \Silverstripe\Search\Client\Exception\BoostsGetNotFoundException
* @throws \Silverstripe\Search\Client\Exception\BoostsGetUnprocessableEntityException
* @throws \Silverstripe\Search\Client\Exception\UnexpectedStatusCodeException
*
* @return \Silverstripe\Search\Client\Model\BoostGetResponse[]
*/
protected function transformResponseBody(\Psr\Http\Message\ResponseInterface $response, \Symfony\Component\Serializer\SerializerInterface $serializer, ?string $contentType = null)
{
$status = $response->getStatusCode();
$body = (string) $response->getBody();
if (is_null($contentType) === false && (200 === $status && mb_strpos(strtolower($contentType), 'application/json') !== false)) {
return $serializer->deserialize($body, 'Silverstripe\Search\Client\Model\BoostGetResponse[]', 'json');
}
if (404 === $status) {
throw new \Silverstripe\Search\Client\Exception\BoostsGetNotFoundException($response);
}
if (is_null($contentType) === false && (422 === $status && mb_strpos(strtolower($contentType), 'application/json') !== false)) {
throw new \Silverstripe\Search\Client\Exception\BoostsGetUnprocessableEntityException($serializer->deserialize($body, 'Silverstripe\Search\Client\Model\HTTPValidationError', 'json'), $response);
}
throw new \Silverstripe\Search\Client\Exception\UnexpectedStatusCodeException($status, $body);
}
public function getAuthenticationScopes(): array
{
return ['HTTPBearer'];
}
}