Skip to content

Commit 9515f90

Browse files
committed
Merge pull request #22 from clue-labs/api
Rename Api -> ActionSender
2 parents 37c1363 + 464612e commit 9515f90

7 files changed

Lines changed: 32 additions & 31 deletions

File tree

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ Once [installed](#install), you can use the following code to access your local
3131
Asterisk Telephony instance and issue some simple commands via AMI:
3232

3333
```php
34+
$loop = React\EventLoop\Factory::create();
3435
$factory = new Factory($loop);
3536

3637
$factory->createClient('user:secret@localhost')->then(function (Client $client) {
3738
echo 'Client connected' . PHP_EOL;
3839

39-
$api = new Api($client);
40-
$api->listCommands()->then(function (Response $response) {
40+
$sender = new ActionSender($client);
41+
$sender->listCommands()->then(function (Response $response) {
4142
echo 'Available commands:' . PHP_EOL;
4243
var_dump($response);
4344
});
@@ -103,7 +104,7 @@ The `close()` method can be used to force-close the AMI connection and reject al
103104
The `end()` method can be used to soft-close the AMI connection once all pending actions are completed.
104105

105106
> Advanced: Creating [`Action`](#action) objects, sending them via AMI and waiting for incoming
106-
> [`Response`](#response) objects is usually hidden behind the [`Api`](#api) interface.
107+
> [`Response`](#response) objects is usually hidden behind the [`ActionSender`](#actionsender) interface.
107108
>
108109
> If you happen to need a custom or otherwise unsupported action, you can also do so manually
109110
> as follows. Consider filing a PR though :)
@@ -114,29 +115,29 @@ The `end()` method can be used to soft-close the AMI connection once all pending
114115
> The `request(Action $action)` method can be used to queue the given messages to be sent via AMI
115116
> and wait for a [`Response`](#response) object that matches the value of its "ActionID" field.
116117
117-
### Api
118+
### ActionSender
118119

119-
The `Api` wraps a given [`Client`](#client) instance to provide a simple way to execute common actions.
120+
The `ActionSender` wraps a given [`Client`](#client) instance to provide a simple way to execute common actions.
120121
This class represents the main interface to execute actions and wait for the corresponding responses.
121122

122123
```php
123-
$api = new Api($client);
124+
$sender = new ActionSender($client);
124125

125-
$api->ping()->then(function (Response $response) {
126+
$sender->ping()->then(function (Response $response) {
126127
// response received for ping action
127128
});
128129
```
129130

130131
All public methods resemble their respective AMI actions.
131-
Listing all available actions is out of scope here, please refer to the [class outline](src/Api.php).
132+
Listing all available actions is out of scope here, please refer to the [class outline](src/ActionSender.php).
132133

133134
Sending actions is async (non-blocking), so you can actually send multiple action requests in parallel.
134135
The AMI will respond to each action with a [`Response`](#response) object. The order is not guaranteed.
135136
Sending actions uses a Promise-based interface that makes it easy to react to when an action is *fulfilled*
136137
(i.e. either successfully resolved or rejected with an error):
137138

138139
```php
139-
$api->ping()->then(
140+
$sender->ping()->then(
140141
function (Response $response) {
141142
// response received for ping action
142143
},
@@ -153,11 +154,11 @@ $api->ping()->then(
153154
});
154155
```
155156

156-
> Advanced: Using the `Api` is not strictly necessary, but is the recommended way to execute common actions.
157+
> Advanced: Using the `ActionSender` is not strictly necessary, but is the recommended way to execute common actions.
157158
>
158159
> If you happen to need a new or otherwise unsupported action, or additional arguments,
159160
> you can also do so manually. See the advanced [`Client`](#client) usage above for details.
160-
> A PR that updates the `Api` is very much appreciated :)
161+
> A PR that updates the `ActionSender` is very much appreciated :)
161162
162163
### Message
163164

examples/commands.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use Clue\React\Ami\Factory;
44
use Clue\React\Ami\Client;
5-
use Clue\React\Ami\Api;
5+
use Clue\React\Ami\ActionSender;
66
use Clue\React\Ami\Protocol\Response;
77

88
require __DIR__ . '/../vendor/autoload.php';
@@ -14,11 +14,11 @@
1414

1515
$factory->createClient($target)->then(function (Client $client) use ($loop) {
1616
echo 'Client connected. Use STDIN to send CLI commands via asterisk AMI.' . PHP_EOL;
17-
$api = new Api($client);
17+
$sender = new ActionSender($client);
1818

19-
$api->events(false);
19+
$sender->events(false);
2020

21-
$api->listCommands()->then(function (Response $response) {
21+
$sender->listCommands()->then(function (Response $response) {
2222
echo 'Commands: ' . implode(', ', array_keys($response->getFields())) . PHP_EOL;
2323
});
2424

@@ -28,11 +28,11 @@
2828
$loop->removeReadStream(STDIN);
2929
});
3030

31-
$loop->addReadStream(STDIN, function () use ($api) {
31+
$loop->addReadStream(STDIN, function () use ($sender) {
3232
$line = trim(fread(STDIN, 4096));
3333
echo '<' . $line . PHP_EOL;
3434

35-
$api->command($line)->then(
35+
$sender->command($line)->then(
3636
function (Response $response) {
3737
echo $response->getFieldValue('_') . PHP_EOL;
3838
},

examples/events.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use Clue\React\Ami\Factory;
44
use Clue\React\Ami\Client;
5-
use Clue\React\Ami\Api;
5+
use Clue\React\Ami\ActionSender;
66
use Clue\React\Ami\Protocol\Response;
77
use Clue\React\Ami\Protocol\Event;
88

@@ -17,8 +17,8 @@
1717
function (Client $client) use ($loop) {
1818
echo 'Client connected ' . PHP_EOL;
1919

20-
$api = new Api($client);
21-
$api->events(true);
20+
$sender = new ActionSender($client);
21+
$sender->events(true);
2222

2323
$client->on('close', function() {
2424
echo 'Connection closed' . PHP_EOL;

examples/peers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use Clue\React\Ami\Factory;
44
use Clue\React\Ami\Client;
5-
use Clue\React\Ami\Api;
5+
use Clue\React\Ami\ActionSender;
66
use Clue\React\Ami\Collector;
77
use Clue\React\Ami\Protocol\Collection;
88

src/Api.php renamed to src/ActionSender.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use UnexpectedValueException;
99
use Clue\React\Ami\Protocol\Event;
1010

11-
class Api
11+
class ActionSender
1212
{
1313
private $client;
1414

src/Factory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public function createClient($address = null)
4343

4444
if (isset($parts['user'])) {
4545
$promise = $promise->then(function (Client $client) use ($parts, $secure) {
46-
$api = new Api($client);
46+
$sender = new ActionSender($client);
4747

48-
return $api->login($parts['user'], $parts['pass'])->then(
48+
return $sender->login($parts['user'], $parts['pass'])->then(
4949
function ($response) use ($client) {
5050
return $client;
5151
},

tests/FunctionalTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use Clue\React\Ami\Factory;
44
use React\Promise\PromiseInterface;
55
use Clue\React\Ami\Client;
6-
use Clue\React\Ami\Api;
6+
use Clue\React\Ami\ActionSender;
77
use Clue\React\Ami\Protocol\Response;
88

99
class FunctionalTest extends TestCase
@@ -42,9 +42,9 @@ public function testConnection()
4242
*/
4343
public function testPing(Client $client)
4444
{
45-
$api = new Api($client);
45+
$sender = new ActionSender($client);
4646

47-
$pong = $this->waitFor($api->ping());
47+
$pong = $this->waitFor($sender->ping());
4848
/* @var $pong Response */
4949
}
5050

@@ -62,11 +62,11 @@ public function testInvalidCommandGetsRejected(Client $client)
6262
* @depends testConnection
6363
* @param Client $client
6464
*/
65-
public function testApiLogoffDisconnects(Client $client)
65+
public function testActionSenderLogoffDisconnects(Client $client)
6666
{
67-
$api = new Api($client);
67+
$sender = new ActionSender($client);
6868

69-
$ret = $this->waitFor($api->logoff());
69+
$ret = $this->waitFor($sender->logoff());
7070
/* @var $ret Response */
7171

7272
$this->assertFalse($client->isBusy());
@@ -79,7 +79,7 @@ public function testApiLogoffDisconnects(Client $client)
7979
}
8080

8181
/**
82-
* @depends testApiLogoffDisconnects
82+
* @depends testActionSenderLogoffDisconnects
8383
* @param Client $client
8484
* @expectedException Exception
8585
*/

0 commit comments

Comments
 (0)