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

Add Sandbox option #137

Merged
merged 4 commits into from
Jul 19, 2016
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
2 changes: 1 addition & 1 deletion examples/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Uphold\UpholdClient as Client;

// Initialize the client.
$client = new Client();
$client = new Client(array('sandbox' => true));

// Get user.
$user = $client->getUser('AUTHORIZATION_TOKEN');
Expand Down
2 changes: 1 addition & 1 deletion examples/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Uphold\UpholdClient as Client;

// Initialize the client.
$client = new Client();
$client = new Client(array('sandbox' => true));

// Get user.
$user = $client->getUser('AUTHORIZATION_TOKEN');
Expand Down
2 changes: 1 addition & 1 deletion examples/Reserve.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use \Uphold\UpholdClient as Client;

// Initialize the client.
$client = new Client();
$client = new Client(array('sandbox' => true));

// Get the reserve summary of all the obligations and assets within it (public endpoint).
$statistics = $client->getReserve()->getStatistics();
Expand Down
2 changes: 1 addition & 1 deletion examples/Ticker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Uphold\UpholdClient as Client;

// Initialize the client.
$client = new Client();
$client = new Client(array('sandbox' => true));

// Get rates (public endpoint).
$rates = $client->getRates();
Expand Down
2 changes: 1 addition & 1 deletion examples/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Uphold\UpholdClient as Client;

// Initialize the client.
$client = new Client();
$client = new Client(array('sandbox' => true));

// Get user.
$user = $client->getUser('AUTHORIZATION_TOKEN');
Expand Down
2 changes: 1 addition & 1 deletion examples/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Uphold\UpholdClient as Client;

// Initialize the client.
$client = new Client();
$client = new Client(array('sandbox' => true));

// Get user.
$user = $client->getUser('AUTHORIZATION_TOKEN');
Expand Down
23 changes: 16 additions & 7 deletions lib/Uphold/Command/CreateTokenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

namespace Uphold\Command;

use Uphold\UpholdClient;
use Uphold\Exception\AuthenticationRequiredException;
use Uphold\Exception\BadRequestException;
use Uphold\Exception\TwoFactorAuthenticationRequiredException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;
use Uphold\Exception\AuthenticationRequiredException;
use Uphold\Exception\BadRequestException;
use Uphold\Exception\TwoFactorAuthenticationRequiredException;
use Uphold\UpholdClient;

/**
* Command to create a new Personal Access Token
Expand All @@ -22,8 +23,16 @@ class CreateTokenCommand extends Command
*/
protected function configure()
{
$this->setName('tokens:create')
->setDescription('Create a new Personal Access Token');
$this
->setName('tokens:create')
->setDescription('Create a new Personal Access Token')
->addOption(
'sandbox',
null,
InputOption::VALUE_NONE,
'If set, the request will be made to Uphold\'s sandbox API'
)
;
}

/**
Expand All @@ -40,7 +49,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
$this->output = $output;

// Uphold client.
$this->client = new UpholdClient();
$this->client = new UpholdClient(array('sandbox' => $input->getOption('sandbox')));

// Input variables.
$this->description = null;
Expand Down
12 changes: 11 additions & 1 deletion lib/Uphold/UpholdClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
*/
class UpholdClient
{
/**
* Uphold API urls.
*/
const UPHOLD_API_URL = 'https://api.uphold.com';
const UPHOLD_SANDBOX_API_URL = 'https://api-sandbox.uphold.com';

/**
* Guzzle instance used to communicate with Uphold.
*
Expand All @@ -36,8 +42,8 @@ class UpholdClient
*/
private $options = array(
'api_version' => 'v0',
'base_url' => 'https://api.uphold.com/',
'debug' => false,
'sandbox' => false,
'timeout' => 10,
'user_agent' => 'uphold-sdk-php {version} (https://github.com/seegno/uphold-sdk-php)',
'version' => '4.2.0',
Expand All @@ -50,6 +56,10 @@ class UpholdClient
*/
public function __construct(array $options = array())
{
if (!isset($options['base_url'])) {
$options['base_url'] = isset($options['sandbox']) && $options['sandbox'] ? self::UPHOLD_SANDBOX_API_URL : self::UPHOLD_API_URL;
}

$this->options = array_merge($this->options, $options);

$this->setHttpClient(new HttpClient($this->options));
Expand Down
2 changes: 1 addition & 1 deletion test/Uphold/Tests/Functional/ReserveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function shouldReturnTransactions()
*/
public function shouldReturnOneTransactions()
{
$exampleTransactionId = '66fc2a0d-a933-45f0-ba27-8cf12870fcce';
$exampleTransactionId = 'af3ef9a7-9262-4022-b376-7b4d928f7206';

$transaction = $this->client->getReserve()->getTransactionById($exampleTransactionId);

Expand Down
2 changes: 1 addition & 1 deletion test/Uphold/Tests/Functional/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TestCase extends \PHPUnit_Framework_TestCase
*/
public function setUp()
{
$client = new UpholdClient();
$client = new UpholdClient(array('sandbox' => true));

$this->client = $client;
}
Expand Down