Skip to content

Commit

Permalink
watch();
Browse files Browse the repository at this point in the history
  • Loading branch information
francis94c committed Aug 28, 2019
1 parent 7e52fc2 commit 3e41fe6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
34 changes: 34 additions & 0 deletions libraries/GMail.php
Expand Up @@ -100,6 +100,40 @@ public function getProfile(string $user='me'):?array {
if ($response !== false) return $this->process_response($code, $response);
return null;
}
/**
* [watch Causes push notifications to be sent on events which occur in the
* user's mailbox. Requires Google Cloud PubSub.
* see https://developers.google.com/gmail/api/v1/reference/users/watch]
* @param string $topic Topic to push events to.
* @param string $userId The ID/Email address of the user whose
* mailbox event, are being listened to.
* @param mixed $labelIds Narrow down labels in the mailbox, whose
* [string|int] events are to be listened to.
* @param string $labelFilterAction [description]
* @return [type] [description]
*/
public function watch(string $topic, string $userId='me', mixed $labelIds=null, string $labelFilterAction='include'):?array {
$body = [
'topicName' => $topic,
'labelFilterAction' => $labelFilterAction
];

if ($labelIds != null) {
if (is_scalar($labelIds)) {
$body['labelIds'] = [$labelIds];
} elseif (is_array($labelIds)) {
$body['labelIds'] = $labelIds;
}
}

list($code, $response) = (new GMailCURL(GMailCURL::POST))(
self::API . "$userId/watch",
["Authorization: Bearer $this->token"],
$body
);
if ($response !== false)$this->process_response($code, $response);
return null;
}
/**
* [process_response description]
* @param int $code [description]
Expand Down
7 changes: 7 additions & 0 deletions libraries/GMailLabels.php
@@ -0,0 +1,7 @@
<?php
declare(strict_types=1);
defined('BASEPATH') OR exit('No direct script access allowed');

class GMailLabels {
const INBOX = 'INBOX';
}

0 comments on commit 3e41fe6

Please sign in to comment.