Skip to content

Commit ec99a8d

Browse files
author
Kedar
authored
Merge pull request #17 from OpenSTFoundation/v1.1_changes
V1.1 changes
2 parents d2791e4 + 785dc01 commit ec99a8d

7 files changed

Lines changed: 145 additions & 44 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[OST PHP SDK v1.1.0](https://github.com/OpenSTFoundation/ost-sdk-php/tree/v1.1.0) July 2 2018
2+
---
3+
4+
* Added user balances module to V1 API's
5+
* Added transaction ledger module to V1 API's
6+
7+
[OST PHP SDK v1.0.0](https://github.com/OpenSTFoundation/ost-sdk-php/tree/v1.0.0) May 30 2018
8+
---
9+
Initial release of the official OST PHP SDK<br />
10+
This release has the OST API interaction layer implementation.

src/Lib/Request.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,7 @@ public function __construct(array $params)
4545
$this->apiKey = $params['apiKey'];
4646
$this->apiSecret = $params['apiSecret'];
4747

48-
// append a trailing / to apiEndpoint (if required)
49-
// NOTE: As Guzzle remove "v1" from base url if ending slash is not present
50-
$apiBaseUrl = $params['apiBaseUrl'];
51-
if ($apiBaseUrl[strlen($apiBaseUrl) - 1] !== '/') {
52-
$apiBaseUrl .= '/';
53-
}
54-
55-
$this->baseUrl = $apiBaseUrl;
48+
$this->baseUrl = $this->sanitizeApiBaseUrl($params['apiBaseUrl']);
5649

5750
}
5851

@@ -126,6 +119,28 @@ function ($reason) {
126119
);
127120
}
128121

122+
123+
/**
124+
* sanitize API Base URL
125+
*
126+
* @param string $apiBaseUrl api base url
127+
*
128+
* @return string
129+
*
130+
*/
131+
private function sanitizeApiBaseUrl($apiBaseUrl)
132+
{
133+
134+
// append a trailing / to apiEndpoint (if required)
135+
// NOTE: As Guzzle remove "v1" from base url if ending slash is not present
136+
if ($apiBaseUrl[strlen($apiBaseUrl) - 1] !== '/') {
137+
$apiBaseUrl .= '/';
138+
}
139+
140+
return $apiBaseUrl;
141+
142+
}
143+
129144
/**
130145
* Parse response of GET / POST requests
131146
*

src/OSTSdk.php

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,37 @@
99
class OSTSdk
1010
{
1111

12-
/** @var object object to access methods */
13-
public $services;
12+
/** @var object object to access methods */
13+
public $services;
1414

