mirror of
https://github.com/anikeen-com/id.git
synced 2026-11-06 23:58:35 +00:00
Send extra request headers and throw PreconditionFailedException on 412
This commit is contained in:
5 files changed
+164
-18
No files matched your search
+12
-10
@@ -369,10 +369,12 @@ class AnikeenId
|
||||
/**
|
||||
* Build query & execute.
|
||||
*
|
||||
* @param array<string, string> $headers Extra request headers, e.g. `If-Match` for conditional
|
||||
* writes; they are sent in addition to (and may not replace) Client-ID, Accept and Authorization.
|
||||
* @throws GuzzleException
|
||||
* @throws RequestRequiresClientIdException
|
||||
*/
|
||||
public function request(string $method, string $path, null|array $payload = null, array $parameters = [], ?Paginator $paginator = null, bool $useClientSecret = false): Result
|
||||
public function request(string $method, string $path, null|array $payload = null, array $parameters = [], ?Paginator $paginator = null, bool $useClientSecret = false, array $headers = []): Result
|
||||
{
|
||||
if ($paginator !== null) {
|
||||
$parameters[$paginator->action] = $paginator->cursor();
|
||||
@@ -380,7 +382,7 @@ class AnikeenId
|
||||
|
||||
try {
|
||||
$response = $this->client->request($method, $path, [
|
||||
'headers' => $this->buildHeaders((bool)$payload, $useClientSecret),
|
||||
'headers' => $this->buildHeaders((bool)$payload, $useClientSecret) + $headers,
|
||||
'query' => Query::build($parameters),
|
||||
'json' => $payload ?: null,
|
||||
]);
|
||||
@@ -419,35 +421,35 @@ class AnikeenId
|
||||
* @throws GuzzleException
|
||||
* @throws RequestRequiresClientIdException
|
||||
*/
|
||||
public function get(string $path, array $parameters = [], ?Paginator $paginator = null): Result
|
||||
public function get(string $path, array $parameters = [], ?Paginator $paginator = null, array $headers = []): Result
|
||||
{
|
||||
return $this->request('GET', $path, null, $parameters, $paginator);
|
||||
return $this->request('GET', $path, null, $parameters, $paginator, false, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws GuzzleException
|
||||
* @throws RequestRequiresClientIdException
|
||||
*/
|
||||
public function post(string $path, array $payload = [], array $parameters = [], ?Paginator $paginator = null): Result
|
||||
public function post(string $path, array $payload = [], array $parameters = [], ?Paginator $paginator = null, array $headers = []): Result
|
||||
{
|
||||
return $this->request('POST', $path, $payload, $parameters, $paginator);
|
||||
return $this->request('POST', $path, $payload, $parameters, $paginator, false, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws GuzzleException
|
||||
* @throws RequestRequiresClientIdException
|
||||
*/
|
||||
public function put(string $path, array $payload = [], array $parameters = [], ?Paginator $paginator = null): Result
|
||||
public function put(string $path, array $payload = [], array $parameters = [], ?Paginator $paginator = null, array $headers = []): Result
|
||||
{
|
||||
return $this->request('PUT', $path, $payload, $parameters, $paginator);
|
||||
return $this->request('PUT', $path, $payload, $parameters, $paginator, false, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws GuzzleException
|
||||
* @throws RequestRequiresClientIdException
|
||||
*/
|
||||
public function delete(string $path, array $payload = [], array $parameters = [], ?Paginator $paginator = null): Result
|
||||
public function delete(string $path, array $payload = [], array $parameters = [], ?Paginator $paginator = null, array $headers = []): Result
|
||||
{
|
||||
return $this->request('DELETE', $path, $payload, $parameters, $paginator);
|
||||
return $this->request('DELETE', $path, $payload, $parameters, $paginator, false, $headers);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user