Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate and stop using magic call method on ApiClient #362

Merged
merged 1 commit into from
Sep 18, 2019
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
17 changes: 14 additions & 3 deletions src/API/Helpers/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public function __construct($config)
}
}

/**
* Magic method to map HTTP verbs to request types.
*
* @deprecated 5.6.0, use $this->method().
*
* @param string $name - Method name used to call the magic method.
* @param array $arguments - Arguments used in the magic method call.
*
* @return RequestBuilder
*/
public function __call($name, $arguments)
{
$builder = new RequestBuilder([
Expand All @@ -81,11 +91,12 @@ public function __call($name, $arguments)
* Create a new RequestBuilder.
* Similar to the above but does not use a magic method.
*
* @param string $method - HTTP method to use (GET, POST, PATCH, etc).
* @param string $method - HTTP method to use (GET, POST, PATCH, etc).
* @param boolean $set_content_type - Automatically set a content-type header.
*
* @return RequestBuilder
*/
public function method($method)
public function method($method, $set_content_type = true)
{
$method = strtolower($method);
$builder = new RequestBuilder([
Expand All @@ -97,7 +108,7 @@ public function method($method)
]);
$builder->withHeaders($this->headers);

if (in_array($method, [ 'patch', 'post', 'put', 'delete' ])) {
if ($set_content_type && in_array($method, [ 'patch', 'post', 'put' ])) {
$builder->withHeader(new ContentType('application/json'));
}

Expand Down
15 changes: 6 additions & 9 deletions src/API/Management/Blacklists.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Auth0\SDK\API\Management;

use Auth0\SDK\API\Header\ContentType;

class Blacklists extends GenericResource
{
/**
Expand All @@ -13,9 +11,9 @@ class Blacklists extends GenericResource
*/
public function getAll($aud)
{
return $this->apiClient->get()
->blacklists()
->tokens()
return $this->apiClient->method('get')
->addPath('blacklists')
->addPath('tokens')
->withParam('aud', $aud)
->call();
}
Expand All @@ -28,10 +26,9 @@ public function getAll($aud)
*/
public function blacklist($aud, $jti)
{
return $this->apiClient->post()
->blacklists()
->tokens()
->withHeader(new ContentType('application/json'))
return $this->apiClient->method('post')
->addPath('blacklists')
->addPath('tokens')
->withBody(json_encode([
'aud' => $aud,
'jti' => $jti
Expand Down
2 changes: 1 addition & 1 deletion src/API/Management/ClientGrants.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function update($id, array $scope)
*/
public function get($id, $audience = null)
{
$request = $this->apiClient->get()
$request = $this->apiClient->method('get')
->addPath('client-grants');

if ($audience !== null) {
Expand Down
9 changes: 3 additions & 6 deletions src/API/Management/DeviceCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Auth0\SDK\API\Management;

use Auth0\SDK\API\Header\ContentType;

class DeviceCredentials extends GenericResource
{
const TYPE_PUBLIC_KEY = 'public_key';
Expand All @@ -20,7 +18,7 @@ class DeviceCredentials extends GenericResource
*/
public function getAll($user_id = null, $client_id = null, $type = null, $fields = null, $include_fields = null)
{
$request = $this->apiClient->get()
$request = $this->apiClient->method('get')
->addPath('device-credentials');

if ($fields !== null) {
Expand Down Expand Up @@ -57,9 +55,8 @@ public function getAll($user_id = null, $client_id = null, $type = null, $fields
*/
public function createPublicKey($data)
{
return $this->apiClient->post()
return $this->apiClient->method('post')
->addPath('device-credentials')
->withHeader(new ContentType('application/json'))
->withBody(json_encode($data))
->call();
}
Expand All @@ -71,7 +68,7 @@ public function createPublicKey($data)
*/
public function deleteDeviceCredential($id)
{
return $this->apiClient->delete()
return $this->apiClient->method('delete')
->addPath('device-credentials', $id)
->call();
}
Expand Down
28 changes: 12 additions & 16 deletions src/API/Management/Emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Auth0\SDK\API\Management;

use Auth0\SDK\API\Header\ContentType;

class Emails extends GenericResource
{
/**
Expand All @@ -14,9 +12,9 @@ class Emails extends GenericResource
*/
public function getEmailProvider($fields = null, $include_fields = null)
{
$request = $this->apiClient->get()
->emails()
->provider();
$request = $this->apiClient->method('get')
->addPath('emails')
->addPath('provider');

if ($fields !== null) {
if (is_array($fields)) {
Expand All @@ -40,10 +38,9 @@ public function getEmailProvider($fields = null, $include_fields = null)
*/
public function configureEmailProvider($data)
{
return $this->apiClient->post()
->emails()
->provider()
->withHeader(new ContentType('application/json'))
return $this->apiClient->method('post')
->addPath('emails')
->addPath('provider')
->withBody(json_encode($data))
->call();
}
Expand All @@ -55,10 +52,9 @@ public function configureEmailProvider($data)
*/
public function updateEmailProvider($data)
{
return $this->apiClient->patch()
->emails()
->provider()
->withHeader(new ContentType('application/json'))
return $this->apiClient->method('patch')
->addPath('emails')
->addPath('provider')
->withBody(json_encode($data))
->call();
}
Expand All @@ -69,9 +65,9 @@ public function updateEmailProvider($data)
*/
public function deleteEmailProvider()
{
return $this->apiClient->delete()
->emails()
->provider()
return $this->apiClient->method('delete')
->addPath('emails')
->addPath('provider')
->call();
}
}
13 changes: 5 additions & 8 deletions src/API/Management/Jobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Auth0\SDK\API\Management;

use Auth0\SDK\API\Header\ContentType;

class Jobs extends GenericResource
{
/**
Expand Down Expand Up @@ -40,8 +38,8 @@ public function getErrors($id)
*/
public function importUsers($file_path, $connection_id, $params = [])
{
$request = $this->apiClient->post()
->jobs()
$request = $this->apiClient->method('post', false)
->addPath('jobs')
->addPath('users-imports')
->addFile('users', $file_path)
->addFormParam('connection_id', $connection_id);
Expand All @@ -54,7 +52,7 @@ public function importUsers($file_path, $connection_id, $params = [])
$request->addFormParam('send_completion_email', filter_var($params['send_completion_email'], FILTER_VALIDATE_BOOLEAN));
}

if (!empty($params['external_id'])) {
if (! empty($params['external_id'])) {
$request->addFormParam('external_id', $params['external_id']);
}

Expand All @@ -68,10 +66,9 @@ public function importUsers($file_path, $connection_id, $params = [])
*/
public function sendVerificationEmail($user_id)
{
return $this->apiClient->post()
->jobs()
return $this->apiClient->method('post')
->addPath('jobs')
->addPath('verification-email')
->withHeader(new ContentType('application/json'))
->withBody(json_encode([
'user_id' => $user_id
]))
Expand Down
10 changes: 5 additions & 5 deletions src/API/Management/Stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Stats extends GenericResource
*/
public function getActiveUsersCount()
{
return $this->apiClient->get()
->stats()
return $this->apiClient->method('get')
->addPath('stats')
->addPath('active-users')
->call();
}
Expand All @@ -24,9 +24,9 @@ public function getActiveUsersCount()
*/
public function getDailyStats($from, $to)
{
return $this->apiClient->get()
->stats()
->daily()
return $this->apiClient->method('get')
->addPath('stats')
->addPath('daily')
->withParam('from', $from)
->withParam('to', $to)
->call();
Expand Down
15 changes: 6 additions & 9 deletions src/API/Management/Tenants.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Auth0\SDK\API\Management;

use Auth0\SDK\API\Header\ContentType;

class Tenants extends GenericResource
{
/**
Expand All @@ -14,9 +12,9 @@ class Tenants extends GenericResource
*/
public function get($fields = null, $include_fields = null)
{
$request = $this->apiClient->get()
->tenants()
->settings();
$request = $this->apiClient->method('get')
->addPath('tenants')
->addPath('settings');

if ($fields !== null) {
if (is_array($fields)) {
Expand All @@ -40,10 +38,9 @@ public function get($fields = null, $include_fields = null)
*/
public function update($data)
{
return $this->apiClient->patch()
->tenants()
->settings()
->withHeader(new ContentType('application/json'))
return $this->apiClient->method('patch')
->addPath('tenants')
->addPath('settings')
->withBody(json_encode($data))
->call();
}
Expand Down
12 changes: 4 additions & 8 deletions src/API/Management/Tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Auth0\SDK\API\Management;

use Auth0\SDK\API\Header\ContentType;

class Tickets extends GenericResource
{
/**
Expand All @@ -19,10 +17,9 @@ public function createEmailVerificationTicket($user_id, $result_url = null)
$body['result_url'] = $result_url;
}

$request = $this->apiClient->post()
->tickets()
$request = $this->apiClient->method('post')
->addPath('tickets')
->addPath('email-verification')
->withHeader(new ContentType('application/json'))
->withBody(json_encode($body));

return $request->call();
Expand Down Expand Up @@ -103,10 +100,9 @@ public function createPasswordChangeTicketRaw(
$body['connection_id'] = $connection_id;
}

return $this->apiClient->post()
->tickets()
return $this->apiClient->method('post')
->addPath('tickets')
->addPath('password-change')
->withHeader(new ContentType('application/json'))
->withBody(json_encode($body))
->call();
}
Expand Down
8 changes: 4 additions & 4 deletions src/API/Management/UserBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class UserBlocks extends GenericResource
*/
public function get($user_id)
{
return $this->apiClient->get()
return $this->apiClient->method('get')
->addPath('user-blocks', $user_id)
->call();
}
Expand All @@ -23,7 +23,7 @@ public function get($user_id)
*/
public function getByIdentifier($identifier)
{
return $this->apiClient->get()
return $this->apiClient->method('get')
->addPath('user-blocks')
->withParam('identifier', $identifier)
->call();
Expand All @@ -36,7 +36,7 @@ public function getByIdentifier($identifier)
*/
public function unblock($user_id)
{
return $this->apiClient->delete()
return $this->apiClient->method('delete')
->addPath('user-blocks', $user_id)
->call();
}
Expand All @@ -48,7 +48,7 @@ public function unblock($user_id)
*/
public function unblockByIdentifier($identifier)
{
return $this->apiClient->delete()
return $this->apiClient->method('delete')
->addPath('user-blocks')
->withParam('identifier', $identifier)
->call();
Expand Down
2 changes: 1 addition & 1 deletion src/API/Management/UsersByEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class UsersByEmail extends GenericResource
{
public function get($params = [])
{
$client = $this->apiClient->get()
$client = $this->apiClient->method('get')
->addPath('users-by-email');

foreach ($params as $param => $value) {
Expand Down
2 changes: 0 additions & 2 deletions tests/API/Management/RolesMockedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ public function testThatDeleteRoleRequestIsFormattedProperly()

$headers = $api->getHistoryHeaders();
$this->assertEquals( 'Bearer __api_token__', $headers['Authorization'][0] );
$this->assertEquals( 'application/json', $headers['Content-Type'][0] );
$this->assertEquals( self::$expectedTelemetry, $headers['Auth0-Client'][0] );
}

Expand Down Expand Up @@ -490,7 +489,6 @@ public function testThatRemoveRolePermissionsRequestIsFormattedProperly()

$headers = $api->getHistoryHeaders();
$this->assertEquals( 'Bearer __api_token__', $headers['Authorization'][0] );
$this->assertEquals( 'application/json', $headers['Content-Type'][0] );
$this->assertEquals( self::$expectedTelemetry, $headers['Auth0-Client'][0] );

$body = $api->getHistoryBody();
Expand Down
Loading