Skip to content

Commit

Permalink
Merge pull request #74 from auth0/3.x.x-dev
Browse files Browse the repository at this point in the history
3.1.0
  • Loading branch information
glena committed Mar 10, 2016
2 parents ca3e22c + ed6aa11 commit 6c132ef
Show file tree
Hide file tree
Showing 24 changed files with 105 additions and 96 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ This is a common issue with latest PHP versions under windows (related to a inco
```
$token = "eyJhbGciO....eyJhdWQiOiI....1ZVDisdL...";
$domain = "account.auth0.com";
$guzzleOptions = [ ... ];
$auth0Api = new \Auth0\SDK\Auth0Api($token, $domain);
$auth0Api = new \Auth0\SDK\Auth0Api($token, $domain, $guzzleOptions); /* $guzzleOptions is optional */
$usersList = $auth0Api->users->search([ "q" => "email@test.com" ]);
```
Expand Down
8 changes: 1 addition & 7 deletions src/API/Blacklists.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
use Auth0\SDK\API\Helpers\ApiClient;
use Auth0\SDK\API\Header\ContentType;

class Blacklists {

protected $apiClient;

public function __construct(ApiClient $apiClient) {
$this->apiClient = $apiClient;
}
class Blacklists extends GenericResource {

public function getAll($aud) {

Expand Down
8 changes: 1 addition & 7 deletions src/API/Clients.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
use Auth0\SDK\API\Helpers\ApiClient;
use Auth0\SDK\API\Header\ContentType;

class Clients {

protected $apiClient;

public function __construct(ApiClient $apiClient) {
$this->apiClient = $apiClient;
}
class Clients extends GenericResource {

public function getAll($fields = null, $include_fields = null) {

Expand Down
8 changes: 1 addition & 7 deletions src/API/Connections.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
use Auth0\SDK\API\Helpers\ApiClient;
use Auth0\SDK\API\Header\ContentType;

class Connections {

protected $apiClient;

public function __construct(ApiClient $apiClient) {
$this->apiClient = $apiClient;
}
class Connections extends GenericResource {

public function getAll($strategy = null, $fields = null, $include_fields = null) {

Expand Down
8 changes: 1 addition & 7 deletions src/API/DeviceCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@
use Auth0\SDK\API\Helpers\ApiClient;
use Auth0\SDK\API\Header\ContentType;

class DeviceCredentials {
class DeviceCredentials extends GenericResource {

const TYPE_PUBLIC_KEY = 'public_key';
const TYPE_REFESH_TOKEN = 'refresh_token';

protected $apiClient;

public function __construct(ApiClient $apiClient) {
$this->apiClient = $apiClient;
}

public function getAll($user_id = null, $client_id = null, $type = null, $fields = null, $include_fields = null) {

$request = $this->apiClient->get()
Expand Down
8 changes: 1 addition & 7 deletions src/API/Emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
use Auth0\SDK\API\Helpers\ApiClient;
use Auth0\SDK\API\Header\ContentType;

class Emails {

protected $apiClient;

public function __construct(ApiClient $apiClient) {
$this->apiClient = $apiClient;
}
class Emails extends GenericResource {

public function getEmailProvider($fields = null, $include_fields = null) {

Expand Down
17 changes: 17 additions & 0 deletions src/API/GenericResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php namespace Auth0\SDK\API;

use Auth0\SDK\API\Helpers\ApiClient;

class GenericResource {

protected $apiClient;

public function __construct(ApiClient $apiClient) {
$this->apiClient = $apiClient;
}

public function getApiClient() {
return $this->apiClient;
}

}
7 changes: 5 additions & 2 deletions src/API/Helpers/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ public static function disableInfoHeaders(){
protected $domain;
protected $basePath;
protected $headers;
protected $guzzleOptions;

public function __construct($config) {
$this->basePath = $config['basePath'];
$this->domain = $config['domain'];
$this->headers = isset($config['headers']) ? $config['headers'] : array();
$this->headers = isset($config['headers']) ? $config['headers'] : [];
$this->guzzleOptions = isset($config['guzzleOptions']) ? $config['guzzleOptions'] : [];

if (self::$infoHeadersDataEnabled) {
$this->headers[] = new Header('Auth0-Client', self::getInfoHeadersData()->build());
Expand All @@ -56,8 +58,9 @@ public function __construct($config) {
public function __call($name, $arguments) {
$builder = new RequestBuilder(array(
'domain' => $this->domain,
'basePath' => $this->basePath,
'method' => $name,
'path' => array( $this->basePath ),
'guzzleOptions' => $this->guzzleOptions
));

return $builder->withHeaders($this->headers);
Expand Down
18 changes: 16 additions & 2 deletions src/API/Helpers/RequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@

class RequestBuilder {

protected $domain;
protected $basePath;

protected $path = [];
protected $method = [];
protected $headers = [];
protected $params = [];
protected $form_params = [];
protected $files = [];
protected $guzzleOptions = [];
protected $body;

public function __construct( $config ) {

$this->method = $config['method'];
$this->domain = $config['domain'];
$this->basePath = isset($config['basePath']) ? $config['basePath'] : '';
$this->guzzleOptions = isset($config['guzzleOptions']) ? $config['guzzleOptions'] : [];
$this->headers = isset($config['headers']) ? $config['headers'] : array();
if (array_key_exists('path', $config)) $this->path = $config['path'];

Expand Down Expand Up @@ -57,7 +63,7 @@ public function addPathVariable($variable) {
}

public function getUrl() {
return $this->domain . '/' . trim(implode('/',$this->path), '/') . $this->getParams();
return trim(implode('/',$this->path), '/') . $this->getParams();
}

public function getParams() {
Expand Down Expand Up @@ -96,8 +102,16 @@ public function addFormParam($key, $value) {
return $this;
}

public function getGuzzleOptions() {
return array_merge(
["base_uri" => $this->domain . $this->basePath],
$this->guzzleOptions
);
}

public function call() {
$client = new Client();

$client = new Client( $this->getGuzzleOptions() );

try {

Expand Down
8 changes: 1 addition & 7 deletions src/API/Jobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
use Auth0\SDK\API\Helpers\ApiClient;
use Auth0\SDK\API\Header\ContentType;

class Jobs {

protected $apiClient;

public function __construct(ApiClient $apiClient) {
$this->apiClient = $apiClient;
}
class Jobs extends GenericResource {

public function get($id) {

Expand Down
8 changes: 1 addition & 7 deletions src/API/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
use Auth0\SDK\API\Helpers\ApiClient;
use Auth0\SDK\API\Header\ContentType;

class Rules {

protected $apiClient;

public function __construct(ApiClient $apiClient) {
$this->apiClient = $apiClient;
}
class Rules extends GenericResource {

public function getAll($enabled = null, $fields = null, $include_fields = null) {

Expand Down
8 changes: 1 addition & 7 deletions src/API/Stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
use Auth0\SDK\API\Helpers\ApiClient;
use Auth0\SDK\API\Header\ContentType;

class Stats {

protected $apiClient;

public function __construct(ApiClient $apiClient) {
$this->apiClient = $apiClient;
}
class Stats extends GenericResource {

public function getActiveUsersCount() {

Expand Down
8 changes: 1 addition & 7 deletions src/API/Tenants.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
use Auth0\SDK\API\Helpers\ApiClient;
use Auth0\SDK\API\Header\ContentType;

class Tenants {

protected $apiClient;

public function __construct(ApiClient $apiClient) {
$this->apiClient = $apiClient;
}
class Tenants extends GenericResource {

public function get($fields = null, $include_fields = null) {

Expand Down
8 changes: 1 addition & 7 deletions src/API/Tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
use Auth0\SDK\API\Helpers\ApiClient;
use Auth0\SDK\API\Header\ContentType;

class Tickets {

protected $apiClient;

public function __construct(ApiClient $apiClient) {
$this->apiClient = $apiClient;
}
class Tickets extends GenericResource {

public function createEmailVerificationTicket($user_id, $result_url = null) {

Expand Down
8 changes: 1 addition & 7 deletions src/API/UserBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
use Auth0\SDK\API\Helpers\ApiClient;
use Auth0\SDK\API\Header\ContentType;

class UserBlocks {

protected $apiClient;

public function __construct(ApiClient $apiClient) {
$this->apiClient = $apiClient;
}
class UserBlocks extends GenericResource {

public function get($user_id) {

Expand Down
8 changes: 1 addition & 7 deletions src/API/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
use Auth0\SDK\API\Helpers\ApiClient;
use Auth0\SDK\API\Header\ContentType;

class Users {

protected $apiClient;

public function __construct(ApiClient $apiClient) {
$this->apiClient = $apiClient;
}
class Users extends GenericResource {

public function get($user_id) {

Expand Down
7 changes: 5 additions & 2 deletions src/Auth0Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Auth0Api {
private $token;
private $domain;
private $apiClient;
private $guzzleOptions;

public $blacklists;
public $clients;
Expand All @@ -36,9 +37,10 @@ class Auth0Api {
public $userBlocks;
public $users;

public function __construct($token, $domain) {
public function __construct($token, $domain, $guzzleOptions = []) {
$this->token = $token;
$this->domain = $domain;
$this->guzzleOptions = $guzzleOptions;

$this->setApiClient();

Expand All @@ -61,7 +63,8 @@ protected function setApiClient() {

$client = new ApiClient([
'domain' => $apiDomain,
'basePath' => '/api/v2',
'basePath' => '/api/v2/',
'guzzleOptions' => $this->guzzleOptions,
'headers' => [
new AuthorizationBearer($this->token)
]
Expand Down
7 changes: 7 additions & 0 deletions tests/BasicCrudTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

abstract class BasicCrudTest extends ApiTests {

protected $domain;

protected abstract function getApiClient();
protected abstract function getCreateBody();
protected abstract function getUpdateBody();
Expand All @@ -19,6 +21,11 @@ public function testAll() {

$client = $this->getApiClient();

$options = $client->getApiClient()->get()->getGuzzleOptions();

$this->assertArrayHasKey('base_uri', $options);
$this->assertEquals("https://$this->domain/api/v2/", $options['base_uri']);

$created = $client->create($this->getCreateBody());

$all = $client->getAll();
Expand Down
2 changes: 2 additions & 0 deletions tests/BlacklistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public function testBlacklistAndGet() {
]
]);

$this->domain = $env['DOMAIN'];

$api = new Auth0Api($token, $env['DOMAIN']);

$aud = $env["GLOBAL_CLIENT_ID"];
Expand Down
2 changes: 2 additions & 0 deletions tests/ClientsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ protected function getApiClient() {
]
]);

$this->domain = $env['DOMAIN'];

$api = new Auth0Api($token, $env['DOMAIN']);

return $api->clients;
Expand Down
2 changes: 2 additions & 0 deletions tests/ConnectionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ protected function getApiClient() {
]
]);

$this->domain = $env['DOMAIN'];

$api = new Auth0Api($token, $env['DOMAIN']);

return $api->connections;
Expand Down
Loading

0 comments on commit 6c132ef

Please sign in to comment.