Skip to content

Commit bd5b877

Browse files
author
Helperhaps
committed
get url all together
1 parent f4e291c commit bd5b877

File tree

7 files changed

+46
-50
lines changed

7 files changed

+46
-50
lines changed

examples/schedule_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def delete_schedule():
1010
def get_schedule():
1111
schedule.get_schedule_by_id("e9c553d0-0850-11e6-b6d4-0021f652c102")
1212

13-
def get_schedule():
13+
def get_schedule_list():
1414
schedule.get_schedule_list("1")
1515

1616
def post_schedule():

jpush/common.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,14 @@
22
import logging
33
import requests
44

5-
BASE_URL = "https://api.jpush.cn/"
6-
PUSH_URL = BASE_URL + 'v3/push'
7-
VALIDATE_PUSH_URL = BASE_URL + 'v3/push/validate'
8-
GROUP_PUSH_URL = BASE_URL + 'v3/grouppush'
9-
10-
DEVICE_BASEURL = "https://device.jpush.cn/"
11-
DEVICE_URL = DEVICE_BASEURL + "v3/devices/"
12-
TAG_URL = DEVICE_BASEURL + "v3/tags/"
13-
TAGLIST_URL = TAG_URL
14-
ALIAS_URL = DEVICE_BASEURL + "v3/aliases/"
15-
16-
REPORT_BASEURL="https://report.jpush.cn/"
17-
RECEIVED_URL=REPORT_BASEURL+"v3/received?msg_ids="
18-
MESSAGES_URL=REPORT_BASEURL+"v3/messages?msg_ids="
19-
USERS_URL=REPORT_BASEURL+"v3/users?"
20-
21-
BASE_SCHEDULEURL="https://api.jpush.cn/v3/schedules/"
22-
BASE_LISTURL="https://api.jpush.cn/v3/schedules?page="
5+
PUSH_URL = 'https://api.jpush.cn/v3/'
6+
REPORT_URL = 'https://report.jpush.cn/v3/'
7+
DEVICE_URL = 'https://device.jpush.cn/v3/devices/'
8+
ALIAS_URL = 'https://device.jpush.cn/v3/aliases/'
9+
TAG_URL ='https://device.jpush.cn/v3/tags/'
10+
SCHEDULE_URL = 'https://api.jpush.cn/v3/schedules/'
11+
ADMIN_URL ='https://admin.jpush.cn/v1/'
12+
2313
logger = logging.getLogger('jpush')
2414

2515

jpush/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def push(self, payload):
5656
"JPush.push() is deprecated. See documentation on upgrading.",
5757
DeprecationWarning)
5858
body = json.dumps(payload)
59-
self._request('POST', body, common.PUSH_URL, 'application/json', version=1)
59+
self._request('POST', body, common.PUSH_URL + 'push', 'application/json', version=1)
6060

6161
def set_logging(self, level):
6262
level_list= ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NOTSET"]
@@ -99,7 +99,7 @@ def __init__(self, key, secret):
9999

100100
def create_push(self):
101101
"""Create a Group Push notification."""
102-
return Push(self, url = common.GROUP_PUSH_URL)
102+
return Push(self, end_point = 'grouppush')
103103

104104
class Admin(JPush):
105105
def __init__(self, key, secret):

jpush/device/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ class Device(object):
88
99
"""
1010
def __init__(self, jpush):
11-
self._jpush = jpush
11+
self._jpush = jpush
1212
self.entity = None
1313

1414
def send(self, method, url, body, content_type=None, version=3):
1515
"""Send the request
16-
16+
1717
"""
1818
response = self._jpush._request(method, body, url, content_type, version=3)
1919
return DeviceResponse(response)
2020

2121
def get_taglist(self):
2222
"""Get deviceinfo with registration id.
2323
"""
24-
url = common.TAGLIST_URL
24+
url = common.TAG_URL
2525
body = None
2626
info = self.send("GET", url, body)
2727
return info

jpush/push/core.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class Push(object):
99
"""A push notification. Set audience, message, etc, and send."""
1010

11-
def __init__(self, jpush, url = common.PUSH_URL):
11+
def __init__(self, jpush, end_point = 'push'):
1212
self._jpush = jpush
1313
self.audience = None
1414
self.notification = None
@@ -17,7 +17,7 @@ def __init__(self, jpush, url = common.PUSH_URL):
1717
self.options = None
1818
self.message = None
1919
self.smsmessage=None
20-
self.url = url
20+
self.end_point = end_point
2121

2222
@property
2323
def payload(self):
@@ -49,7 +49,7 @@ def send(self):
4949
5050
"""
5151
body = json.dumps(self.payload)
52-
url = self.url
52+
url = common.PUSH_URL + self.end_point
5353
response = self._jpush._request('POST', body, url, 'application/json', version=3)
5454
return PushResponse(response)
5555

