Commit 07c0f3da authored by linbo's avatar linbo

Add report received API

parent 2fbc680c
from jpush import RecvClient
recv_client = RecvClient('appkey', 'master_secret')
recv_client.get_recv([0, 1, 2])
recv_client.get_recv('0,1,2')
from .client import JPushClient
from .push import JPushClient
from .recv import RecvClient
__version__ = '2.0.0'
__version__ = '2.0.1'
VERSION = tuple(map(int, __version__.split('.')))
__all__ = ['JPushClient']
__all__ = ['JPushClient', 'RecvClient']
# -*- coding: utf-8 -*-
#
# Push API
#
import json
import hashlib
......
# -*- coding: utf-8 -*-
#
# Report Received API
#
import httplib
API_HOST = "report.jpush.cn"
API_PATH = "/v2/received"
class RecvClient:
""" JPush Report Received Python Client Class"""
def __init__(self, appkey, master_secret, timeout=5):
self._timeout = timeout
self._auth = ("%s:%s" % (appkey, master_secret)).encode("base64").strip()
self._conn = None
self._reconnect()
def _reconnect(self):
if self._conn is None:
self._conn = httplib.HTTPSConnection(API_HOST,
timeout=self._timeout)
def close(self):
"""close connection"""
if self._conn:
self._conn.close()
def __del__(self):
try:
self.close()
except:
pass
def get_recv(self, msg_ids):
"""get recv result"""
if isinstance(msg_ids, list):
msg_ids = [str(i) for i in msg_ids]
msg_ids = ",".join(msg_ids)
url = "%s?msg_ids=%s" % (API_PATH, msg_ids)
auth_header = {"Authorization": "Basic %s" % self._auth}
if self._conn is None:
self._reconnect()
try:
self._conn.request(method="GET", url=url, headers=auth_header)
print self._conn.getresponse().read()
except Exception, e:
self._conn = None
print "Request receive result error: %s" % e
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