|
|
@@ -14,7 +14,7 @@ class Pusher implements LoggerAwareInterface
|
|
|
/**
|
|
|
* @var string Version
|
|
|
*/
|
|
|
- public static $VERSION = '3.3.1';
|
|
|
+ public static $VERSION = '4.1.1';
|
|
|
|
|
|
/**
|
|
|
* @var null|PusherCrypto
|
|
|
@@ -27,6 +27,7 @@ class Pusher implements LoggerAwareInterface
|
|
|
private $settings = array(
|
|
|
'scheme' => 'http',
|
|
|
'port' => 80,
|
|
|
+ 'path' => '',
|
|
|
'timeout' => 30,
|
|
|
'debug' => false,
|
|
|
'curl_options' => array(),
|
|
|
@@ -87,10 +88,12 @@ class Pusher implements LoggerAwareInterface
|
|
|
}
|
|
|
|
|
|
$this->settings['host'] = $host;
|
|
|
+ $this->settings['path'] = '';
|
|
|
|
|
|
$this->log('Legacy $host parameter provided: {scheme} host: {host}', array(
|
|
|
'scheme' => $this->settings['scheme'],
|
|
|
'host' => $this->settings['host'],
|
|
|
+ 'path' => $this->settings['path'],
|
|
|
));
|
|
|
}
|
|
|
|
|
|
@@ -297,8 +300,8 @@ class Pusher implements LoggerAwareInterface
|
|
|
/**
|
|
|
* Utility function used to create the curl object with common settings.
|
|
|
*
|
|
|
- * @param string $domain
|
|
|
- * @param string $s_url
|
|
|
+ * @param string $url_prefix
|
|
|
+ * @param string $path
|
|
|
* @param string [optional] $request_method
|
|
|
* @param array [optional] $query_params
|
|
|
*
|
|
|
@@ -306,18 +309,18 @@ class Pusher implements LoggerAwareInterface
|
|
|
*
|
|
|
* @return resource
|
|
|
*/
|
|
|
- private function create_curl($domain, $s_url, $request_method = 'GET', $query_params = array())
|
|
|
+ private function create_curl($url_prefix, $path, $request_method = 'GET', $query_params = array())
|
|
|
{
|
|
|
// Create the signed signature...
|
|
|
$signed_query = self::build_auth_query_string(
|
|
|
$this->settings['auth_key'],
|
|
|
$this->settings['secret'],
|
|
|
$request_method,
|
|
|
- $s_url,
|
|
|
+ $path,
|
|
|
$query_params
|
|
|
);
|
|
|
|
|
|
- $full_url = $domain.$s_url.'?'.$signed_query;
|
|
|
+ $full_url = $url_prefix.$path.'?'.$signed_query;
|
|
|
|
|
|
$this->log('create_curl( {full_url} )', array('full_url' => $full_url));
|
|
|
|
|
|
@@ -390,23 +393,23 @@ class Pusher implements LoggerAwareInterface
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Build the notification domain.
|
|
|
+ * Build the notification url prefix.
|
|
|
*
|
|
|
* @return string
|
|
|
*/
|
|
|
- private function notification_domain()
|
|
|
+ private function notification_url_prefix()
|
|
|
{
|
|
|
return $this->settings['notification_scheme'].'://'.$this->settings['notification_host'];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Build the Channels domain.
|
|
|
+ * Build the Channels url prefix.
|
|
|
*
|
|
|
* @return string
|
|
|
*/
|
|
|
- private function channels_domain()
|
|
|
+ private function channels_url_prefix()
|
|
|
{
|
|
|
- return $this->settings['scheme'].'://'.$this->settings['host'].':'.$this->settings['port'];
|
|
|
+ return $this->settings['scheme'].'://'.$this->settings['host'].':'.$this->settings['port'].$this->settings['path'];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -517,7 +520,7 @@ class Pusher implements LoggerAwareInterface
|
|
|
|
|
|
$query_params = array();
|
|
|
|
|
|
- $s_url = $this->settings['base_path'].'/events';
|
|
|
+ $path = $this->settings['base_path'].'/events';
|
|
|
|
|
|
// json_encode might return false on failure
|
|
|
if (!$data_encoded) {
|
|
|
@@ -539,7 +542,7 @@ class Pusher implements LoggerAwareInterface
|
|
|
|
|
|
$query_params['body_md5'] = md5($post_value);
|
|
|
|
|
|
- $ch = $this->create_curl($this->channels_domain(), $s_url, 'POST', $query_params);
|
|
|
+ $ch = $this->create_curl($this->channels_url_prefix(), $path, 'POST', $query_params);
|
|
|
|
|
|
$this->log('trigger POST: {post_value}', compact('post_value'));
|
|
|
|
|
|
@@ -595,9 +598,9 @@ class Pusher implements LoggerAwareInterface
|
|
|
|
|
|
$query_params = array();
|
|
|
$query_params['body_md5'] = md5($post_value);
|
|
|
- $s_url = $this->settings['base_path'].'/batch_events';
|
|
|
+ $path = $this->settings['base_path'].'/batch_events';
|
|
|
|
|
|
- $ch = $this->create_curl($this->channels_domain(), $s_url, 'POST', $query_params);
|
|
|
+ $ch = $this->create_curl($this->channels_url_prefix(), $path, 'POST', $query_params);
|
|
|
|
|
|
$this->log('trigger POST: {post_value}', compact('post_value'));
|
|
|
|
|
|
@@ -662,6 +665,26 @@ class Pusher implements LoggerAwareInterface
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Fetch user ids currently subscribed to a presence channel.
|
|
|
+ *
|
|
|
+ * @param string $channel The name of the channel
|
|
|
+ *
|
|
|
+ * @throws PusherException Throws exception if curl wasn't initialized correctly
|
|
|
+ *
|
|
|
+ * @return array|bool
|
|
|
+ */
|
|
|
+ public function get_users_info($channel)
|
|
|
+ {
|
|
|
+ $response = $this->get('/channels/'.$channel.'/users');
|
|
|
+
|
|
|
+ if ($response['status'] === 200) {
|
|
|
+ return json_decode($response['body']);
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* GET arbitrary REST API resource using a synchronous http client.
|
|
|
* All request signing is handled automatically.
|
|
|
@@ -675,9 +698,9 @@ class Pusher implements LoggerAwareInterface
|
|
|
*/
|
|
|
public function get($path, $params = array())
|
|
|
{
|
|
|
- $s_url = $this->settings['base_path'].$path;
|
|
|
+ $path = $this->settings['base_path'].$path;
|
|
|
|
|
|
- $ch = $this->create_curl($this->channels_domain(), $s_url, 'GET', $params);
|
|
|
+ $ch = $this->create_curl($this->channels_url_prefix(), $path, 'GET', $params);
|
|
|
|
|
|
$response = $this->exec_curl($ch);
|
|
|
|
|
|
@@ -781,8 +804,8 @@ class Pusher implements LoggerAwareInterface
|
|
|
|
|
|
$query_params['body_md5'] = md5($post_value);
|
|
|
|
|
|
- $notification_path = '/server_api/v1'.$this->settings['base_path'].'/notifications';
|
|
|
- $ch = $this->create_curl($this->notification_domain(), $notification_path, 'POST', $query_params);
|
|
|
+ $path = '/server_api/v1'.$this->settings['base_path'].'/notifications';
|
|
|
+ $ch = $this->create_curl($this->notification_url_prefix(), $path, 'POST', $query_params);
|
|
|
|
|
|
$this->log('trigger POST (Native notifications): {post_value}', compact('post_value'));
|
|
|
|