Skip to content

Commit b7bd967

Browse files
committed
Simplify message names
1 parent a1dd204 commit b7bd967

9 files changed

Lines changed: 34 additions & 34 deletions

File tree

example/commands.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use Clue\React\Ami\Factory;
44
use Clue\React\Ami\Client;
55
use Clue\React\Ami\Api;
6-
use Clue\React\Ami\Protocol\ActionResponse;
7-
use Clue\React\Ami\Protocol\EventMessage;
6+
use Clue\React\Ami\Protocol\Response;
7+
use Clue\React\Ami\Protocol\Event;
88
use Clue\React\Ami\Protocol\ErrorException;
99

1010
require __DIR__ . '/../vendor/autoload.php';
@@ -20,7 +20,7 @@
2020

2121
$api->events(false);
2222

23-
$api->listCommands()->then(function (ActionResponse $response) {
23+
$api->listCommands()->then(function (Response $response) {
2424
echo 'Commands: ' . implode(', ', array_keys($response->getParts())) . PHP_EOL;
2525
});
2626

@@ -33,7 +33,7 @@
3333
echo '<' . $line . PHP_EOL;
3434

3535
$api->command($line)->then(
36-
function(ActionResponse $response) {
36+
function(Response $response) {
3737
echo $response->getPart('_') . PHP_EOL;
3838
},
3939
function (ErrorException $error) use ($line) {

example/events.php

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

99
require __DIR__ . '/../vendor/autoload.php';
1010

@@ -24,7 +24,7 @@ function (Client $client) use ($loop) {
2424
echo 'Connection closed' . PHP_EOL;
2525
});
2626

27-
$client->on('event', function (EventMessage $event) {
27+
$client->on('event', function (Event $event) {
2828
echo 'Event: ' . $event->getName() . ': ' . $event->toJson() . PHP_EOL;
2929
});
3030
},

src/Api.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace Clue\React\Ami;
44

55
use Clue\React\Ami\Client;
6-
use Clue\React\Ami\Protocol\ActionResponse;
7-
use Clue\React\Ami\Protocol\ActionRequest;
6+
use Clue\React\Ami\Protocol\Response;
7+
use Clue\React\Ami\Protocol\Action;
88
use UnexpectedValueException;
9-
use Clue\React\Ami\Protocol\EventMessage;
9+
use Clue\React\Ami\Protocol\Event;
1010

1111
class Api
1212
{
@@ -20,33 +20,33 @@ public function __construct(Client $client)
2020
public function login($username, $secret, $events = null)
2121
{
2222
$events = $this->boolParam($events);
23-
return $this->client->request(new ActionRequest('Login', array('UserName' => $username, 'Secret' => $secret, 'Events' => $events)));
23+
return $this->client->request(new Action('Login', array('UserName' => $username, 'Secret' => $secret, 'Events' => $events)));
2424
}
2525

2626
public function logout()
2727
{
28-
return $this->client->request(new ActionRequest('Logout'));
28+
return $this->client->request(new Action('Logout'));
2929
}
3030

3131
public function agentLogoff($agentId, $soft = false)
3232
{
3333
$bool = $soft ? 'true' : 'false';
34-
return $this->client->request(new ActionRequest('AgentLogoff', array('Agent' => $agentId, 'Soft' => $bool)));
34+
return $this->client->request(new Action('AgentLogoff', array('Agent' => $agentId, 'Soft' => $bool)));
3535
}
3636

3737
public function ping()
3838
{
39-
return $this->client->request(new ActionRequest('Ping'));
39+
return $this->client->request(new Action('Ping'));
4040
}
4141

4242
public function coreShowChannels()
4343
{
44-
return $this->client->request(new ActionRequest('CoreShowChannels'));
44+
return $this->client->request(new Action('CoreShowChannels'));
4545
}
4646

4747
public function command($command)
4848
{
49-
return $this->client->request(new ActionRequest('Command', array('Command' => $command)));
49+
return $this->client->request(new Action('Command', array('Command' => $command)));
5050
}
5151

5252
public function events($eventMask)
@@ -59,42 +59,42 @@ public function events($eventMask)
5959
$eventMask = implode(',', $eventMask);
6060
}
6161

62-
return $this->client->request(new ActionRequest('Events', array('EventMask' => $eventMask)));
62+
return $this->client->request(new Action('Events', array('EventMask' => $eventMask)));
6363
}
6464

6565
public function sipPeers()
6666
{
67-
return $this->client->request(new ActionRequest('SIPPeers'));
67+
return $this->client->request(new Action('SIPPeers'));
6868
}
6969

7070
public function sipShowPeer($peerName)
7171
{
72-
return $this->client->request(new ActionRequest('SIPshowpeer', array('Peer' => $peerName)));
72+
return $this->client->request(new Action('SIPshowpeer', array('Peer' => $peerName)));
7373
}
7474

7575
public function listCommands()
7676
{
77-
return $this->client->request(new ActionRequest('ListCommands'));
77+
return $this->client->request(new Action('ListCommands'));
7878
}
7979

8080
public function sendText($channel, $message)
8181
{
82-
return $this->client->request(new ActionRequest('Sendtext', array('Channel' => $channel, 'Message' => $message)));
82+
return $this->client->request(new Action('Sendtext', array('Channel' => $channel, 'Message' => $message)));
8383
}
8484

8585
public function hangup($channel, $cause)
8686
{
87-
return $this->client->request(new ActionRequest('Hangup', array('Channel' => $channel, 'Cause' => $cause)));
87+
return $this->client->request(new Action('Hangup', array('Channel' => $channel, 'Cause' => $cause)));
8888
}
8989

9090
public function challenge($authType = 'MD5')
9191
{
92-
return $this->client->request(new ActionRequest('Challenge', array('AuthType' => $authType)));
92+
return $this->client->request(new Action('Challenge', array('AuthType' => $authType)));
9393
}
9494

9595
public function getConfig($filename, $category = null)
9696
{
97-
return $this->client->request(new ActionRequest('GetConfig', array('Filename' => $filename, 'Category' => $category)));
97+
return $this->client->request(new Action('GetConfig', array('Filename' => $filename, 'Category' => $category)));
9898
}
9999

100100
private function boolParam($value)

src/Client.php

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

33
namespace Clue\React\Ami;
44

5-
use Clue\React\Ami\Protocol\EventMessage;
6-
use Clue\React\Ami\Protocol\ActionRequest;
5+
use Clue\React\Ami\Protocol\Event;
6+
use Clue\React\Ami\Protocol\Action;
77
use Evenement\EventEmitter;
88
use React\Stream\Stream;
99
use Clue\React\Ami\Protocol\Parser;
@@ -40,7 +40,7 @@ public function __construct(Stream $stream, Parser $parser = null)
4040
$this->stream->resume();
4141
}
4242

43-
public function request(ActionRequest $message)
43+
public function request(Action $message)
4444
{
4545
$deferred = new Deferred();
4646

@@ -58,7 +58,7 @@ public function request(ActionRequest $message)
5858

5959
public function handleMessage(Message $message)
6060
{
61-
if ($message instanceof EventMessage) {
61+
if ($message instanceof Event) {
6262
$this->emit('event', array($message));
6363
return;
6464
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Clue\React\Ami\Protocol;
44

5-
class ActionRequest extends Message
5+
class Action extends Message
66
{
77
private $action;
88

src/Protocol/ErrorException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ErrorException extends RuntimeException
88
{
99
private $response;
1010

11-
public function __construct(ActionResponse $response)
11+
public function __construct(Response $response)
1212
{
1313
parent::__construct('Error "' . $response->getPart('Message') . '"');
1414
$this->response = $response;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Clue\React\Ami\Protocol;
44

5-
class EventMessage extends Message
5+
class Event extends Message
66
{
77
private $name;
88

src/Protocol/Parser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ private function parseMessage($message)
6161
$key = key($parts);
6262

6363
if ($key === 'Event') {
64-
return new EventMessage($value, $parts);
64+
return new Event($value, $parts);
6565
}
6666

6767
if ($key === 'Response' && $value === 'Error') {
6868

6969
}
7070

71-
return new ActionResponse($parts);
71+
return new Response($parts);
7272
}
7373

7474
public function clear()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Clue\React\Ami\Protocol;
44

5-
class ActionResponse extends Message
5+
class Response extends Message
66
{
77
public function __construct(array $parts)
88
{

0 commit comments

Comments
 (0)