@@ -63,17 +63,18 @@ def send_validate(self):
6363
6464
"""
6565
body = json.dumps(self.payload)
66-
response = self._jpush._request('POST', body, common.VALIDATE_PUSH_URL, 'application/json', version=3)
66+
url = common.PUSH_URL + 'push/validate'
67+
response = self._jpush._request('POST', body, url, 'application/json', version=3)
6768
return PushResponse(response)
6869

6970
def get_cid(self, count, type = None):
7071
body = None
71-
url = common.VALIDATE_PUSH_URL + '/cid'
72+
url = common.PUSH_URL + 'push/cid'
7273
params = {
7374
'count': count,
7475
'type': type
7576
}
76-
response = self._jpush._request('GET', body, common.VALIDATE_PUSH_URL, 'application/json', version=3, params = params)
77+
response = self._jpush._request('GET', body, url, 'application/json', version=3, params = params)
7778
return PushResponse(response)
7879

7980

jpush/report/core.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,35 @@ class Report(object):
99
def __init__(self, jpush):
1010
self._jpush = jpush
1111

12-
def send(self, method, url, body, content_type=None, version=3):
12+
def send(self, method, url, body, content_type=None, version=3, params = None):
1313
"""Send the request
1414
"""
15-
response = self._jpush._request(method, body,url,content_type,version=3)
15+
response = self._jpush._request(method, body,url,content_type,version=3, params = params)
1616
return ReportResponse(response)
1717

1818
def get_received(self,msg_ids):
19-
url=common.RECEIVED_URL+msg_ids
19+
url = common.REPORT_URL + 'received'
20+
params = { 'msg_ids': msg_ids }
2021
body = None
21-
received = self.send("GET", url, body)
22+
received = self.send("GET", url, body, params = params)
2223
return received
2324

2425
def get_messages(self, msg_ids):
25-
url = common.MESSAGES_URL + msg_ids
26+
url = common.REPORT_URL + 'messages'
27+
params = { 'msg_ids': msg_ids }
2628
body = None
27-
messages = self.send("GET", url, body)
29+
messages = self.send("GET", url, body, params = params)
2830
return messages
2931

3032
def get_users(self, time_unit,start,duration):
31-
url = common.USERS_URL + "time_unit="+time_unit+"&start="+start+"&duration="+duration
33+
url = common.REPORT_URL + 'users'
34+
params = {
35+
'time_unit': time_unit,
36+
'start': start,
37+
'duration': duration
38+
}
3239
body = None
33-
users = self.send("GET", url, body)
40+
users = self.send("GET", url, body, params = params)
3441
return users
3542

3643

jpush/schedule/core.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,37 @@ class Schedule(object):
1010
def __init__(self, jpush):
1111
self._jpush = jpush
1212

13-
def send(self, method, url, body, content_type=None, version=3):
14-
response = self._jpush._request(method, body, url, content_type, version=3)
13+
def send(self, method, url, body, content_type=None, version=3, params = None):
14+
response = self._jpush._request(method, body, url, content_type, version=3, params = params)
1515
return ScheduleResponse(response)
1616

1717
def post_schedule(self, schedulepayload):
18-
url=common.BASE_SCHEDULEURL
18+
url=common.SCHEDULE_URL
1919
body = json.dumps(schedulepayload)
2020
result = self.send("POST", url, body)
2121
return result
2222

2323
def get_schedule_by_id(self, schedule_id):
24-
url=common.BASE_SCHEDULEURL + schedule_id
24+
url=common.SCHEDULE_URL + schedule_id
2525
body = None
2626
result = self.send("GET", url, body)
2727
return result
2828

29-
def get_schedule_list(self, page_id):
30-
if page_id is not None:
31-
url=common.BASE_LISTURL + page_id
32-
else:
33-
url = common.BASE_LISTURL
29+
def get_schedule_list(self, page = 1):
30+
url = common.SCHEDULE_URL
31+
params = { 'page': page }
3432
body = None
35-
result = self.send("GET", url, body)
33+
result = self.send("GET", url, body, params = params)
3634
return result
3735

3836
def put_schedule(self, schedulepayload, schedule_id):
39-
url = common.BASE_SCHEDULEURL + schedule_id
37+
url = common.SCHEDULE_URL + schedule_id
4038
body = json.dumps(schedulepayload)
4139
result = self.send("PUT", url, body)
4240
return result
4341

4442
def delete_schedule(self,schedule_id):
45-
url = common.BASE_SCHEDULEURL + schedule_id
43+
url = common.SCHEDULE_URL + schedule_id
4644
body = None
4745
result = self.send("DELETE", url, body)
4846
return result

0 commit comments

Comments
 (0)