Commit bd5b8772 authored by Helperhaps's avatar Helperhaps

get url all together

parent f4e291c3
......@@ -10,7 +10,7 @@ def delete_schedule():
def get_schedule():
schedule.get_schedule_by_id("e9c553d0-0850-11e6-b6d4-0021f652c102")
def get_schedule():
def get_schedule_list():
schedule.get_schedule_list("1")
def post_schedule():
......
......@@ -2,24 +2,14 @@ import json
import logging
import requests
BASE_URL = "https://api.jpush.cn/"
PUSH_URL = BASE_URL + 'v3/push'
VALIDATE_PUSH_URL = BASE_URL + 'v3/push/validate'
GROUP_PUSH_URL = BASE_URL + 'v3/grouppush'
DEVICE_BASEURL = "https://device.jpush.cn/"
DEVICE_URL = DEVICE_BASEURL + "v3/devices/"
TAG_URL = DEVICE_BASEURL + "v3/tags/"
TAGLIST_URL = TAG_URL
ALIAS_URL = DEVICE_BASEURL + "v3/aliases/"
REPORT_BASEURL="https://report.jpush.cn/"
RECEIVED_URL=REPORT_BASEURL+"v3/received?msg_ids="
MESSAGES_URL=REPORT_BASEURL+"v3/messages?msg_ids="
USERS_URL=REPORT_BASEURL+"v3/users?"
BASE_SCHEDULEURL="https://api.jpush.cn/v3/schedules/"
BASE_LISTURL="https://api.jpush.cn/v3/schedules?page="
PUSH_URL = 'https://api.jpush.cn/v3/'
REPORT_URL = 'https://report.jpush.cn/v3/'
DEVICE_URL = 'https://device.jpush.cn/v3/devices/'
ALIAS_URL = 'https://device.jpush.cn/v3/aliases/'
TAG_URL ='https://device.jpush.cn/v3/tags/'
SCHEDULE_URL = 'https://api.jpush.cn/v3/schedules/'
ADMIN_URL ='https://admin.jpush.cn/v1/'
logger = logging.getLogger('jpush')
......
......@@ -56,7 +56,7 @@ class JPush(object):
"JPush.push() is deprecated. See documentation on upgrading.",
DeprecationWarning)
body = json.dumps(payload)
self._request('POST', body, common.PUSH_URL, 'application/json', version=1)
self._request('POST', body, common.PUSH_URL + 'push', 'application/json', version=1)
def set_logging(self, level):
level_list= ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NOTSET"]
......@@ -99,7 +99,7 @@ class GroupPush(JPush):
def create_push(self):
"""Create a Group Push notification."""
return Push(self, url = common.GROUP_PUSH_URL)
return Push(self, end_point = 'grouppush')
class Admin(JPush):
def __init__(self, key, secret):
......
......@@ -8,12 +8,12 @@ class Device(object):
"""
def __init__(self, jpush):
self._jpush = jpush
self._jpush = jpush
self.entity = None
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 DeviceResponse(response)
......@@ -21,7 +21,7 @@ class Device(object):
def get_taglist(self):
"""Get deviceinfo with registration id.
"""
url = common.TAGLIST_URL
url = common.TAG_URL
body = None
info = self.send("GET", url, body)
return info
......
......@@ -8,7 +8,7 @@ logger = logging.getLogger('jpush')
class Push(object):
"""A push notification. Set audience, message, etc, and send."""
def __init__(self, jpush, url = common.PUSH_URL):
def __init__(self, jpush, end_point = 'push'):
self._jpush = jpush
self.audience = None
self.notification = None
......@@ -17,7 +17,7 @@ class Push(object):
self.options = None
self.message = None
self.smsmessage=None
self.url = url
self.end_point = end_point
@property
def payload(self):
......@@ -49,7 +49,7 @@ class Push(object):
"""
body = json.dumps(self.payload)
url = self.url
url = common.PUSH_URL + self.end_point
response = self._jpush._request('POST', body, url, 'application/json', version=3)
return PushResponse(response)
......@@ -63,17 +63,18 @@ class Push(object):
"""
body = json.dumps(self.payload)
response = self._jpush._request('POST', body, common.VALIDATE_PUSH_URL, 'application/json', version=3)
url = common.PUSH_URL + 'push/validate'
response = self._jpush._request('POST', body, url, 'application/json', version=3)
return PushResponse(response)
def get_cid(self, count, type = None):
body = None
url = common.VALIDATE_PUSH_URL + '/cid'
url = common.PUSH_URL + 'push/cid'
params = {
'count': count,
'type': type
}
response = self._jpush._request('GET', body, common.VALIDATE_PUSH_URL, 'application/json', version=3, params = params)
response = self._jpush._request('GET', body, url, 'application/json', version=3, params = params)
return PushResponse(response)
......
......@@ -9,28 +9,35 @@ class Report(object):
def __init__(self, jpush):
self._jpush = jpush
def send(self, method, url, body, content_type=None, version=3):
def send(self, method, url, body, content_type=None, version=3, params = None):
"""Send the request
"""
response = self._jpush._request(method, body,url,content_type,version=3)
response = self._jpush._request(method, body,url,content_type,version=3, params = params)
return ReportResponse(response)
def get_received(self,msg_ids):
url=common.RECEIVED_URL+msg_ids
url = common.REPORT_URL + 'received'
params = { 'msg_ids': msg_ids }
body = None
received = self.send("GET", url, body)
received = self.send("GET", url, body, params = params)
return received
def get_messages(self, msg_ids):
url = common.MESSAGES_URL + msg_ids
url = common.REPORT_URL + 'messages'
params = { 'msg_ids': msg_ids }
body = None
messages = self.send("GET", url, body)
messages = self.send("GET", url, body, params = params)
return messages
def get_users(self, time_unit,start,duration):
url = common.USERS_URL + "time_unit="+time_unit+"&start="+start+"&duration="+duration
url = common.REPORT_URL + 'users'
params = {
'time_unit': time_unit,
'start': start,
'duration': duration
}
body = None
users = self.send("GET", url, body)
users = self.send("GET", url, body, params = params)
return users
......
......@@ -10,39 +10,37 @@ class Schedule(object):
def __init__(self, jpush):
self._jpush = jpush
def send(self, method, url, body, content_type=None, version=3):
response = self._jpush._request(method, body, url, content_type, version=3)
def send(self, method, url, body, content_type=None, version=3, params = None):
response = self._jpush._request(method, body, url, content_type, version=3, params = params)
return ScheduleResponse(response)
def post_schedule(self, schedulepayload):
url=common.BASE_SCHEDULEURL
url=common.SCHEDULE_URL
body = json.dumps(schedulepayload)
result = self.send("POST", url, body)
return result
def get_schedule_by_id(self, schedule_id):
url=common.BASE_SCHEDULEURL + schedule_id
url=common.SCHEDULE_URL + schedule_id
body = None
result = self.send("GET", url, body)
return result
def get_schedule_list(self, page_id):
if page_id is not None:
url=common.BASE_LISTURL + page_id
else:
url = common.BASE_LISTURL
def get_schedule_list(self, page = 1):
url = common.SCHEDULE_URL
params = { 'page': page }
body = None
result = self.send("GET", url, body)
result = self.send("GET", url, body, params = params)
return result
def put_schedule(self, schedulepayload, schedule_id):
url = common.BASE_SCHEDULEURL + schedule_id
url = common.SCHEDULE_URL + schedule_id
body = json.dumps(schedulepayload)
result = self.send("PUT", url, body)
return result
def delete_schedule(self,schedule_id):
url = common.BASE_SCHEDULEURL + schedule_id
url = common.SCHEDULE_URL + schedule_id
body = None
result = self.send("DELETE", url, body)
return result
......
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