Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jpush-api-python-client
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
jpush-api-python-client
Commits
689d0d08
Commit
689d0d08
authored
Jan 30, 2018
by
Helperhaps
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add zone
parent
bd5b8772
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
56 additions
and
33 deletions
+56
-33
common.py
jpush/common.py
+22
-7
core.py
jpush/core.py
+4
-2
core.py
jpush/device/core.py
+11
-10
core.py
jpush/push/core.py
+7
-4
core.py
jpush/report/core.py
+5
-4
core.py
jpush/schedule/core.py
+7
-6
No files found.
jpush/common.py
View file @
689d0d08
...
...
@@ -2,16 +2,31 @@ import json
import
logging
import
requests
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/'
ZONES
=
{
'DEFAULT'
:
{
'PUSH'
:
'https://api.jpush.cn/v3/'
,
'REPORT'
:
'https://report.jpush.cn/v3/'
,
'DEVICE'
:
'https://device.jpush.cn/v3/devices/'
,
'ALIAS'
:
'https://device.jpush.cn/v3/aliases/'
,
'TAG'
:
'https://device.jpush.cn/v3/tags/'
,
'SCHEDULE'
:
'https://api.jpush.cn/v3/schedules/'
,
'ADMIN'
:
'https://admin.jpush.cn/v1/'
},
'BJ'
:{
'PUSH'
:
'https://bjapi.push.jiguang.cn/v3/'
,
'REPORT'
:
'https://bjapi.push.jiguang.cn/v3/report/'
,
'DEVICE'
:
'https://bjapi.push.jiguang.cn/v3/device/'
,
'ALIAS'
:
'https://bjapi.push.jiguang.cn/v3/device/aliases/'
,
'TAG'
:
'https://bjapi.push.jiguang.cn/v3/device/tags/'
,
'SCHEDULE'
:
'https://bjapi.push.jiguang.cn/v3/push/schedules/'
,
'ADMIN'
:
'https://admin.jpush.cn/v1/'
}
}
logger
=
logging
.
getLogger
(
'jpush'
)
def
get_url
(
key
,
zone
=
'default'
):
return
ZONES
[
zone
.
upper
()][
key
.
upper
()]
class
Unauthorized
(
Exception
):
"""Raised when we get a 401 from the server"""
...
...
jpush/core.py
View file @
689d0d08
...
...
@@ -14,10 +14,11 @@ logger = logging.getLogger('jpush')
class
JPush
(
object
):
def
__init__
(
self
,
key
,
secret
,
timeout
=
30
):
def
__init__
(
self
,
key
,
secret
,
timeout
=
30
,
zone
=
'default'
):
self
.
key
=
key
self
.
secret
=
secret
self
.
timeout
=
timeout
self
.
zone
=
zone
self
.
session
=
requests
.
Session
()
self
.
session
.
auth
=
(
key
,
secret
)
...
...
@@ -56,7 +57,8 @@ class JPush(object):
"JPush.push() is deprecated. See documentation on upgrading."
,
DeprecationWarning
)
body
=
json
.
dumps
(
payload
)
self
.
_request
(
'POST'
,
body
,
common
.
PUSH_URL
+
'push'
,
'application/json'
,
version
=
1
)
url
=
common
.
get_url
(
'push'
,
self
.
zone
)
+
'push'
self
.
_request
(
'POST'
,
body
,
url
,
'application/json'
,
version
=
1
)
def
set_logging
(
self
,
level
):
level_list
=
[
"CRITICAL"
,
"ERROR"
,
"WARNING"
,
"INFO"
,
"DEBUG"
,
"NOTSET"
]
...
...
jpush/device/core.py
View file @
689d0d08
...
...
@@ -7,9 +7,10 @@ class Device(object):
"""Device info query/update..
"""
def
__init__
(
self
,
jpush
):
def
__init__
(
self
,
jpush
,
zone
=
None
):
self
.
_jpush
=
jpush
self
.
entity
=
None
self
.
zone
=
zone
or
jpush
.
zone
def
send
(
self
,
method
,
url
,
body
,
content_type
=
None
,
version
=
3
):
"""Send the request
...
...
@@ -21,7 +22,7 @@ class Device(object):
def
get_taglist
(
self
):
"""Get deviceinfo with registration id.
"""
url
=
common
.
TAG_URL
url
=
common
.
get_url
(
'tag'
,
self
.
zone
)
body
=
None
info
=
self
.
send
(
"GET"
,
url
,
body
)
return
info
...
...
@@ -29,7 +30,7 @@ class Device(object):
def
get_deviceinfo
(
self
,
registration_id
):
"""Get deviceinfo with registration id.
"""
url
=
common
.
DEVICE_URL
+
registration_id
+
"/"
url
=
common
.
get_url
(
'device'
,
self
.
zone
)
+
registration_id
body
=
None
info
=
self
.
send
(
"GET"
,
url
,
body
)
return
info
...
...
@@ -37,7 +38,7 @@ class Device(object):
def
set_deviceinfo
(
self
,
registration_id
,
entity
):
"""Update deviceinfo with registration id.
"""
url
=
common
.
DEVICE_URL
+
registration_id
+
"/"
url
=
common
.
get_url
(
'device'
,
self
.
zone
)
+
registration_id
body
=
json
.
dumps
(
entity
)
info
=
self
.
send
(
"POST"
,
url
,
body
)
return
info
...
...
@@ -45,7 +46,7 @@ class Device(object):
def
set_devicemobile
(
self
,
registration_id
,
entity
):
"""Update deviceinfo with registration id.
"""
url
=
common
.
DEVICE_URL
+
registration_id
+
"/"
url
=
common
.
get_url
(
'device'
,
self
.
zone
)
+
registration_id
body
=
json
.
dumps
(
entity
)
info
=
self
.
send
(
"POST"
,
url
,
body
)
return
info
...
...
@@ -53,7 +54,7 @@ class Device(object):
def
delete_tag
(
self
,
tag
,
platform
=
None
):
"""Delete registration id tag.
"""
url
=
common
.
TAG_URL
+
tag
+
"/"
url
=
common
.
get_url
(
'tag'
,
self
.
zone
)
+
tag
body
=
None
if
platform
:
body
=
platform
...
...
@@ -63,7 +64,7 @@ class Device(object):
def
update_tagusers
(
self
,
tag
,
entity
):
"""Add/Remove specified tag users.
"""
url
=
common
.
TAG_URL
+
tag
+
"/"
url
=
common
.
get_url
(
'tag'
,
self
.
zone
)
+
tag
body
=
json
.
dumps
(
entity
)
info
=
self
.
send
(
"POST"
,
url
,
body
)
return
info
...
...
@@ -71,7 +72,7 @@ class Device(object):
def
check_taguserexist
(
self
,
tag
,
registration_id
):
"""Check registration id whether in tag.
"""
url
=
common
.
TAG_URL
+
tag
+
"/registration_ids/"
+
registration_id
url
=
common
.
get_url
(
'tag'
,
self
.
zone
)
+
tag
+
"/registration_ids/"
+
registration_id
body
=
registration_id
info
=
self
.
send
(
"GET"
,
url
,
body
)
return
info
...
...
@@ -79,7 +80,7 @@ class Device(object):
def
delete_alias
(
self
,
alias
,
platform
=
None
):
"""Delete appkey alias.
"""
url
=
common
.
ALIAS_URL
+
alias
+
"/"
url
=
common
.
get_url
(
'alias'
,
self
.
zone
)
+
alias
body
=
None
if
platform
:
body
=
platform
...
...
@@ -89,7 +90,7 @@ class Device(object):
def
get_aliasuser
(
self
,
alias
,
platform
=
None
):
"""Get appkey alias users.
"""
url
=
common
.
ALIAS_URL
+
alias
+
"/"
url
=
common
.
get_url
(
'alias'
,
self
.
zone
)
+
alias
body
=
None
if
platform
:
body
=
platform
...
...
jpush/push/core.py
View file @
689d0d08
...
...
@@ -8,7 +8,7 @@ logger = logging.getLogger('jpush')
class
Push
(
object
):
"""A push notification. Set audience, message, etc, and send."""
def
__init__
(
self
,
jpush
,
end_point
=
'push'
):
def
__init__
(
self
,
jpush
,
end_point
=
'push'
,
zone
=
None
):
self
.
_jpush
=
jpush
self
.
audience
=
None
self
.
notification
=
None
...
...
@@ -18,6 +18,7 @@ class Push(object):
self
.
message
=
None
self
.
smsmessage
=
None
self
.
end_point
=
end_point
self
.
zone
=
zone
or
jpush
.
zone
@property
def
payload
(
self
):
...
...
@@ -49,7 +50,7 @@ class Push(object):
"""
body
=
json
.
dumps
(
self
.
payload
)
url
=
common
.
PUSH_URL
+
self
.
end_point
url
=
common
.
get_url
(
'push'
,
self
.
zone
)
+
self
.
end_point
response
=
self
.
_jpush
.
_request
(
'POST'
,
body
,
url
,
'application/json'
,
version
=
3
)
return
PushResponse
(
response
)
...
...
@@ -63,13 +64,15 @@ class Push(object):
"""
body
=
json
.
dumps
(
self
.
payload
)
url
=
common
.
PUSH_URL
+
'push/validate'
url
=
common
.
get_url
(
'push'
,
self
.
zone
)
+
'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
.
PUSH_URL
+
'push/cid'
url
=
common
.
get_url
(
'push'
,
self
.
zone
)
+
'push/cid'
params
=
{
'count'
:
count
,
'type'
:
type
...
...
jpush/report/core.py
View file @
689d0d08
...
...
@@ -6,8 +6,9 @@ logger = logging.getLogger('jpush')
class
Report
(
object
):
"""JPush Report API V3"""
def
__init__
(
self
,
jpush
):
def
__init__
(
self
,
jpush
,
zone
=
None
):
self
.
_jpush
=
jpush
self
.
zone
=
zone
or
jpush
.
zone
def
send
(
self
,
method
,
url
,
body
,
content_type
=
None
,
version
=
3
,
params
=
None
):
"""Send the request
...
...
@@ -16,21 +17,21 @@ class Report(object):
return
ReportResponse
(
response
)
def
get_received
(
self
,
msg_ids
):
url
=
common
.
REPORT_URL
+
'received'
url
=
common
.
get_url
(
'report'
,
self
.
zone
)
+
'received'
params
=
{
'msg_ids'
:
msg_ids
}
body
=
None
received
=
self
.
send
(
"GET"
,
url
,
body
,
params
=
params
)
return
received
def
get_messages
(
self
,
msg_ids
):
url
=
common
.
REPORT_URL
+
'messages'
url
=
common
.
get_url
(
'report'
,
self
.
zone
)
+
'messages'
params
=
{
'msg_ids'
:
msg_ids
}
body
=
None
messages
=
self
.
send
(
"GET"
,
url
,
body
,
params
=
params
)
return
messages
def
get_users
(
self
,
time_unit
,
start
,
duration
):
url
=
common
.
REPORT_URL
+
'users'
url
=
common
.
get_url
(
'report'
,
self
.
zone
)
+
'users'
params
=
{
'time_unit'
:
time_unit
,
'start'
:
start
,
...
...
jpush/schedule/core.py
View file @
689d0d08
...
...
@@ -7,40 +7,41 @@ logger = logging.getLogger('jpush')
class
Schedule
(
object
):
"""JPush Report API V3"""
def
__init__
(
self
,
jpush
):
def
__init__
(
self
,
jpush
,
zone
=
None
):
self
.
_jpush
=
jpush
self
.
zone
=
zone
or
jpush
.
zone
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
.
SCHEDULE_URL
url
=
common
.
get_url
(
'schedule'
,
self
.
zone
)
body
=
json
.
dumps
(
schedulepayload
)
result
=
self
.
send
(
"POST"
,
url
,
body
)
return
result
def
get_schedule_by_id
(
self
,
schedule_id
):
url
=
common
.
SCHEDULE_URL
+
schedule_id
url
=
common
.
get_url
(
'schedule'
,
self
.
zone
)
+
schedule_id
body
=
None
result
=
self
.
send
(
"GET"
,
url
,
body
)
return
result
def
get_schedule_list
(
self
,
page
=
1
):
url
=
common
.
SCHEDULE_URL
url
=
common
.
get_url
(
'schedule'
,
self
.
zone
)
params
=
{
'page'
:
page
}
body
=
None
result
=
self
.
send
(
"GET"
,
url
,
body
,
params
=
params
)
return
result
def
put_schedule
(
self
,
schedulepayload
,
schedule_id
):
url
=
common
.
SCHEDULE_URL
+
schedule_id
url
=
common
.
get_url
(
'schedule'
,
self
.
zone
)
+
schedule_id
body
=
json
.
dumps
(
schedulepayload
)
result
=
self
.
send
(
"PUT"
,
url
,
body
)
return
result
def
delete_schedule
(
self
,
schedule_id
):
url
=
common
.
SCHEDULE_URL
+
schedule_id
url
=
common
.
get_url
(
'schedule'
,
self
.
zone
)
+
schedule_id
body
=
None
result
=
self
.
send
(
"DELETE"
,
url
,
body
)
return
result
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment