-
Notifications
You must be signed in to change notification settings - Fork 44
/
AdminActionService.php
31 lines (26 loc) · 1.03 KB
/
AdminActionService.php
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
<?php declare(strict_types=1);
namespace Vin\ShopwareSdk\Service;
/**
* This class is used for calling admin _action apis that are not defined by the SDK yet
*
* Class AdminActionService
* @package Vin\ShopwareSdk\Service
*/
class AdminActionService extends ApiService
{
/**
* @param array|string|resource $data
*/
public function execute(string $method, string $path, $data, array $headers = []): ApiResponse
{
if (!in_array(strtolower($method), ['get', 'post', 'put', 'patch', 'delete'])) {
throw new \InvalidArgumentException('Method ' . $method . ' is not supported');
}
$response = $this->httpClient->$method($this->getFullUrl($path), [
'body' => is_array($data) ? json_encode($data) : $data,
'headers' => $this->getBasicHeaders($headers)
]);
$contents = self::handleResponse($response->getBody()->getContents(), $response->getHeaders());
return new ApiResponse($contents, $response->getHeaders(), $response->getStatusCode());
}
}