15-
/**
16-
* Class constructor.
17-
*
18-
* @param array $params Array containing the necessary params {
19-
* @type string $apiKey API Key.
20-
* @type string $apiSecret API Secret.
21-
* @type string $baseUrl Base API URL.
22-
* }
23-
*
24-
* @throws \Exception
25-
*/
26-
public function __construct(array $params)
27-
{
28-
// Extract API major version
29-
$apiEndpointVersion = explode('/', $params['apiBaseUrl'])[3];
30-
if (empty($apiEndpointVersion)) {
31-
$this->services = new \OST\V0\Manifest($params);
32-
} elseif (!empty($apiEndpointVersion) && strtolower($apiEndpointVersion) === 'v1') {
33-
$this->services = new \OST\V1\Manifest($params);
34-
} else {
35-
throw new \Exception('Api endpoint is invalid');
36-
}
15+
/**
16+
* Class constructor.
17+
*
18+
* @param array $params Array containing the necessary params {
19+
* @type string $apiKey API Key.
20+
* @type string $apiSecret API Secret.
21+
* @type string $baseUrl Base API URL.
22+
* }
23+
*
24+
* @throws \Exception
25+
*/
26+
public function __construct(array $params)
27+
{
28+
// Extract API version
29+
$apiEndpointVersion = explode('/', $params['apiBaseUrl'])[3];
30+
31+
# Provide access to version specific API endpoints
32+
if (is_null($apiEndpointVersion) || $apiEndpointVersion == '') {
33+
$this->services = new \OST\V0\Manifest($params);
34+
} elseif (strtolower($apiEndpointVersion) == 'v1') {
35+
$this->services = new \OST\V1\Manifest($params);
36+
} elseif (strtolower($apiEndpointVersion) == 'v1.1') {
37+
$this->services = new \OST\V1Dot1\Manifest($params);
38+
} else {
39+
throw new \Exception('Api endpoint is invalid');
3740
}
41+
42+
}
43+
44+
3845
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* Balances class
44
*/
55

6-
namespace OST\V1;
6+
namespace OST\V1Dot1;
77

88
use OST\Base;
99

1010
/**
11-
* Class encapsulating methods to interact with V1 API's for Balances module
11+
* Class encapsulating methods to interact with V1.1 API's for Balances module
1212
*/
1313
class Balances extends Base
1414
{
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* Ledger class
44
*/
55

6-
namespace OST\V1;
6+
namespace OST\V1Dot1;
77

88
use OST\Base;
99

1010
/**
11-
* Class encapsulating methods to interact with V1 API's for Ledger module
11+
* Class encapsulating methods to interact with V1.1 API's for Ledger module
1212
*/
1313
class Ledger extends Base
1414
{

src/Services/V1.1/Manifest.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Manifest class
4+
*/
5+
6+
namespace OST\V1Dot1;
7+
8+
use Lib\Request;
9+
10+
use OST\V1\Users;
11+
use OST\V1\Actions;
12+
use OST\V1\Airdrops;
13+
use OST\V1\Token;
14+
use OST\V1\Transactions;
15+
use OST\V1\Transfers;
16+
17+
/**
18+
* Class providing public vars to interact with V1 API's for different modules
19+
*/
20+
class Manifest
21+
{
22+
/** @var Users object which has methods to fire API's belonging to User module */
23+
public $users;
24+
25+
/** @var Actions object which has methods to fire API's belonging to Actions module */
26+
public $actions;
27+
28+
/** @var Airdrops object which has methods to fire API's belonging to Airdrops module */
29+
public $airdrops;
30+
31+
/** @var Token object which has methods to fire API's belonging to Token module */
32+
public $token;
33+
34+
/** @var Transactions object which has methods to fire API's belonging to Transactions module */
35+
public $transactions;
36+
37+
/** @var Transfers object which has methods to fire API's belonging to Transfers module */
38+
public $transfers;
39+
40+
/** @var Balances object which has methods to fire API's belonging to Balances module */
41+
public $balances;
42+
43+
/** @var Ledger object which has methods to fire API's belonging to Ledger module */
44+
public $ledger;
45+
46+
/**
47+
* Constructor
48+
*
49+
* @param array $params Array containing the necessary params {
50+
* @type string $apiKey API Key.
51+
* @type string $apiSecret API Secret.
52+
* @type string $baseUrl Base API URL.
53+
* }
54+
*
55+
* @throws \Exception
56+
*
57+
*/
58+
public function __construct($params)
59+
{
60+
61+
$requestObj = new Request($params);
62+
63+
// Define services available in V1
64+
$this->users = new Users($requestObj);
65+
$this->actions = new Actions($requestObj);
66+
$this->airdrops = new Airdrops($requestObj);
67+
$this->token = new Token($requestObj);
68+
$this->transactions = new Transactions($requestObj);
69+
$this->transfers = new Transfers($requestObj);
70+
71+
// Define services available in V1.1
72+
$this->balances = new Balances($requestObj);
73+
$this->ledger = new Ledger($requestObj);
74+
75+
}
76+
77+
}

src/Services/V1/Manifest.php

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

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-
3933
/**
4034
* Constructor
4135
*
@@ -60,8 +54,6 @@ public function __construct($params)
6054
$this->token = new Token($requestObj);
6155
$this->transactions = new Transactions($requestObj);
6256
$this->transfers = new Transfers($requestObj);
63-
$this->balances = new Balances($requestObj);
64-
$this->ledger = new Ledger($requestObj);
6557

6658
}
6759

0 commit comments

Comments
 (0)