Commit ee41857a authored by hupantingxue's avatar hupantingxue

Add tags server sample;

parent 99517e92
import jpush as jpush
from conf import app_key, master_secret
_jpush = jpush.JPush(app_key, master_secret)
device = _jpush.create_device()
alias = "alias1"
platform = "android,ios"
device.get_aliasuser(alias, platform)
...@@ -3,5 +3,6 @@ from conf import app_key, master_secret ...@@ -3,5 +3,6 @@ from conf import app_key, master_secret
_jpush = jpush.JPush(app_key, master_secret) _jpush = jpush.JPush(app_key, master_secret)
device = _jpush.create_device() device = _jpush.create_device()
reg_id = '090c1f59f89' alias = "alias1"
device.get_deviceinfo(reg_id) platform = "android,ios"
device.delete_alias(alias, platform)
#-*- encoding:utf-8 -*-
import jpush as jpush import jpush as jpush
from conf import app_key, master_secret from conf import app_key, master_secret
_jpush = jpush.JPush(app_key, master_secret) _jpush = jpush.JPush(app_key, master_secret)
device = _jpush.create_device() device = _jpush.create_device()
device.delete_tag(tag) tag = "ddd"
platform = "android,ios"
device.delete_tag(tag, platform)
...@@ -3,4 +3,6 @@ from conf import app_key, master_secret ...@@ -3,4 +3,6 @@ from conf import app_key, master_secret
_jpush = jpush.JPush(app_key, master_secret) _jpush = jpush.JPush(app_key, master_secret)
device = _jpush.create_device() device = _jpush.create_device()
device.get_taglist() tag = "ddd"
registration_id = '090c1f59f89'
device.check_taguserexist(tag, registration_id)
...@@ -3,4 +3,6 @@ from conf import app_key, master_secret ...@@ -3,4 +3,6 @@ from conf import app_key, master_secret
_jpush = jpush.JPush(app_key, master_secret) _jpush = jpush.JPush(app_key, master_secret)
device = _jpush.create_device() device = _jpush.create_device()
device.get_taglist() tag = "ddd"
entity = jpush.device_regid(jpush.add("090c1f59f89"))
device.update_tagusers(tag, entity)
...@@ -48,16 +48,57 @@ class Device(object): ...@@ -48,16 +48,57 @@ class Device(object):
info = self.send("POST", url, body) info = self.send("POST", url, body)
print info print info
def delete_tag(self, tag, platform=None):
def delete_tag(self, registration_id, tag):
"""Delete registration id tag. """Delete registration id tag.
""" """
url = common.DEVICE_URL + registration_id + "/" url = common.TAG_URL + tag + "/"
body = None
if platform:
body = platform
print url, body
info = self.send("DELETE", url, body)
print info
def update_tagusers(self, tag, entity):
"""Add/Remove specified tag users.
"""
url = common.TAG_URL + tag + "/"
body = json.dumps(entity) body = json.dumps(entity)
print url, body print url, body
info = self.send("POST", url, body) info = self.send("POST", url, body)
print info print info
def check_taguserexist(self, tag, registration_id):
"""Check registration id whether in tag.
"""
url = common.TAG_URL + tag + "/exist/"
body = registration_id
print url, registration_id
info = self.send("GET", url, body)
print info
def delete_alias(self, alias, platform=None):
"""Delete appkey alias.
"""
url = common.ALIAS_URL + alias + "/"
body = None
if platform:
body = platform
print url, body
info = self.send("DELETE", url, body)
print info
def get_aliasuser(self, alias, platform=None):
"""Get appkey alias users.
"""
url = common.ALIAS_URL + alias + "/"
body = None
if platform:
body = platform
print url, body
info = self.send("GET", url, body)
print info
class DeviceResponse(object): class DeviceResponse(object):
"""Response to a successful device request send. """Response to a successful device request send.
......
...@@ -75,22 +75,22 @@ def device_regid(*types): ...@@ -75,22 +75,22 @@ def device_regid(*types):
"""Get a registration_id object """Get a registration_id object
>>> device_regid("") >>> device_regid("")
{'registration_id': ''} {'registration_ids': ''}
>>> device_regid("registration_id1") >>> device_regid("registration_id1")
{'registration_id': 'registration_id1'} {'registration_ids': 'registration_id1'}
>>> device_regid(add("registration_id1", "registration_id2"), remove("registration_id3", "registration_id4")) >>> device_regid(add("registration_id1", "registration_id2"), remove("registration_id3", "registration_id4"))
{'registration_id': {'add': ['registration_id1', 'registration_id2'], 'remove': ['registration_id3', 'registration_id4']}} {'registration_ids': {'add': ['registration_id1', 'registration_id2'], 'remove': ['registration_id3', 'registration_id4']}}
""" """
registration_id = {} registration_id = {}
if 1 == len(types) and isinstance(types[0], (str, unicode)): if 1 == len(types) and isinstance(types[0], (str, unicode)):
registration_id["registration_id"] = types[0] registration_id["registration_ids"] = types[0]
return registration_id return registration_id
registration_id["registration_id"] = {} registration_id["registration_ids"] = {}
for t in types: for t in types:
for key in t: for key in t:
if key not in ('add', 'remove'): if key not in ('add', 'remove'):
raise ValueError("Invalid registration_id '%s'" % t) raise ValueError("Invalid registration_id '%s'" % t)
registration_id["registration_id"][key] = t[key] registration_id["registration_ids"][key] = t[key]
return registration_id return registration_id
if "__main__" == __name__: if "__main__" == __name__:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment