-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c78612a
commit 49d2fb0
Showing
21 changed files
with
484 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<?php | ||
|
||
namespace PubNub\Endpoints\PubSub; | ||
|
||
use PubNub\Endpoints\Endpoint; | ||
use PubNub\Enums\PNHttpMethod; | ||
use PubNub\Enums\PNOperationType; | ||
use PubNub\Exceptions\PubNubBuildRequestException; | ||
use PubNub\Exceptions\PubNubValidationException; | ||
use PubNub\Models\Consumer\PubSub\PNSignalResult; | ||
use PubNub\PubNubUtil; | ||
|
||
class Signal extends Endpoint | ||
{ | ||
const SIGNAL_PATH = "/signal/%s/%s/0/%s/0/%s"; | ||
|
||
/** @var mixed $message to send the signal */ | ||
protected $message; | ||
|
||
/** @var string $channel to send message on*/ | ||
protected $channel; | ||
|
||
/** | ||
* @param mixed $message | ||
* @return $this | ||
*/ | ||
public function message($message) | ||
{ | ||
$this->message = $message; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $channel | ||
* @return $this | ||
*/ | ||
public function channel($channel) | ||
{ | ||
$this->channel = $channel; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @throws PubNubValidationException | ||
*/ | ||
protected function validateParams() | ||
{ | ||
if ($this->message === null) { | ||
throw new PubNubValidationException("Message Missing"); | ||
} | ||
|
||
if (!is_string($this->channel) || strlen($this->channel) === 0) { | ||
throw new PubNubValidationException("Channel Missing"); | ||
} | ||
|
||
$this->validateSubscribeKey(); | ||
$this->validatePublishKey(); | ||
} | ||
|
||
/** | ||
* @return string | ||
* @throws PubNubBuildRequestException | ||
*/ | ||
protected function buildPath() | ||
{ | ||
$stringifiedMessage = PubNubUtil::writeValueAsString($this->message); | ||
|
||
return sprintf( | ||
static::SIGNAL_PATH, | ||
$this->pubnub->getConfiguration()->getPublishKey(), | ||
$this->pubnub->getConfiguration()->getSubscribeKey(), | ||
PubNubUtil::urlEncode($this->channel), | ||
$stringifiedMessage | ||
); | ||
} | ||
|
||
|
||
protected function buildData() | ||
{ | ||
return []; | ||
} | ||
|
||
protected function customParams() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* @return PNPublishResult | ||
*/ | ||
public function sync() | ||
{ | ||
return parent::sync(); | ||
} | ||
|
||
/** | ||
* @param array $json Decoded json | ||
* @return PNPublishResult | ||
*/ | ||
protected function createResponse($json) | ||
{ | ||
$timetoken = floatval($json[2]); | ||
|
||
return new PNSignalResult($timetoken); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
protected function isAuthRequired() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
protected function getRequestTimeout() | ||
{ | ||
return $this->pubnub->getConfiguration()->getNonSubscribeRequestTimeout(); | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
protected function getConnectTimeout() | ||
{ | ||
return $this->pubnub->getConfiguration()->getConnectTimeout(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function httpMethod() | ||
{ | ||
return PNHttpMethod::GET; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
protected function getOperationType() | ||
{ | ||
return PNOperationType::PNSignalOperation; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getName() | ||
{ | ||
return "Signal"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.