Skip to content

Commit 5fc3638

Browse files
Vinay Bhaleraomikz
authored andcommitted
make host and port configurable (#16)
* [host] make host and port configurable * fix test case * added scheme * make single root endpoint for the SAAS platform endpoint and fixed test cases * [changelog] update * [changelog] minor edits
1 parent 7b4e2f8 commit 5fc3638

3 files changed

Lines changed: 20 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## Unreleased
5+
6+
### Changed
7+
- Allow custom host and port configurable for 3scale On premise SAAS platform [PR #16](https://github.com/3scale/3scale_ws_api_for_php/.) Note: For example, the signature is changed from ```$url = "http://" . $this->getHost() . "/transactions/authorize.xml"``` to ```$url = $this->getHost() . "/transactions/oauth_authorize.xml";``` for endpoints
8+
49
##[2.7.0] - 2017-02-16
510
### Added
611
- Added support for (Service Tokens)[https://support.3scale.net/docs/accounts/tokens]

lib/ThreeScaleClient.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,30 @@
1717
*
1818
* Objects of this class are stateless and can be shared through multiple
1919
* transactions and by multiple clients.
20+
* DEFAULT_ROOT_ENDPOINT su1.3scale.net communicates with 3scale SAAS platform. When connecting to an on-premise instance of the 3scale platform, replace it with correct scheme, host and port
2021
*/
2122
class ThreeScaleClient {
22-
const DEFAULT_HOST = 'su1.3scale.net';
23+
const DEFAULT_ROOT_ENDPOINT = 'http://su1.3scale.net';
2324

2425
private $providerKey = null;
25-
private $host;
2626
private $httpClient;
27+
private $host;
2728

2829
/**
2930
* Create a ThreeScaleClient instance.
3031
*
3132
* @param $providerKey If (!Provider Key) then service token workflow is triggered.
32-
* @param $host String Hostname of 3scale backend server. Usually there is no reason to use anything
33-
* else than the default value.
33+
* @param $host String scheme + hostname + port of 3scale backend server or On-premise 3scale SAAS platform
3434
* @param $httpClient Object Object for handling HTTP requests. Default is CURL. Don't change it
3535
* unless you know what you are doing.
3636
*/
37-
public function __construct($providerKey = null, $host = self::DEFAULT_HOST, $httpClient = null) {
37+
public function __construct($providerKey = null, $host = self::DEFAULT_ROOT_ENDPOINT, $httpClient = null) {
3838
if ($providerKey) {
3939
$this->providerKey = $providerKey;
4040
}
4141

42-
$this->host = $host;
4342
$this->setHttpClient($httpClient);
43+
$this->host = $host;
4444
}
4545

4646
/**
@@ -52,7 +52,7 @@ public function getProviderKey() {
5252
}
5353

5454
/**
55-
* Get hostname of 3scale backend server.
55+
* Get hostname of backend server.
5656
* @return string
5757
*/
5858
public function getHost() {
@@ -94,7 +94,7 @@ public function getHost() {
9494
*/
9595

9696
public function authorize($appId, $appKey = null, $credentials_or_service_id, $usage = null) {
97-
$url = "http://" . $this->getHost() . "/transactions/authorize.xml";
97+
$url = $this->getHost() . "/transactions/authorize.xml";
9898
$params = array('app_id' => $appId);
9999

100100
if ($credentials_or_service_id instanceof ThreeScaleClientCredentials ) {
@@ -156,7 +156,7 @@ public function authorize($appId, $appKey = null, $credentials_or_service_id, $u
156156
* </code>
157157
*/
158158
public function oauth_authorize($appId, $credentials_or_service_id, $usage = null) {
159-
$url = "http://" . $this->getHost() . "/transactions/oauth_authorize.xml";
159+
$url = $this->getHost() . "/transactions/oauth_authorize.xml";
160160
$params = array('app_id' => $appId);
161161

162162
if ($credentials_or_service_id instanceof ThreeScaleClientCredentials ) {
@@ -215,7 +215,7 @@ public function oauth_authorize($appId, $credentials_or_service_id, $usage = nul
215215
*/
216216

217217
public function authorize_with_user_key($userKey, $credentials_or_service_id, $usage = null) {
218-
$url = "http://" . $this->getHost() . "/transactions/authorize.xml";
218+
$url = $this->getHost() . "/transactions/authorize.xml";
219219
$params = array('user_key' => $userKey);
220220

221221
if ($credentials_or_service_id instanceof ThreeScaleClientCredentials ) {
@@ -275,7 +275,7 @@ public function authorize_with_user_key($userKey, $credentials_or_service_id, $u
275275
*/
276276

277277
public function authrep($appId, $appKey = null, $credentials_or_service_id, $usage = null, $userId = null, $object = null, $no_body = null) {
278-
$url = "http://" . $this->getHost() . "/transactions/authrep.xml";
278+
$url = $this->getHost() . "/transactions/authrep.xml";
279279

280280
$params = array('app_id' => $appId);
281281

@@ -337,7 +337,7 @@ public function authrep($appId, $appKey = null, $credentials_or_service_id, $usa
337337
*/
338338

339339
public function authrep_with_user_key($userKey, $credentials_or_service_id, $usage = null, $userId = null, $object = null, $no_body = null) {
340-
$url = "http://" . $this->getHost() . "/transactions/authrep.xml";
340+
$url = $this->getHost() . "/transactions/authrep.xml";
341341

342342
$params = array('user_key' => $userKey);
343343

@@ -429,7 +429,7 @@ public function report($transactions, $credentials_or_service_id) {
429429
throw new InvalidArgumentException('no transactions to report');
430430
}
431431

432-
$url = "http://" . $this->getHost() . "/transactions.xml";
432+
$url = $this->getHost() . "/transactions.xml";
433433

434434
$params = array();
435435

test/ThreeScaleClientTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function testThrowsExceptionIfServiceTokenIsMissing() {
3838
function testDefaultHost() {
3939
$client = new ThreeScaleClient('1234abcd');
4040

41-
$this->assertEqual('su1.3scale.net', $client->getHost());
41+
$this->assertEqual('http://su1.3scale.net', $client->getHost());
4242
}
4343

4444
function testSuccessfulAuthorize() {
@@ -159,7 +159,7 @@ function testSuccessfulReport() {
159159

160160
function testReportEncodesTransactions() {
161161
$this->httpClient->expectOnce('post',
162-
array('http://' . ThreeScaleClient::DEFAULT_HOST . '/transactions.xml',
162+
array(ThreeScaleClient::DEFAULT_ROOT_ENDPOINT . '/transactions.xml',
163163
array(
164164
'service_token' => '12345',
165165
'service_id' => '12345',

0 commit comments

Comments
 (0)