Commit f4e291c3 authored by Helperhaps's avatar Helperhaps

add admin api

parent 51e4cb1f
......@@ -4,18 +4,20 @@ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')
import jpush
from .conf import app_key, master_secret
from .conf import app_key, master_secret, dev_key, dev_secret
from . import device_example
from . import push_example
from . import report_example
from . import schedule_example
from . import group_push_example
from . import admin_example
__all__ = [
device_example,
push_example,
report_example,
schedule_example,
group_push_example
group_push_example,
admin_example
]
from . import jpush, dev_key, dev_secret
admin = jpush.Admin(dev_key, dev_secret)
admin.set_logging("DEBUG")
def create_app():
response = admin.create_app('aaa', 'cn.jpush.app')
return response
def delete_app(app_key):
response = admin.delete_app(app_key)
return response
"""Python package for using the JPush API"""
from .core import JPush, GroupPush
from .core import JPush, GroupPush, Admin
from .common import JPushFailure, Unauthorized
from .push import (
......@@ -44,6 +44,7 @@ from .schedule import (
__all__ = [
JPush,
GroupPush,
Admin,
JPushFailure,
Unauthorized,
all_,
......
......@@ -100,3 +100,42 @@ class GroupPush(JPush):
def create_push(self):
"""Create a Group Push notification."""
return Push(self, url = common.GROUP_PUSH_URL)
class Admin(JPush):
def __init__(self, key, secret):
JPush.__init__(self, key, secret)
def create_app(self, app_name, android_package, group_name=None):
url = 'https://admin.jpush.cn/v1/app'
entity = {
'app_name': app_name,
'android_package': android_package,
'group_name': group_name
}
body = json.dumps(entity)
response = self._request('post', body, url, content_type=None, version=3)
return AdminResponse(response)
def delete_app(self, app_key):
url = 'https://admin.jpush.cn/v1/app/' + app_key + '/delete'
response = self._request('post', None, url, content_type=None, version=3)
return AdminResponse(response)
class AdminResponse(object):
payload = None
status_code = None
def __init__(self, response):
self.status_code = response.status_code
if 0 != len(response.content):
data = response.json()
self.payload = data
elif 200 == response.status_code:
self.payload = "success"
def get_status_code(self):
return self.status_code
def __str__(self):
return "Admin response Payload: {0}".format(self.payload)
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