Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 107 additions & 29 deletions src/API/Management/ResourceServers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,150 @@

namespace Auth0\SDK\API\Management;

use Auth0\SDK\API\Header\ContentType;
use Auth0\SDK\Exception\CoreException;

/**
* Class ResourceServers.
* Handles requests to the Resource Servers endpoint of the v2 Management API.
*
* @package Auth0\SDK\API\Management
*/
class ResourceServers extends GenericResource
{
/**
* Get all Resource Servers, by page if desired.
* Required scope: "read:resource_servers"
*
* @param null|integer $page Page number to get, zero-based.
* @param null|integer $per_page Number of results to get, null to return the default number.
*
* @return mixed
*
* @throws \Exception Thrown by the HTTP client when there is a problem with the API call.
*
* @link https://auth0.com/docs/api/management/v2#!/Resource_Servers/get_resource_servers
*/
public function getAll()
public function getAll($page = null, $per_page = null)
{
return $this->apiClient->get()
->addPath('resource-servers')
->call();
$params = [];

// Pagination parameters.
if (null !== $page) {
$params['page'] = abs(intval($page));
}

if (null !== $per_page) {
$params['per_page'] = abs(intval($per_page));
}

return $this->apiClient->method('get')
->withDictParams($params)
->addPath('resource-servers')
->call();
}

/**
* Get a single Resource Server by ID or API identifier.
* Required scope: "read:resource_servers"
*
* @param string $id Resource Server ID or identifier to get.
*
* @param string $id
* @return mixed
*
* @throws CoreException Thrown if the id parameter is empty or is not a string.
* @throws \Exception Thrown by the HTTP client when there is a problem with the API call.
*
* @link https://auth0.com/docs/api/management/v2#!/Resource_Servers/get_resource_servers_by_id
*/
public function get($id)
{
return $this->apiClient->get()
->addPath('resource-servers', $id)
->call();
if (empty($id) || ! is_string($id)) {
throw new CoreException('Invalid "id" parameter.');
}

return $this->apiClient->method('get')
->addPath('resource-servers', $id)
->call();
}

/**
* Create a new Resource Server.
* Required scope: "create:resource_servers"
*
* @param string $identifier API identifier to use.
* @param array $data Additional fields to add.
*
* @param string $client_id
* @param array $data
* @return mixed
*
* @throws CoreException Thrown if the identifier parameter or data field is empty or is not a string.
* @throws \Exception Thrown by the HTTP client when there is a problem with the API call.
*
* @link https://auth0.com/docs/api/management/v2#!/Resource_Servers/post_resource_servers
*/
public function create($client_id, $data)
public function create($identifier, array $data)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better param name, not breaking

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$client_id was never used before ? 😆 Backwards compatibility seems fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, param was there but not used anywhere in the method 🤷‍♂️

{
return $this->apiClient->post()
->addPath('resource-servers')
->withHeader(new ContentType('application/json'))
->withBody(json_encode($data))
->call();
// Backwards-compatibility with previously-unused $identifier parameter.
if (empty($data['identifier'])) {
$data['identifier'] = $identifier;
}

if (empty($data['identifier']) || ! is_string($data['identifier'])) {
throw new CoreException('Invalid "identifier" field.');
}

return $this->apiClient->method('post')
->addPath('resource-servers')
->withBody(json_encode($data))
->call();
}

/**
* Delete a Resource Server by ID.
* Required scope: "delete:resource_servers"
*
* @param string $id Resource Server ID or identifier to delete.
*
* @param string $id
* @return mixed
*
* @throws CoreException Thrown if the id parameter is empty or is not a string.
* @throws \Exception Thrown by the HTTP client when there is a problem with the API call.
*
* @link https://auth0.com/docs/api/management/v2#!/Resource_Servers/delete_resource_servers_by_id
*/
public function delete($id)
{
return $this->apiClient->delete()
->addPath('resource-servers', $id)
->call();
if (empty($id) || ! is_string($id)) {
throw new CoreException('Invalid "id" parameter.');
}

return $this->apiClient->method('delete')
->addPath('resource-servers', $id)
->call();
}

/**
* Update a Resource Server by ID.
* Required scope: "update:resource_servers"
*
* @param string $id Resource Server ID or identifier to update.
* @param array $data Data to update.
*
* @param string $id
* @param array $data
* @return mixed
*
* @throws CoreException Thrown if the id parameter is empty or is not a string.
* @throws \Exception Thrown by the HTTP client when there is a problem with the API call.
*
* @link https://auth0.com/docs/api/management/v2#!/Resource_Servers/patch_resource_servers_by_id
*/
public function update($id, $data)
public function update($id, array $data)
{
return $this->apiClient->patch()
->addPath('resource-servers', $id)
->withHeader(new ContentType('application/json'))
->withBody(json_encode($data))
->call();
if (empty($id) || ! is_string($id)) {
throw new CoreException('Invalid "id" parameter.');
}

return $this->apiClient->method('patch')
->addPath('resource-servers', $id)
->withBody(json_encode($data))
->call();
}
}
Loading