Skip to content

Commit 0cdb00d

Browse files
committed
Merge branch 'dev'
2 parents 03b5443 + 070b9cf commit 0cdb00d

File tree

7 files changed

+86
-62
lines changed

7 files changed

+86
-62
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ install:
1212
- pip install .
1313

1414
# command to run tests
15-
script: nosetests -w tests/push/ --verbosity=2
15+
script: nosetests tests/push tests/devices --verbosity=2

README.rst

+45-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ JPush API Python Client
1414

1515
JPush's officially supported Python client library for accessing JPush APIs.
1616

17+
JPush Rest API Documents: `http://docs.jpush.cn/display/dev/REST+API <http://docs.jpush.cn/display/dev/REST+API/>`_
18+
19+
You can download the latest release file here: `Releases <https://github.com/jpush/jpush-api-python-client/releases>`_
20+
1721
------------
1822
Dependencies
1923
------------
@@ -45,10 +49,50 @@ or from source:
4549
4650
$ sudo python setup.py install
4751
52+
-------
53+
Testing
54+
-------
55+
For running the tests, you need the standard `unittest` module, shipped
56+
with Python.
57+
58+
To run jpush-api-python-client tests, simply:
59+
60+
.. code-block:: sh
61+
62+
$ nosetests tests/push tests/devices --verbosity=2
63+
4864
--------
4965
Examples
5066
--------
51-
Details refer to `examples <https://github.com/jpush/jpush-api-python-client/blob/master/examples>`_
67+
You can see more examples in `examples <https://github.com/jpush/jpush-api-python-client/blob/master/examples>`_
68+
69+
Simple iOS Push
70+
---------------
71+
>>> import jpush as jpush
72+
>>> from conf import app_key, master_secret
73+
>>> _jpush = jpush.JPush(app_key, master_secret)
74+
>>> push = _jpush.create_push()
75+
>>> push.audience = jpush.all_
76+
>>> ios_msg = jpush.ios(alert="Hello, IOS JPush!", badge="+1", sound="a.caf", extras={'k1':'v1'})
77+
>>> push.notification = jpush.notification(alert="Hello, JPush!", android=android_msg, ios=ios_msg)
78+
>>> push.options = {"time_to_live":86400, "sendno":12345,"apns_production":True}
79+
>>> push.platform = jpush.platform("ios")
80+
>>> push.send()
81+
82+
83+
Get taglist
84+
-----------------
85+
>>> import jpush as jpush
86+
>>> from conf import app_key, master_secret
87+
>>> _jpush = jpush.JPush(app_key, master_secret)
88+
>>> device = _jpush.create_device()
89+
>>> device.get_taglist()
90+
91+
--------
92+
Questions
93+
--------
94+
The best place to ask questions is our Q&A site:
95+
http://www.jpush.cn/qa/
5296

5397
--------
5498
Thanks to

docs/examples.rst

-59
This file was deleted.

jpush/device/entity.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/usr/bin/env python
22
#-*- coding:utf8 -*-
3+
import sys
4+
5+
if 2 != sys.version_info[0]:
6+
unicode = str
37

48
def add(*types):
59
"""Select a (list of) to be added objects(s)

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
description='JPush\'s officially supported Python client library',
1313
keywords=('JPush', 'JPush API', 'Android Push', 'iOS Push'),
1414
license='MIT License',
15-
long_description=open("README", "r").read(),
15+
long_description=open("README.rst", "r").read(),
1616

1717
url='https://github.com/jpush/jpush-api-python-client',
1818
author='jpush',

tests/devices/test_devices.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import unittest
2+
import requests
3+
import jpush

tests/devices/test_entity.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import unittest
2+
import jpush
3+
4+
class TestEntity(unittest.TestCase):
5+
6+
def test_basic_entity(self):
7+
entities = (
8+
(jpush.add, 'tag1', {'add': ['tag1']}),
9+
(jpush.remove, 'tag1', {'remove': ['tag1']}),
10+
(jpush.device_tag, 'tag1', {'tags': 'tag1'}),
11+
(jpush.device_alias, 'alias1', {'alias': 'alias1'}),
12+
(jpush.device_regid, 'registration_id1', {'registration_ids': 'registration_id1'}),
13+
)
14+
for entity, value, result in entities:
15+
self.assertEqual(entity(value), result)
16+
17+
def test_compound_entity(self):
18+
self.assertEqual(
19+
jpush.device_tag(jpush.add("tag1", "tag2")),
20+
{'tags':{'add':['tag1', 'tag2']}})
21+
22+
self.assertEqual(
23+
jpush.device_tag(jpush.remove("tag1", "tag2")),
24+
{'tags':{'remove':['tag1', 'tag2']}})
25+
26+
self.assertEqual(
27+
jpush.device_alias(jpush.add("alias1", "alias2"), jpush.remove("alias3", "alias4")),
28+
{'alias':{'add':['alias1', 'alias2'], 'remove':['alias3', 'alias4']}})
29+
30+
self.assertEqual(
31+
jpush.device_regid(jpush.add("regid1", "regid2"), jpush.remove("regid3", "regid4")),
32+
{'registration_ids':{'add':['regid1', 'regid2'], 'remove':['regid3', 'regid4']}})

0 commit comments

Comments
 (0)