Skip to content

Commit 12fc356

Browse files
committed
support hmos
1 parent 16b1716 commit 12fc356

File tree

9 files changed

+64
-14
lines changed

9 files changed

+64
-14
lines changed

docs/push/push.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ ios(alert=None, badge='+1', sound=None, content_available=False, mutable_conte
250250

251251
返回值
252252

253-
> ios payload 字典
253+
> android payload 字典
254254
255255
##### android payload
256256
```

examples/device_example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
def alias_user():
88
alias = "alias1"
9-
platform = "android,ios"
9+
platform = "android,ios,hmos"
1010
device.get_aliasuser(alias, platform)
1111

1212
def ctrl_tag():
@@ -20,12 +20,12 @@ def get_device():
2020

2121
def delete_alias():
2222
alias = "alias1"
23-
platform = "android,ios"
23+
platform = "android,ios,hmos"
2424
device.delete_alias(alias, platform)
2525

2626
def delete_tag():
2727
tag = "ddd"
28-
platform = "android,ios"
28+
platform = "android,ios,hmos"
2929
device.delete_tag(tag, platform)
3030

3131
def check_tag():

examples/push_example.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ def notification():
5858

5959
ios = jpush.ios(alert="Hello, IOS JPush!", sound="a.caf", extras={'k1':'v1'})
6060
android = jpush.android(alert="Hello, Android msg", priority=1, style=1, alert_type=1,big_text='jjjjjjjjjj', extras={'k1':'v1'})
61+
hmos = jpush.hmos(alert="Hello, HMOS JPush!", category="category", large_icon="large_icon", intent={"url":"action.system.home"}, extras={'k1':'v1'}, style="style", inbox="inbox")
6162

62-
push.notification = jpush.notification(alert="Hello, JPush!", android=android, ios=ios)
63+
push.notification = jpush.notification(alert="Hello, JPush!", android=android, ios=ios, hmos=hmos)
6364

6465
# pprint (push.payload)
6566
result = push.send()
@@ -77,7 +78,8 @@ def platfrom_msg():
7778
push.audience = jpush.all_
7879
ios_msg = jpush.ios(alert="Hello, IOS JPush!", badge="+1", sound="a.caf", extras={'k1':'v1'})
7980
android_msg = jpush.android(alert="Hello, android msg")
80-
push.notification = jpush.notification(alert="Hello, JPush!", android=android_msg, ios=ios_msg)
81+
hmos_msg = jpush.hmos(alert="Hello, HMOS JPush msg")
82+
push.notification = jpush.notification(alert="Hello, JPush!", android=android_msg, ios=ios_msg, hmos=hmos_msg)
8183
push.message=jpush.message("content",extras={'k2':'v2','k3':'v3'})
8284
push.platform = jpush.all_
8385
push.send()
@@ -88,7 +90,8 @@ def silent():
8890
push.audience = jpush.all_
8991
ios_msg = jpush.ios(alert="Hello, IOS JPush!", badge="+1", extras={'k1':'v1'}, sound_disable=True)
9092
android_msg = jpush.android(alert="Hello, android msg")
91-
push.notification = jpush.notification(alert="Hello, JPush!", android=android_msg, ios=ios_msg)
93+
hmos_msg = jpush.hmos(alert="Hello, HMOS JPush msg")
94+
push.notification = jpush.notification(alert="Hello, JPush!", android=android_msg, ios=ios_msg, hmos=hmos_msg)
9295
push.platform = jpush.all_
9396
push.send()
9497

jpush/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
notification,
1414
ios,
1515
android,
16+
hmos,
1617
winphone,
1718
platform,
1819
audience,
@@ -57,6 +58,7 @@
5758
notification,
5859
ios,
5960
android,
61+
hmos,
6062
winphone,
6163
message,
6264
smsmessage,

jpush/push/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
android,
1515
ios,
1616
winphone,
17+
hmos,
1718
platform,
1819
cid,
1920
notification,

jpush/push/payload.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
string_types = (str, unicode)
1414

1515

16-
def notification(alert=None, ios=None, android=None, winphone=None):
16+
def notification(alert=None, ios=None, android=None, winphone=None,hmos=None):
1717
"""Create a notification payload.
1818
1919
:keyword alert: A simple text alert, applicable for all platforms.
2020
:keyword ios: An iOS platform override, as generated by :py:func:`ios`.
2121
:keyword android: An Android platform override, as generated by :py:func:`android`.
2222
:keyword winphone: A MPNS platform override, as generated by :py:func:`mpns`.
23+
:keyword hmos: A hmos platform override, as generated by :py:func:`hmos`.
2324
2425
"""
2526
payload = {}
@@ -31,6 +32,8 @@ def notification(alert=None, ios=None, android=None, winphone=None):
3132
payload['android'] = android
3233
if winphone is not None:
3334
payload['winphone'] = winphone
35+
if hmos is not None:
36+
payload['hmos'] = hmos
3437
if not payload:
3538
raise ValueError("Notification body may not be empty")
3639
return payload
@@ -48,6 +51,9 @@ def ios(alert=None, badge='+1', sound=None, content_available=False,
4851
:keyword extras: A set of key/value pairs to include in the push payload
4952
sent to the device.
5053
:keyword sound_disalbe: Disable sound to implement slient push.
54+
:keyword mutable_content: If True, enables modifying notification content in iOS service extension.
55+
:keyword category: String category for iOS notification action buttons.
56+
:keyword thread_id: String identifier to group related notifications in iOS.
5157
5258
>>> ios(alert='Hello!', sound='cat.caf',
5359
... extras={'articleid': '12345'})
@@ -147,6 +153,38 @@ def winphone(alert, title=None, _open_page=None, extras=None):
147153
payload['extras'] = extras
148154
return payload
149155

156+
def hmos(alert, title=None, category=None, large_icon=None, intent=None, extras=None, style=None, inbox=None):
157+
"""Hmos specific platform override payload.
158+
more info:https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push#hmos
159+
160+
:keyword alert: String alert text.
161+
:keyword title: String
162+
:keyword category: String
163+
:keyword large_icon: String
164+
:keyword intent: A set of key/value pairs to include in the push payload
165+
:keyword extras: A set of key/value pairs to include in the push payload
166+
:keyword style: String
167+
:keyword inbox: String
168+
"""
169+
payload = {}
170+
if alert is not None:
171+
payload['alert'] = alert
172+
if title is not None:
173+
payload['title'] = title
174+
if category is not None:
175+
payload['category'] = category
176+
if large_icon is not None:
177+
payload['large_icon'] = large_icon
178+
if intent is not None:
179+
payload['intent'] = intent
180+
if extras is not None:
181+
payload['extras'] = extras
182+
if style is not None:
183+
payload['style'] = style
184+
if inbox is not None:
185+
payload['inbox'] = inbox
186+
return payload
187+
150188
def message(msg_content, title=None, content_type=None, extras=None):
151189
"""Inner-conn push message payload creation.
152190
@@ -199,7 +237,7 @@ def platform(*types):
199237
if len(types) == 1 and types[0] == 'all':
200238
return 'all'
201239
for t in types:
202-
if t not in ('ios', 'android', 'winphone'):
240+
if t not in ('ios', 'android', 'winphone', 'hmos'):
203241
raise ValueError("Invalid platform '%s'" % t)
204242
return [t for t in types]
205243

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
try:
55
from setuptools import setup
66
except (ImportError):
7-
from distutils.core import setup
7+
from distutils.core import setup
88

99
_version_re = re.compile(r'__version__\s+=\s+(.*)')
1010

@@ -16,7 +16,7 @@
1616
name='jpush',
1717
version=version,
1818
description='JPush\'s officially supported Python client library',
19-
keywords=('JPush', 'JPush API', 'Android Push', 'iOS Push'),
19+
keywords=('JPush', 'JPush API', 'Android Push', 'iOS Push', 'HMOS Push'),
2020
license='MIT License',
2121
long_description=open("README.rst", "r").read(),
2222
long_description_content_type="text/markdown",

tests/devices/test_devices.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_create_device(self):
1919

2020
def test_aliasuser(self):
2121
alias = "alias1"
22-
platform = "android,ios"
22+
platform = "android,ios,hmos"
2323
result = device.get_aliasuser(alias, platform)
2424
self.assertEqual(result.status_code, 200)
2525

@@ -44,13 +44,13 @@ def test_get_device(self):
4444

4545
def test_remove_alias(self):
4646
alias = "alias1"
47-
platform = "android,ios"
47+
platform = "android,ios,hmos"
4848
result = device.delete_alias(alias, platform)
4949
self.assertEqual(result.status_code, 200)
5050

5151
def test_remove_tags(self):
5252
tag = "ddd"
53-
platform = "android,ios"
53+
platform = "android,ios,hmos"
5454
result = device.delete_tag(tag, platform)
5555
self.assertEqual(result.status_code, 200)
5656

tests/push/test_message.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ def test_winphone(self):
3333
jpush.notification(winphone=jpush.winphone(alert="Hello", extras={'k3':'v3'})),
3434
{'winphone': {'extras': {'k3': 'v3'}, 'alert': 'Hello'}}
3535
)
36+
37+
def test_hmos(self):
38+
self.assertEqual(
39+
jpush.notification(hmos=jpush.hmos(alert="Hello", title="Title", extras={'k4':'v4'})),
40+
{'hmos': {'extras': {'k4': 'v4'}, 'alert': 'Hello', 'title': 'Title'}}
41+
)
3642

3743
def test_push(self):
3844
_jpush = jpush.JPush(app_key, master_secret)

0 commit comments

Comments
 (0)