Commit 99517e92 authored by hupantingxue's avatar hupantingxue

Add device api sample;

parent cf31124d
app_key = u'dd1066407b044738b6479275'
master_secret = u'2b38ce69b1de2a7fa95706ea'
import jpush as jpush
from conf import app_key, master_secret
_jpush = jpush.JPush(app_key, master_secret)
device = _jpush.create_device()
reg_id = '090c1f59f89'
entity = jpush.device_tag("")
device.set_deviceinfo(reg_id, entity)
import jpush as jpush
from conf import app_key, master_secret
_jpush = jpush.JPush(app_key, master_secret)
device = _jpush.create_device()
reg_id = '090c1f59f89'
device.get_deviceinfo(reg_id)
import jpush as jpush
from conf import app_key, master_secret
_jpush = jpush.JPush(app_key, master_secret)
device = _jpush.create_device()
device.delete_tag(tag)
import jpush as jpush
from conf import app_key, master_secret
_jpush = jpush.JPush(app_key, master_secret)
device = _jpush.create_device()
device.get_taglist()
import jpush as jpush
from conf import app_key, master_secret
_jpush = jpush.JPush(app_key, master_secret)
device = _jpush.create_device()
device.get_taglist()
import jpush as jpush
from conf import app_key, master_secret
_jpush = jpush.JPush(app_key, master_secret)
device = _jpush.create_device()
device.get_taglist()
import jpush as jpush
from conf import app_key, master_secret
_jpush = jpush.JPush(app_key, master_secret)
device = _jpush.create_device()
reg_id = '090c1f59f89'
entity = jpush.device_tag(jpush.add("ddd", "tageee"))
device.set_deviceinfo(reg_id, entity)
......@@ -22,7 +22,7 @@ from .push import (
message,
)
from device import (
from .device import (
Device,
add,
remove,
......
......@@ -8,6 +8,7 @@ PUSH_URL = BASE_URL + 'v3/push'
DEVICE_BASEURL = "https://device.jpush.cn/"
DEVICE_URL = DEVICE_BASEURL + "v3/device/"
TAG_URL = DEVICE_BASEURL + "v3/tag/"
TAGLIST_URL = TAG_URL + "list/"
ALIAS_URL = DEVICE_BASEURL + "v3/alias/"
logger = logging.getLogger('jpush')
......
......@@ -6,7 +6,7 @@ import requests
from . import common
from .push import Push
from device import Device
from .device import Device
logger = logging.getLogger('jpush')
......
#!/usr/bin/env python
#from jpush import common
from jpush import common
import json
DEVICE_BASEURL = "https://device.jpush.cn/"
DEVICE_URL = DEVICE_BASEURL + "v3/device/"
TAG_URL = DEVICE_BASEURL + "v3/tag/"
TAGLIST_URL = TAG_URL + "list/"
ALIAS_URL = DEVICE_BASEURL + "v3/alias/"
class Device(object):
......@@ -14,20 +16,46 @@ class Device(object):
self._jpush = jpush
self.entity = None
def send(self, method, url, body, params, content_type=None, version=3):
def send(self, method, url, body, content_type=None, version=3):
"""Send the request
"""
response = self._jpush._request(method, body,
url, content_type, version=3)
data = response.json()
return DeviceResponse(response)
def get_taglist(self):
"""Get deviceinfo with registration id.
"""
url = common.TAGLIST_URL
info = self.send("GET", url, None)
print info
def get_deviceinfo(self, registration_id):
"""Get deviceinfo with registration id
"""Get deviceinfo with registration id.
"""
url = common.DEVICE_URL + registration_id + "/"
info = self.send("GET", url, None)
print info
def set_deviceinfo(self, registration_id, entity):
"""Update deviceinfo with registration id.
"""
url = common.DEVICE_URL + registration_id + "/"
body = json.dumps(entity)
print url, body
info = self.send("POST", url, body)
print info
def delete_tag(self, registration_id, tag):
"""Delete registration id tag.
"""
url = DEVICE_URL + registration_id
info = self.send("GET", None, None)
url = common.DEVICE_URL + registration_id + "/"
body = json.dumps(entity)
print url, body
info = self.send("POST", url, body)
print info
class DeviceResponse(object):
......@@ -41,8 +69,11 @@ class DeviceResponse(object):
payload = None
def __init__(self, response):
data = response.json()
self.payload = data
if 0 != len(response.content):
data = response.json()
self.payload = data
elif 200 == response.status_code:
self.payload = "success"
def __str__(self):
return "Device response Payload: {0}".format(self.payload)
......@@ -18,7 +18,7 @@ setup(
author='jpush',
author_email='support@jpush.cn',
packages=['jpush', 'jpush.push'],
packages=['jpush', 'jpush.push', 'jpush.device'],
platforms='any',
classifiers=[
'Environment :: Console',
......
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