fogproject  1.5.9
About: FOG is a Linux-based network computer cloning solution for Windows, Mac OSX and various Linux distributions that ties together a few open-source tools with a PHP-based web interface. FOG doesn’t use any boot disks, or CDs; everything is done via TFTP and PXE.
  Fossies Dox: fogproject-1.5.9.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

pushbullethandler.class.php
Go to the documentation of this file.
1 <?php
25 {
26  private $_apiKey;
27  private $_curlCallback;
28  const URL_PUSHES
29  = 'https://api.pushbullet.com/v2/pushes';
31  = 'https://api.pushbullet.com/v2/devices';
33  = 'https://api.pushbullet.com/v2/contacts';
35  = 'https://api.pushbullet.com/v2/upload-request';
36  const URL_USERS
37  = 'https://api.pushbullet.com/v2/users';
39  = 'https://api.pushbullet.com/v2/subscriptions';
41  = 'https://api.pushbullet.com/v2/channel-info';
43  = 'https://api.pushbullet.com/v2/ephemerals';
51  public function __construct($apiKey)
52  {
53  $this->_apiKey = $apiKey;
54  if (!function_exists('curl_init')) {
55  throw new PushbulletException(
56  'cURL library is not loaded.'
57  );
58  }
59  }
70  public function pushNote(
71  $recipient,
72  $title,
73  $body = null
74  ) {
75  $data = array();
77  $recipient,
78  $data
79  );
80  $data['type'] = 'note';
81  $data['title'] = $title;
82  $data['body'] = $body;
83  return $this->_curlRequest(
84  self::URL_PUSHES,
85  'POST',
86  $data
87  );
88  }
100  public function pushLink(
101  $recipient,
102  $title,
103  $url,
104  $body = null
105  ) {
106  $data = array();
108  $recipient,
109  $data
110  );
111  $data['type'] = 'link';
112  $data['title'] = $title;
113  $data['url'] = $url;
114  $data['body'] = $body;
115  return $this->_curlRequest(
116  self::URL_PUSHES,
117  'POST',
118  $data
119  );
120  }
131  public function pushAddress(
132  $recipient,
133  $name,
134  $address
135  ) {
136  $data = array();
138  $recipient,
139  $data
140  );
141  $data['type'] = 'address';
142  $data['name'] = $name;
143  $data['address'] = $address;
144  return $this->_curlRequest(
145  self::URL_PUSHES,
146  'POST',
147  $data
148  );
149  }
160  public function pushList(
161  $recipient,
162  $title,
163  array $items
164  ) {
165  $data = array();
167  $recipient,
168  $data
169  );
170  $data['type'] = 'list';
171  $data['title'] = $title;
172  $data['items'] = $items;
173  return $this->_curlRequest(
174  self::URL_PUSHES,
175  'POST',
176  $data
177  );
178  }
195  public function pushFile(
196  $recipient,
197  $filePath,
198  $mimeType = null,
199  $title = null,
200  $body = null,
201  $altFileName = null
202  ) {
203  $data = array();
204  $fullFilePath = realpath($filePath);
205  if (!is_readable($fullFilePath)) {
206  throw new PushbulletException(
207  'File: File does not exist or is unreadable.'
208  );
209  }
210  if (self::getFilesize($fullFilePath) > 25 * 1024 * 1024) {
211  throw new PushbulletException(
212  'File: File size exceeds 25 MB.'
213  );
214  }
215  $data['file_name'] = $altFileName === null ?
216  basename($fullFilePath) :
217  $altFileName;
218  // Try to guess the MIME type if the argument is NULL
219  $data['file_type'] = $mimeType === null ?
220  mime_content_type($fullFilePath) :
221  $mimeType;
222  // Request authorization to upload the file
223  $response = $this->_curlRequest(
224  self::URL_UPLOAD_REQUEST,
225  'GET',
226  $data
227  );
228  $data['file_url'] = $response->file_url;
229  if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
230  $response->data->file = new CURLFile($fullFilePath);
231  } else {
232  $response->data->file = '@' . $fullFilePath;
233  }
234  // Upload the file
235  $this->_curlRequest(
236  $response->upload_url,
237  'POST',
238  $response->data,
239  false,
240  false
241  );
243  $recipient,
244  $data
245  );
246  $data['type'] = 'file';
247  $data['title'] = $title;
248  $data['body'] = $body;
249  return $this->_curlRequest(
250  self::URL_PUSHES,
251  'POST',
252  $data
253  );
254  }
269  public function getPushHistory(
270  $modifiedAfter = 0,
271  $cursor = null,
272  $limit = null
273  ) {
274  $data = array();
275  $data['modified_after'] = $modifiedAfter;
276  if ($cursor !== null) {
277  $data['cursor'] = $cursor;
278  }
279  if ($limit !== null) {
280  $data['limit'] = $limit;
281  }
282  return $this->_curlRequest(
283  self::URL_PUSHES,
284  'GET',
285  $data
286  );
287  }
296  public function dismissPush($pushIden)
297  {
298  return $this->_curlRequest(
299  self::URL_PUSHES . '/' . $pushIden,
300  'POST',
301  array('dismissed' => true)
302  );
303  }
312  public function deletePush($pushIden)
313  {
314  return $this->_curlRequest(
315  self::URL_PUSHES . '/' . $pushIden,
316  'DELETE'
317  );
318  }
333  public function getDevices(
334  $modifiedAfter = 0,
335  $cursor = null,
336  $limit = null
337  ) {
338  $data = array();
339  $data['modified_after'] = $modifiedAfter;
340  if ($cursor !== null) {
341  $data['cursor'] = $cursor;
342  }
343  if ($limit !== null) {
344  $data['limit'] = $limit;
345  }
346  return $this->_curlRequest(
347  self::URL_DEVICES,
348  'GET',
349  $data
350  );
351  }
360  public function deleteDevice($deviceIden)
361  {
362  return $this->_curlRequest(
363  self::URL_DEVICES . '/' . $deviceIden,
364  'DELETE'
365  );
366  }
376  public function createContact($name, $email)
377  {
378  if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
379  throw new PushbulletException(
380  'Create contact: Invalid email address.'
381  );
382  }
383  $queryData = array(
384  'name' => $name,
385  'email' => $email
386  );
387  return $this->_curlRequest(
388  self::URL_CONTACTS,
389  'POST',
390  $queryData
391  );
392  }
407  public function getContacts(
408  $modifiedAfter = 0,
409  $cursor = null,
410  $limit = null
411  ) {
412  $data = array();
413  $data['modified_after'] = $modifiedAfter;
414  if ($cursor !== null) {
415  $data['cursor'] = $cursor;
416  }
417  if ($limit !== null) {
418  $data['limit'] = $limit;
419  }
420  return $this->_curlRequest(
421  self::URL_CONTACTS,
422  'GET',
423  $data
424  );
425  }
435  public function updateContact($contactIden, $name)
436  {
437  return $this->_curlRequest(
438  self::URL_CONTACTS . '/' . $contactIden,
439  'POST',
440  array('name' => $name)
441  );
442  }
451  public function deleteContact($contactIden)
452  {
453  return $this->_curlRequest(
454  self::URL_CONTACTS . '/' . $contactIden,
455  'DELETE'
456  );
457  }
464  public function getUserInformation()
465  {
466  return $this->_curlRequest(self::URL_USERS . '/me', 'GET');
467  }
476  public function updateUserPreferences($preferences)
477  {
478  return $this->_curlRequest(
479  self::URL_USERS . '/me',
480  'POST',
481  array('preferences' => $preferences)
482  );
483  }
492  public function subscribeToChannel($channelTag)
493  {
494  return $this->_curlRequest(
495  self::URL_SUBSCRIPTIONS,
496  'POST',
497  array('channel_tag' => $channelTag)
498  );
499  }
506  public function getSubscriptions()
507  {
508  return $this->_curlRequest(self::URL_SUBSCRIPTIONS, 'GET');
509  }
518  public function unsubscribeFromChannel($channelIden)
519  {
520  return $this->_curlRequest(
521  self::URL_SUBSCRIPTIONS . '/' . $channelIden,
522  'DELETE'
523  );
524  }
533  public function getChannelInformation($channelTag)
534  {
535  return $this->_curlRequest(
536  self::URL_CHANNEL_INFO,
537  'GET',
538  array('tag' => $channelTag)
539  );
540  }
555  public function sendSms($fromDeviceIden, $toNumber, $message)
556  {
557  $data = array(
558  'type' => 'push',
559  'push' => array(
560  'type' => 'messaging_extension_reply',
561  'package_name' => 'com.pushbullet.android',
562  'source_user_iden' => $this->getUserInformation()->iden,
563  'target_device_iden' => $fromDeviceIden,
564  'conversation_iden' => $toNumber,
565  'message' => $message
566  ));
567 
568  return $this->_curlRequest(self::URL_EPHEMERALS, 'POST', $data, true, true);
569  }
578  public function addCurlCallback(callable $callback)
579  {
580  $this->_curlCallback = $callback;
581  }
591  private static function _parseRecipient($recipient, array &$data)
592  {
593  if (!empty($recipient)) {
594  if (filter_var($recipient, FILTER_VALIDATE_EMAIL) !== false) {
595  $data[email] = $recipient;
596  } else {
597  if (substr($recipient, 0, 1) == "#") {
598  $data[channel_tag] = substr($recipient, 1);
599  } else {
600  $data[device_iden] = $recipient;
601  }
602  }
603  }
604  }
617  private function _curlRequest(
618  $url,
619  $method,
620  $data = null,
621  $sendAsJSON = false,
622  $auth = true
623  ) {
624  $data = self::$FOGURLRequests->process(
625  $url,
626  $method,
627  $data,
628  $sendAsJSON,
629  (
630  $auth ?
631  $this->_apiKey :
632  false
633  ),
634  $this->_curlCallback
635  );
636  return json_decode($data[0]);
637  }
638 }
PushbulletHandler
Definition: pushbullethandler.class.php:25
PushbulletHandler\getUserInformation
getUserInformation()
Definition: pushbullethandler.class.php:464
PushbulletHandler\subscribeToChannel
subscribeToChannel($channelTag)
Definition: pushbullethandler.class.php:492
$response
$response
Definition: logtoview.php:185
PushbulletException
Definition: pushbulletexception.class.php:25
PushbulletHandler\updateContact
updateContact($contactIden, $name)
Definition: pushbullethandler.class.php:435
PushbulletHandler\createContact
createContact($name, $email)
Definition: pushbullethandler.class.php:376
PushbulletHandler\updateUserPreferences
updateUserPreferences($preferences)
Definition: pushbullethandler.class.php:476
PushbulletHandler\addCurlCallback
addCurlCallback(callable $callback)
Definition: pushbullethandler.class.php:578
PushbulletHandler\getChannelInformation
getChannelInformation($channelTag)
Definition: pushbullethandler.class.php:533
PushbulletHandler\getPushHistory
getPushHistory( $modifiedAfter=0, $cursor=null, $limit=null)
Definition: pushbullethandler.class.php:269
PushbulletHandler\pushList
pushList( $recipient, $title, array $items)
Definition: pushbullethandler.class.php:160
PushbulletHandler\dismissPush
dismissPush($pushIden)
Definition: pushbullethandler.class.php:296
$items
$items
Definition: boot.php:24
PushbulletHandler\sendSms
sendSms($fromDeviceIden, $toNumber, $message)
Definition: pushbullethandler.class.php:555
PushbulletHandler\deleteContact
deleteContact($contactIden)
Definition: pushbullethandler.class.php:451
PushbulletHandler\pushNote
pushNote( $recipient, $title, $body=null)
Definition: pushbullethandler.class.php:70
PushbulletHandler\_parseRecipient
static _parseRecipient($recipient, array &$data)
Definition: pushbullethandler.class.php:591
PushbulletHandler\$_apiKey
$_apiKey
Definition: pushbullethandler.class.php:26
PushbulletHandler\deleteDevice
deleteDevice($deviceIden)
Definition: pushbullethandler.class.php:360
PushbulletHandler\getContacts
getContacts( $modifiedAfter=0, $cursor=null, $limit=null)
Definition: pushbullethandler.class.php:407
PushbulletHandler\URL_CONTACTS
const URL_CONTACTS
Definition: pushbullethandler.class.php:33
Pushbullet
Definition: pushbullet.class.php:25
PushbulletHandler\pushAddress
pushAddress( $recipient, $name, $address)
Definition: pushbullethandler.class.php:131
PushbulletHandler\URL_CHANNEL_INFO
const URL_CHANNEL_INFO
Definition: pushbullethandler.class.php:41
PushbulletHandler\getDevices
getDevices( $modifiedAfter=0, $cursor=null, $limit=null)
Definition: pushbullethandler.class.php:333
PushbulletHandler\deletePush
deletePush($pushIden)
Definition: pushbullethandler.class.php:312
FOGController\$data
$data
Definition: fogcontroller.class.php:35
PushbulletHandler\_curlRequest
_curlRequest( $url, $method, $data=null, $sendAsJSON=false, $auth=true)
Definition: pushbullethandler.class.php:617
PushbulletHandler\URL_UPLOAD_REQUEST
const URL_UPLOAD_REQUEST
Definition: pushbullethandler.class.php:35
PushbulletHandler\pushLink
pushLink( $recipient, $title, $url, $body=null)
Definition: pushbullethandler.class.php:100
PushbulletHandler\URL_USERS
const URL_USERS
Definition: pushbullethandler.class.php:37
PushbulletHandler\getSubscriptions
getSubscriptions()
Definition: pushbullethandler.class.php:506
PushbulletHandler\unsubscribeFromChannel
unsubscribeFromChannel($channelIden)
Definition: pushbullethandler.class.php:518
PushbulletHandler\pushFile
pushFile( $recipient, $filePath, $mimeType=null, $title=null, $body=null, $altFileName=null)
Definition: pushbullethandler.class.php:195
$url
$url
Definition: kernelvers.php:27
PushbulletHandler\URL_DEVICES
const URL_DEVICES
Definition: pushbullethandler.class.php:31
PushbulletHandler\$_curlCallback
$_curlCallback
Definition: pushbullethandler.class.php:27
PushbulletHandler\__construct
__construct($apiKey)
Definition: pushbullethandler.class.php:51
PushbulletHandler\URL_PUSHES
const URL_PUSHES
Definition: pushbullethandler.class.php:29
PushbulletHandler\URL_EPHEMERALS
const URL_EPHEMERALS
Definition: pushbullethandler.class.php:43
PushbulletHandler\URL_SUBSCRIPTIONS
const URL_SUBSCRIPTIONS
Definition: pushbullethandler.class.php:39