-
Notifications
You must be signed in to change notification settings - Fork 24
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 reserve model #40
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b4a9dd6
Add reserve model
c950995
Add reserve model tests
8bb6536
Add reserve to bitreserve client
0ac4fd0
Change bitreserve client transactions methods
063c6fc
Add reserve example
607758e
Update readme with reserve examples
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
require_once 'vendor/autoload.php'; | ||
|
||
use \Bitreserve\BitreserveClient as Client; | ||
|
||
// Initialize the client. In this case, we don't need an | ||
// AUTHORIZATION_TOKEN because the Ticker endpoint is public. | ||
$client = new Client(); | ||
|
||
// Get the reserve summary of all the obligations and assets within it. | ||
$statistics = $client->getReserve()->getStatistics(); | ||
|
||
print_r($statistics); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Bitreserve\Model; | ||
|
||
use Bitreserve\BitreserveClient; | ||
|
||
/** | ||
* Reserve Model. | ||
*/ | ||
class Reserve extends BaseModel implements ReserveInterface | ||
{ | ||
/** | ||
* Constructor. | ||
* | ||
* @param BitreserveClient $client Bitreserve client | ||
*/ | ||
public function __construct(BitreserveClient $client) | ||
{ | ||
$this->client = $client;; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getStatistics() | ||
{ | ||
return $this->client->get('/reserve/statistics'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTransactionById($id) | ||
{ | ||
$data = $this->client->get(sprintf('/reserve/transactions/%s', $id)); | ||
|
||
return new Transaction($this->client, $data); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTransactions() | ||
{ | ||
$data = $this->client->get('/reserve/transactions'); | ||
|
||
return array_map(function($transaction) { | ||
return new Transaction($this->client, $transaction); | ||
}, $data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Bitreserve\Model; | ||
|
||
/** | ||
* ReserveInterface. | ||
*/ | ||
interface ReserveInterface | ||
{ | ||
/** | ||
* Return the public view of any transaction. | ||
* | ||
* @return Transaction The transaction identified by a given id. | ||
*/ | ||
public function getTransactionById($id); | ||
|
||
/** | ||
* Return the public view of all transactions from the beginning of time. | ||
* | ||
* @return array The list all public transactions. | ||
*/ | ||
public function getTransactions(); | ||
|
||
/** | ||
* Get the reserve summary of all the obligations and assets within it. | ||
* | ||
* @return array The list of each holdings in all available currencies. | ||
*/ | ||
public function getStatistics(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
namespace Bitreserve\Tests\Model; | ||
|
||
use Bitreserve\Model\Reserve; | ||
|
||
class ReserveTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldReturnInstanceOfReserve() | ||
{ | ||
$client = $this->getBitreserveClientMock(); | ||
|
||
$reserve = new Reserve($client); | ||
|
||
$this->assertInstanceOf('Bitreserve\BitreserveClient', $reserve->getClient()); | ||
$this->assertInstanceOf('Bitreserve\Model\Reserve', $reserve); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldReturnStatistics() | ||
{ | ||
$data = array('foo' => 'bar'); | ||
|
||
$client = $this->getBitreserveClientMock(); | ||
$client->expects($this->once()) | ||
->method('get') | ||
->with('/reserve/statistics') | ||
->will($this->returnValue($data)); | ||
|
||
$reserve = new Reserve($client); | ||
|
||
$this->assertEquals($data, $reserve->getStatistics()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldReturnTransactions() | ||
{ | ||
$data = array(array( | ||
'id' => 'a97bb994-6e24-4a89-b653-e0a6d0bcf634', | ||
'status' => 'completed', | ||
), array( | ||
'id' => '63dc7ccb-0e57-400d-8ea7-7d903753801c', | ||
'status' => 'pending', | ||
)); | ||
|
||
$client = $this->getBitreserveClientMock(); | ||
$client->expects($this->once()) | ||
->method('get') | ||
->with('/reserve/transactions') | ||
->will($this->returnValue($data)); | ||
|
||
$reserve = new Reserve($client); | ||
|
||
$transactions = $reserve->getTransactions(); | ||
|
||
foreach ($transactions as $key => $transaction) { | ||
$this->assertInstanceOf('Bitreserve\Model\Transaction', $transaction); | ||
$this->assertEquals($data[$key]['id'], $transaction->getId()); | ||
$this->assertEquals($data[$key]['status'], $transaction->getStatus()); | ||
} | ||
} | ||
|
||
public function shouldReturnOneTransaction() | ||
{ | ||
$data = array( | ||
'id' => 'a97bb994-6e24-4a89-b653-e0a6d0bcf634', | ||
'status' => 'completed', | ||
); | ||
|
||
$client = $this->getBitreserveClientMock(); | ||
$client->expects($this->once()) | ||
->method('get') | ||
->with(sprintf('/reserve/transactions/%s', $data['id'])) | ||
->will($this->returnValue($data)); | ||
|
||
$reserve = new Reserve($client); | ||
|
||
$transaction = $reserve->getTransactionById($data['id']); | ||
|
||
$this->assertInstanceOf('Bitreserve\Model\Transaction', $transaction); | ||
$this->assertEquals($data['id'], $transaction->getId()); | ||
$this->assertEquals($data['status'], $transaction->getStatus()); | ||
} | ||
|
||
protected function getModelClass() | ||
{ | ||
return 'Bitreserve\Model\Reserve'; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing data assert.