Home | Trees | Indices | Help |
---|
|
Channel notifications support. Classes and functions to support channel subscriptions and notifications on those channels. Notes: - This code is based on experimental APIs and is subject to change. - Notification does not do deduplication of notification ids, that's up to the receiver. - Storing the Channel between calls is up to the caller. Example setting up a channel: # Create a new channel that gets notifications via webhook. channel = new_webhook_channel("https://example.com/my_web_hook") # Store the channel, keyed by 'channel.id'. Store it before calling the # watch method because notifications may start arriving before the watch # method returns. ... resp = service.objects().watchAll( bucket="some_bucket_id", body=channel.body()).execute() channel.update(resp) # Store the channel, keyed by 'channel.id'. Store it after being updated # since the resource_id value will now be correct, and that's needed to # stop a subscription. ... An example Webhook implementation using webapp2. Note that webapp2 puts headers in a case insensitive dictionary, as headers aren't guaranteed to always be upper case. id = self.request.headers[X_GOOG_CHANNEL_ID] # Retrieve the channel by id. channel = ... # Parse notification from the headers, including validating the id. n = notification_from_headers(channel, self.request.headers) # Do app specific stuff with the notification here. if n.resource_state == 'sync': # Code to handle sync state. elif n.resource_state == 'exists': # Code to handle the exists state. elif n.resource_state == 'not_exists': # Code to handle the not exists state. Example of unsubscribing. service.channels().stop(channel.body())
|
|||
Notification A Notification from a Channel. |
|||
Channel A Channel for notifications. |
|
|||
|
|||
|
|||
|
|
|||
EPOCH = datetime.datetime.utcfromtimestamp(0)
|
|||
CHANNEL_PARAMS = {'address': 'address', 'id': 'id', 'expiratio
|
|||
X_GOOG_CHANNEL_ID = 'X-GOOG-CHANNEL-ID'
|
|||
X_GOOG_MESSAGE_NUMBER = 'X-GOOG-MESSAGE-NUMBER'
|
|||
X_GOOG_RESOURCE_STATE = 'X-GOOG-RESOURCE-STATE'
|
|||
X_GOOG_RESOURCE_URI = 'X-GOOG-RESOURCE-URI'
|
|||
X_GOOG_RESOURCE_ID = 'X-GOOG-RESOURCE-ID'
|
|
Parse a notification from the webhook request headers, validate the notification, and return a Notification object. Args: channel: Channel, The channel that the notification is associated with. headers: dict, A dictionary like object that contains the request headers from the webhook HTTP request. Returns: A Notification object. Raises: errors.InvalidNotificationError if the notification is invalid. ValueError if the X-GOOG-MESSAGE-NUMBER can't be converted to an int. |
Create a new webhook Channel. Args: url: str, URL to post notifications to. token: str, An arbitrary string associated with the channel that is delivered to the target address with each notification delivered over this channel. expiration: datetime.datetime, A time in the future when the channel should expire. Can also be None if the subscription should use the default expiration. Note that different services may have different limits on how long a subscription lasts. Check the response from the watch() method to see the value the service has set for an expiration time. params: dict, Extra parameters to pass on channel creation. Currently not used for webhook channels.
|
|
CHANNEL_PARAMS
|
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Mon Jun 5 13:38:39 2017 | http://epydoc.sourceforge.net |