Skip to content

Commit

Permalink
varsitynewsnetwork#23 possibility of change prefix in endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
4n70w4 committed May 1, 2019
1 parent 504fc29 commit 8c03d5f
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Endpoint/Categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class Categories extends AbstractWpEndpoint
*/
protected function getEndpoint()
{
return '/wp-json/wp/v2/categories';
return '/wp/v2/categories';
}
}
2 changes: 1 addition & 1 deletion src/Endpoint/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class Comments extends AbstractWpEndpoint
*/
protected function getEndpoint()
{
return '/wp-json/wp/v2/comments';
return '/wp/v2/comments';
}
}
2 changes: 1 addition & 1 deletion src/Endpoint/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class Media extends AbstractWpEndpoint
*/
protected function getEndpoint()
{
return '/wp-json/wp/v2/media';
return '/wp/v2/media';
}
}
2 changes: 1 addition & 1 deletion src/Endpoint/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class Pages extends AbstractWpEndpoint
*/
protected function getEndpoint()
{
return '/wp-json/wp/v2/pages';
return '/wp/v2/pages';
}
}
2 changes: 1 addition & 1 deletion src/Endpoint/PostStatuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class PostStatuses extends AbstractWpEndpoint
*/
protected function getEndpoint()
{
return '/wp-json/wp/v2/statuses';
return '/wp/v2/statuses';
}
}
2 changes: 1 addition & 1 deletion src/Endpoint/PostTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class PostTypes extends AbstractWpEndpoint
*/
protected function getEndpoint()
{
return '/wp-json/wp/v2/types';
return '/wp/v2/types';
}
}
2 changes: 1 addition & 1 deletion src/Endpoint/Posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class Posts extends AbstractWpEndpoint
*/
protected function getEndpoint()
{
return '/wp-json/wp/v2/posts';
return '/wp/v2/posts';
}
}
2 changes: 1 addition & 1 deletion src/Endpoint/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class Tags extends AbstractWpEndpoint
*/
protected function getEndpoint()
{
return '/wp-json/wp/v2/tags';
return '/wp/v2/tags';
}
}
2 changes: 1 addition & 1 deletion src/Endpoint/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class Users extends AbstractWpEndpoint
*/
protected function getEndpoint()
{
return '/wp-json/wp/v2/users';
return '/wp/v2/users';
}
}
19 changes: 17 additions & 2 deletions src/WpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class WpClient
*/
private $wordpressUrl;

/**
* @var string
*/
private $restApiPrefix;

/**
* @var array
*/
Expand All @@ -49,11 +54,13 @@ class WpClient
* WpClient constructor.
* @param ClientInterface $httpClient
* @param string $wordpressUrl
* @param string $restApiPrefix
*/
public function __construct(ClientInterface $httpClient, $wordpressUrl = '')
public function __construct(ClientInterface $httpClient, $wordpressUrl = '', $restApiPrefix = 'wp-json')
{
$this->httpClient = $httpClient;
$this->wordpressUrl = $wordpressUrl;
$this->restApiPrefix = $restApiPrefix;
}

/**
Expand All @@ -64,6 +71,14 @@ public function setWordpressUrl($wordpressUrl)
$this->wordpressUrl = $wordpressUrl;
}

/**
* @param $restApiPrefix
*/
public function setRestApiPrefix($restApiPrefix)
{
$this->restApiPrefix = $restApiPrefix;
}

/**
* @param AuthInterface $auth
*/
Expand Down Expand Up @@ -102,7 +117,7 @@ public function send(RequestInterface $request)
}

$request = $request->withUri(
$this->httpClient->makeUri($this->wordpressUrl . $request->getUri())
$this->httpClient->makeUri($this->wordpressUrl . "/{$this->restApiPrefix}" . $request->getUri())
);

return $this->httpClient->send($request);
Expand Down

0 comments on commit 8c03d5f

Please sign in to comment.