summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/google_settings/settings.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2013-01-21 02:34:22 -0800
committerLance Stout <lancestout@gmail.com>2013-01-21 02:34:22 -0800
commitbad405bea96405eb952888dc6996b8b40be85ac4 (patch)
treeb5998707d5d8d836eaa807f1e755047c1aed5c48 /sleekxmpp/plugins/google_settings/settings.py
parent648f3f978a84445ed188be055453ac4cab3ed4f5 (diff)
parent4f9a95b011277ab64a137aceeb4df2e9fc0f1e25 (diff)
downloadslixmpp-bad405bea96405eb952888dc6996b8b40be85ac4.tar.gz
slixmpp-bad405bea96405eb952888dc6996b8b40be85ac4.tar.bz2
slixmpp-bad405bea96405eb952888dc6996b8b40be85ac4.tar.xz
slixmpp-bad405bea96405eb952888dc6996b8b40be85ac4.zip
Merge branch 'master' into develop
Diffstat (limited to 'sleekxmpp/plugins/google_settings/settings.py')
-rw-r--r--sleekxmpp/plugins/google_settings/settings.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/sleekxmpp/plugins/google_settings/settings.py b/sleekxmpp/plugins/google_settings/settings.py
new file mode 100644
index 00000000..6bd209c7
--- /dev/null
+++ b/sleekxmpp/plugins/google_settings/settings.py
@@ -0,0 +1,68 @@
+"""
+ SleekXMPP: The Sleek XMPP Library
+ Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout
+ This file is part of SleekXMPP.
+
+ See the file LICENSE for copying permission.
+"""
+
+import logging
+
+from sleekxmpp.stanza import Iq
+from sleekxmpp.xmlstream.handler import Callback
+from sleekxmpp.xmlstream.matcher import StanzaPath
+from sleekxmpp.xmlstream import register_stanza_plugin
+from sleekxmpp.plugins import BasePlugin
+from sleekxmpp.plugins.google_settings import stanza
+
+
+log = logging.getLogger(__name__)
+
+
+class GoogleSettings(BasePlugin):
+
+ """
+ Google: Gmail Notifications
+
+ Also see <https://developers.google.com/talk/jep_extensions/usersettings>.
+ """
+
+ name = 'google_settings'
+ description = 'Google: User Settings'
+ dependencies = set()
+ stanza = stanza
+
+ def plugin_init(self):
+ register_stanza_plugin(Iq, stanza.UserSettings)
+
+ self.xmpp.register_handler(
+ Callback('Google Settings',
+ StanzaPath('iq@type=set/google_settings'),
+ self._handle_settings_change))
+
+ def plugin_end(self):
+ self.xmpp.remove_handler('Google Settings')
+
+ def get(self, block=True, timeout=None, callback=None):
+ iq = self.xmpp.Iq()
+ iq['type'] = 'get'
+ iq.enable('google_settings')
+ return iq.send(block=block, timeout=timeout, callback=callback)
+
+ def update(self, settings, block=True, timeout=None, callback=None):
+ iq = self.xmpp.Iq()
+ iq['type'] = 'set'
+ iq.enable('google_settings')
+
+ for setting, value in settings.items():
+ iq['google_settings'][setting] = value
+
+ return iq.send(block=block, timeout=timeout, callback=callback)
+
+ def _handle_settings_change(self, iq):
+ reply = self.xmpp.Iq()
+ reply['type'] = 'result'
+ reply['id'] = iq['id']
+ reply['to'] = iq['from']
+ reply.send()
+ self.xmpp.event('google_settings_change', iq)