Skip to content

Commit e9ece43

Browse files
committed
IMP: Make wordpress httpclient an abstract class
1 parent 96b0599 commit e9ece43

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

Model/HttpClient/Page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class Page extends Wordpress
1010
{
11-
const WP_JSON_URL_SUFFIX = 'pages';
11+
public $type = 'pages';
1212

1313
public function postMetaDataToPage(int $pageId, string $key, string $value, string $authentication)
1414
{

Model/HttpClient/Wordpress.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
use Symfony\Component\HttpClient\HttpClient;
99
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
1010

11-
class Wordpress
11+
abstract class Wordpress
1212
{
1313
const WP_JSON_URL_PREFIX = '/wp-json/wp/v2/';
14-
public const WP_JSON_URL_SUFFIX = '';
14+
15+
public $type = '';
1516

1617
/**
1718
* @var \Symfony\Contracts\HttpClient\HttpClientInterface
@@ -65,7 +66,7 @@ public function all(int $pageSize = 10, array $filters = []): \Generator
6566
$response = $this->client->request(
6667
'GET',
6768
static::WP_JSON_URL_PREFIX .
68-
static::WP_JSON_URL_SUFFIX .
69+
$this->type .
6970
'?' .
7071
http_build_query(
7172
array_merge([
@@ -94,7 +95,7 @@ public function all(int $pageSize = 10, array $filters = []): \Generator
9495
*/
9596
public function get(int $id): array
9697
{
97-
$response = $this->client->request('GET', static::WP_JSON_URL_PREFIX . static::WP_JSON_URL_SUFFIX . '/' . $id);
98+
$response = $this->client->request('GET', static::WP_JSON_URL_PREFIX . $this->type . '/' . $id);
9899

99100
return json_decode($response->getContent(), true);
100101
}
@@ -104,7 +105,7 @@ public function postMetaDataToPage(int $pageId, string $key, string $value, stri
104105
try {
105106
$response = $this->client->request(
106107
'POST',
107-
static::WP_JSON_URL_PREFIX . static::WP_JSON_URL_SUFFIX . '/' . $pageId . '?' . $key . '=' . $value,
108+
static::WP_JSON_URL_PREFIX . $this->type . '/' . $pageId . '?' . $key . '=' . $value,
108109

109110
[
110111
'auth_basic' => $authentication
@@ -127,7 +128,7 @@ public function postMetaDataToPage(int $pageId, string $key, string $value, stri
127128
*/
128129
public function peek(int $pageSize): array
129130
{
130-
$peekResponse = $this->client->request('HEAD', static::WP_JSON_URL_PREFIX . static::WP_JSON_URL_SUFFIX . '?per_page=' . $pageSize);
131+
$peekResponse = $this->client->request('HEAD', static::WP_JSON_URL_PREFIX . $this->type . '?per_page=' . $pageSize);
131132

132133
return $peekResponse->getHeaders();
133134
}

0 commit comments

Comments
 (0)