Commit a0004990 authored by fendouai's avatar fendouai

add report api

parent f49e7514
app_key = u'6be9204c30b9473e87bad4dc'
master_secret = u'9349ad7c90292a603c512e92'
import jpush as jpush
from conf import app_key, master_secret
_jpush = jpush.JPush(app_key, master_secret)
report=_jpush.create_report();
report.get_messages("3289406737")
\ No newline at end of file
...@@ -33,6 +33,10 @@ from .device import ( ...@@ -33,6 +33,10 @@ from .device import (
device_mobile, device_mobile,
) )
from .report import (
Report,
)
__all__ = [ __all__ = [
JPush, JPush,
JPushFailure, JPushFailure,
...@@ -58,6 +62,7 @@ __all__ = [ ...@@ -58,6 +62,7 @@ __all__ = [
device_tag, device_tag,
device_alias, device_alias,
device_regid, device_regid,
Report,
] ]
# Silence urllib3 INFO logging by default # Silence urllib3 INFO logging by default
......
...@@ -12,6 +12,11 @@ TAG_URL = DEVICE_BASEURL + "v3/tags/" ...@@ -12,6 +12,11 @@ TAG_URL = DEVICE_BASEURL + "v3/tags/"
TAGLIST_URL = TAG_URL TAGLIST_URL = TAG_URL
ALIAS_URL = DEVICE_BASEURL + "v3/aliases/" ALIAS_URL = DEVICE_BASEURL + "v3/aliases/"
REPORT_BASEURL="https://report.jpush.cn/"
RECEIVED_URL=REPORT_BASEURL+"v3/received"
MESSAGES_URL=REPORT_BASEURL+"v3/messages?msg_ids="
USERS_URL=REPORT_BASEURL+"v3/users?"
logger = logging.getLogger('jpush') logger = logging.getLogger('jpush')
class Unauthorized(Exception): class Unauthorized(Exception):
......
...@@ -7,7 +7,7 @@ import requests ...@@ -7,7 +7,7 @@ import requests
from . import common from . import common
from .push import Push from .push import Push
from .device import Device from .device import Device
from .report import Report
logger = logging.getLogger('jpush') logger = logging.getLogger('jpush')
class JPush(object): class JPush(object):
...@@ -68,3 +68,7 @@ class JPush(object): ...@@ -68,3 +68,7 @@ class JPush(object):
def create_device(self): def create_device(self):
"""Create a Device information.""" """Create a Device information."""
return Device(self) return Device(self)
def create_report(self):
"""Create a Push notification."""
return Report(self)
from .core import Report
__all__ = [
Report,
]
\ No newline at end of file
import json
import logging
from jpush import common
logger = logging.getLogger('jpush')
class Report(object):
"""JPush Report API V3"""
def __init__(self, jpush):
self._jpush = jpush
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)
return ReportResponse(response)
def get_received(self,msg_ids):
url=common.RECEIVED_URL+msg_ids
body = None
received = self.send("GET", url, body)
print (received)
return received
def get_messages(self, msg_ids):
url = common.MESSAGES_URL + msg_ids
body = None
messages = self.send("GET", url, body)
print (messages)
return messages
class ReportResponse(object):
"""Response to a successful device request send.
Right now this is a fairly simple wrapper around the json payload response,
but making it an object gives us some flexibility to add functionality
later.
"""
payload = None
def __init__(self, response):
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)
\ No newline at end of file
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