-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoostGet.php
More file actions
67 lines (65 loc) · 2.88 KB
/
BoostGet.php
File metadata and controls
67 lines (65 loc) · 2.88 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
65
66
67
<?php
namespace Silverstripe\Search\Client\Endpoint;
class BoostGet extends \Silverstripe\Search\Client\Runtime\Client\BaseEndpoint implements \Silverstripe\Search\Client\Runtime\Client\Endpoint
{
protected $field_name;
protected $boost_id;
protected $engine_name;
/**
* Get a specific boost by its ID.
* @param string $fieldName Name of the field
* @param string $boostId ID of the boost to retrieve
* @param string $engineName
*/
public function __construct(string $fieldName, string $boostId, string $engineName)
{
$this->field_name = $fieldName;
$this->boost_id = $boostId;
$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}', '{boost_id}', '{engine_name}'], [$this->field_name, $this->boost_id, $this->engine_name], '/{engine_name}/field/{field_name}/boosts/{boost_id}');
}
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\BoostGetNotFoundException
* @throws \Silverstripe\Search\Client\Exception\BoostGetUnprocessableEntityException
* @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\BoostGetNotFoundException($response);
}
if (is_null($contentType) === false && (422 === $status && mb_strpos(strtolower($contentType), 'application/json') !== false)) {
throw new \Silverstripe\Search\Client\Exception\BoostGetUnprocessableEntityException($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'];
}
}