Skip to content

Commit d2791e4

Browse files
authored
Merge pull request #16 from OpenSTFoundation/santhosh/balances_and_ledger
Refactoring + Balance and Ledger API changes
2 parents 88c9e51 + ad1a820 commit d2791e4

11 files changed

Lines changed: 146 additions & 33 deletions

File tree

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ end_of_line = lf
1212
insert_final_newline = true
1313
trim_trailing_whitespace = true
1414
indent_style = space
15-
indent_size = 4
15+
indent_size = 2

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ docs
33
composer.lock
44
.idea
55
.env
6+
.env.example

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,33 @@ $executeParams['amount'] = '1';
265265
$response = $transferService->execute($executeParams)->wait();
266266
var_dump($response);
267267
```
268+
269+
### Balance Module
270+
271+
```php
272+
$balanceService = $ostObj->services->balances;
273+
```
274+
Get User balance:
275+
276+
```php
277+
$getParams = array();
278+
$getParams['id'] = 'ad03a99e-e7c4-4f5a-9fab-ef9a3e422621';
279+
$response = $balanceService->get($getParams)->wait();
280+
var_dump($response);
281+
```
282+
283+
### Ledger Module
284+
285+
```php
286+
$ledgerService = $ostObj->services->ledger;
287+
```
288+
289+
Get User Ledger:
290+
291+
```php
292+
$getParams = array();
293+
$getParams['id'] = 'ad03a99e-e7c4-4f5a-9fab-ef9a3e422621';
294+
$response = $ledgerService->get($getParams)->wait();
295+
var_dump($response);
296+
```
297+

src/Lib/Request.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function ($response) {
8282
return $this->parseResponse($response);
8383
},
8484
// $onRejected
85-
function () {
85+
function ($reason) {
8686
return $this->customGenericErrorResponse('g_1');
8787
}
8888
);
@@ -120,7 +120,7 @@ function ($response) {
120120
return $this->parseResponse($response);
121121
},
122122
// $onRejected
123-
function () {
123+
function ($reason) {
124124
return $this->customGenericErrorResponse('p_1');
125125
}
126126
);

src/OSTSdk.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ class OSTSdk
2626
public function __construct(array $params)
2727
{
2828
// Extract API major version
29-
$apiEndpointVersion = explode('/', $params['apiBaseUrl']);
30-
if (empty($apiEndpointVersion[3])) {
29+
$apiEndpointVersion = explode('/', $params['apiBaseUrl'])[3];
30+
if (empty($apiEndpointVersion)) {
3131
$this->services = new \OST\V0\Manifest($params);
32-
} elseif (!empty($apiEndpointVersion[3]) && strtolower($apiEndpointVersion[3]) === 'v1') {
32+
} elseif (!empty($apiEndpointVersion) && strtolower($apiEndpointVersion) === 'v1') {
3333
$this->services = new \OST\V1\Manifest($params);
3434
} else {
3535
throw new \Exception('Api endpoint is invalid');

src/Services/V1/Airdrops.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
namespace OST\V1;
77

8+
use OST\Base;
9+
810
/**
911
* Class encapsulating methods to interact with V1 API's for Airdrops module
1012
*/
11-
class Airdrops extends \OST\Base
13+
class Airdrops extends Base
1214
{
1315
const PREFIX = '/airdrops';
1416

src/Services/V1/Balances.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Balances class
4+
*/
5+
6+
namespace OST\V1;
7+
8+
use OST\Base;
9+
10+
/**
11+
* Class encapsulating methods to interact with V1 API's for Balances module
12+
*/
13+
class Balances extends Base
14+
{
15+
16+
const PREFIX = '/balances';
17+
18+
/**
19+
* Get balance of user
20+
*
21+
* @param array $params params for fetching balance of user
22+
*
23+
* @throws \Exception
24+
*
25+
* @return object
26+
*
27+
*/
28+
public function get($params = array()) {
29+
return $this->requestObj->get($this->getPrefix() . '/' . $this->getId($params) . '/', $params);
30+
}
31+
32+
}

src/Services/V1/Ledger.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Ledger class
4+
*/
5+
6+
namespace OST\V1;
7+
8+
use OST\Base;
9+
10+
/**
11+
* Class encapsulating methods to interact with V1 API's for Ledger module
12+
*/
13+
class Ledger extends Base
14+
{
15+
16+
const PREFIX = '/ledger';
17+
18+
/**
19+
* Get ledger for user
20+
*
21+
* @param array $params params for fetching ledger for an user
22+
*
23+
* @throws \Exception
24+
*
25+
* @return object
26+
*
27+
*/
28+
public function get($params = array()) {
29+
return $this->requestObj->get($this->getPrefix() . '/' . $this->getId($params) . '/', $params);
30+
}
31+
32+
}

src/Services/V1/Manifest.php

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,39 @@ class Manifest
3030
/** @var Transfers object which has methods to fire API's belonging to Transfers module */
3131
public $transfers;
3232

33-
/**
34-
* Constructor
35-
*
36-
* @param array $params Array containing the necessary params {
37-
* @type string $apiKey API Key.
38-
* @type string $apiSecret API Secret.
39-
* @type string $baseUrl Base API URL.
40-
* }
41-
*
42-
* @throws \Exception
43-
*
44-
*/
45-
public function __construct($params)
46-
{
47-
$requestObj = new Request($params);
48-
49-
// Define services available in V1
50-
$this->users = new Users($requestObj);
51-
$this->actions = new Actions($requestObj);
52-
$this->airdrops = new Airdrops($requestObj);
53-
$this->token = new Token($requestObj);
54-
$this->transactions = new Transactions($requestObj);
55-
$this->transfers = new Transfers($requestObj);
56-
}
33+
/** @var Balances object which has methods to fire API's belonging to Balances module */
34+
public $balances;
35+
36+
/** @var Ledger object which has methods to fire API's belonging to Ledger module */
37+
public $ledger;
38+
39+
/**
40+
* Constructor
41+
*
42+
* @param array $params Array containing the necessary params {
43+
* @type string $apiKey API Key.
44+
* @type string $apiSecret API Secret.
45+
* @type string $baseUrl Base API URL.
46+
* }
47+
*
48+
* @throws \Exception
49+
*
50+
*/
51+
public function __construct($params)
52+
{
53+
54+
$requestObj = new Request($params);
55+
56+
// Define services available in V1
57+
$this->users = new Users($requestObj);
58+
$this->actions = new Actions($requestObj);
59+
$this->airdrops = new Airdrops($requestObj);
60+
$this->token = new Token($requestObj);
61+
$this->transactions = new Transactions($requestObj);
62+
$this->transfers = new Transfers($requestObj);
63+
$this->balances = new Balances($requestObj);
64+
$this->ledger = new Ledger($requestObj);
65+
66+
}
67+
5768
}

src/Services/V1/Token.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
class Token extends Base
1414
{
15-
const TOKEN = '/token';
15+
const PREFIX = '/token';
1616

1717
/**
1818
* Get token details

0 commit comments

Comments
 (0)