Skip to content
This repository has been archived by the owner on Feb 20, 2022. It is now read-only.

Commit

Permalink
Added Installation channel modification so that account holders can m…
Browse files Browse the repository at this point in the history
…anually add/remove subscriptions of users on their application
  • Loading branch information
arahayrabedian committed Jan 28, 2015
1 parent ba9b2f6 commit 4a6bb30
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions parse_rest/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,35 @@
class Installation(ParseResource):
ENDPOINT_ROOT = '/'.join([API_ROOT, 'installations'])

@classmethod
def _get_installation_url(cls, installation_id):
"""
Get the URL for RESTful operations on this particular installation
"""
return '/'.join([cls.ENDPOINT_ROOT, installation_id])

@classmethod
def update_channels(cls, installation_id, channels_to_add=set(),
channels_to_remove=set(), **kw):
"""
Allow an application to manually subscribe or unsubscribe an
installation to a certain push channel in a unified operation.
this is based on:
https://www.parse.com/docs/rest#installations-updating
installation_id: the installation id you'd like to add a channel to
channels_to_add: the name of the channel you'd like to subscribe the user to
channels_to_remove: the name of the channel you'd like to unsubscribe the user from
"""
installation_url = cls._get_installation_url(installation_id)
current_config = cls.GET(installation_url)

new_channels = list(set(current_config['channels']).union(channels_to_add).difference(channels_to_remove))

cls.PUT(installation_url, channels=new_channels)


class Push(ParseResource):
ENDPOINT_ROOT = '/'.join([API_ROOT, 'push'])
Expand Down

0 comments on commit 4a6bb30

Please sign in to comment.