Skip to content

Commit d5aee90

Browse files
lornajanemheap
authored andcommitted
Allow independent override of both rest and api URLs
1 parent 3960c78 commit d5aee90

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,27 @@ If you're using Composer, make sure the autoloader is included in your project's
4141
```php
4242
require_once "vendor/autoload.php";
4343
```
44-
44+
4545
Create a client with your API key and secret:
4646

4747
```php
4848
$client = new Nexmo\Client(new Nexmo\Client\Credentials\Basic(API_KEY, API_SECRET));
4949
```
5050

51-
For testing purposes you may want to change the URL that `nexmo-php` makes requests to. You can do this by providing an array containing `base_url` as the second parameter when creating a `Nexmo\Client` instance.
51+
For testing purposes you may want to change the URL that `nexmo-php` makes requests to from `api.nexmo.com` to something else. You can do this by providing an array containing `base_api_url` as the second parameter when creating a `Nexmo\Client` instance.
5252

5353
```php
5454
$client = new Nexmo\Client(
5555
new Nexmo\Client\Credentials\Basic(API_KEY, API_SECRET),
5656
[
57-
'base_url' => 'https://example.com'
57+
'base_api_url' => 'https://example.com'
5858
]
5959
);
6060

6161
```
6262

63+
For APIs that would usually hit `rest.nexmo.com`, supplying a `base_rest_url` as an option to the constructor will change those requests.
64+
6365
Examples
6466
--------
6567

src/Client.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,14 @@ public function __construct(CredentialsInterface $credentials, $options = array(
9696
$this->apiUrl = static::BASE_API;
9797
$this->restUrl = static::BASE_REST;
9898

99-
// If they've provided a base URL, use that instead
99+
// If they've provided alternative URLs, use that instead
100100
// of the defaults
101-
if (isset($options['base_url'])) {
102-
$this->restUrl = $options['base_url'];
103-
$this->apiUrl = $options['base_url'];
101+
if (isset($options['base_rest_url'])) {
102+
$this->restUrl = $options['base_rest_url'];
103+
}
104+
105+
if (isset($options['base_api_url'])) {
106+
$this->apiUrl = $options['base_api_url'];
104107
}
105108

106109
$this->setFactory(new MapFactory([

0 commit comments

Comments
 (0)