Skip to content

Commit

Permalink
Merge 7e4b106 into 82bf3e8
Browse files Browse the repository at this point in the history
  • Loading branch information
WouterToering committed Nov 7, 2019
2 parents 82bf3e8 + 7e4b106 commit 85c4b91
Show file tree
Hide file tree
Showing 17 changed files with 391 additions and 645 deletions.
71 changes: 48 additions & 23 deletions sample/sample.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

require_once('vendor/autoload.php');

use Bynder\Api\BynderClient;
use Bynder\Api\Impl\OAuth2\Configuration;
use Bynder\Api\Impl\OAuth2;
use Bynder\Api\Impl\PermanentTokens;

define('BYNDER_INTEGRATION_ID', '');

$bynderDomain = 'portal.bynder.com';
// When using OAuth2

$bynderDomain = 'portal.getbynder.com';
$redirectUri = '';
$clientId = '';
$clientSecret = '';
Expand All @@ -21,33 +23,56 @@
]);
*/

try {
$bynder = new BynderClient(new Configuration(
$bynderDomain,
$redirectUri,
$clientId,
$clientSecret,
$token,
['timeout' => 5] // Guzzle HTTP request options
));
$bynder = new BynderClient(new Oauth2\Configuration(
$bynderDomain,
$redirectUri,
$clientId,
$clientSecret,
$token,
['timeout' => 5] // Guzzle HTTP request options
));

if($token === null) {
echo $bynder->getAuthorizationUrl([
'offline',
'current.user:read',
'current.profile:read',
'asset:read',
'asset:write',
'meta.assetbank:read',
'asset.usage:read',
'asset.usage:write',
]) . "\n\n";

$code = readline('Enter code: ');

if($code == null) {
exit;
}

if($token === null) {
echo $bynder->getAuthorizationUrl(['offline asset:read collection:read admin.user:read current.user:read current.profile:read meta.assetbank:read']) . "\n\n";
$token = $bynder->getAccessToken($code);
var_dump($token);
}

$code = readline('Enter code: ');
// When using permanent tokens

if($code == null) {
exit;
}
$bynderDomain = 'portal.getbynder.com';
$token = '';

$token = $bynder->getAccessToken($code);
}
$configuration = new PermanentTokens\Configuration(
$bynderDomain,
$token,
['timeout' => 5] // Guzzle HTTP request options
);

var_dump($token);
$bynder = new BynderClient($configuration);

// Example calls

try {
$currentUser = $bynder->getCurrentUser()->wait();
$user = $bynder->getUser($currentUser['id'])->wait();
var_dump($user);
var_dump($currentUser);

if(isset($currentUser['profileId'])) {
$roles = $bynder->getSecurityProfile($currentUser['profileId'])->wait();
}
Expand Down
13 changes: 10 additions & 3 deletions src/Bynder/Api/BynderClient.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace Bynder\Api;

use Bynder\Api\Impl\AssetBankManager;
use Bynder\Api\Impl\OAuth2;
use Bynder\Api\Impl\PermanentTokens;

class BynderClient
{

/**
* @var RequestHandler used to process API requests.
*/
Expand All @@ -19,8 +19,15 @@ class BynderClient

public function __construct($configuration)
{
if ($configuration instanceof PermanentTokens\Configuration) {
$this->requestHandler = new PermanentTokens\RequestHandler($configuration);
} else if($configuration instanceof OAuth2\Configuration) {
$this->requestHandler = new OAuth2\RequestHandler($configuration);
} else {
throw new \Exception('Invalid configuration passed');
}

$this->configuration = $configuration;
$this->requestHandler = new RequestHandler($configuration);
}

/**
Expand Down

0 comments on commit 85c4b91

Please sign in to comment.