Commit 0cdb00d7 authored by hupantingxue's avatar hupantingxue

Merge branch 'dev'

parents 03b5443d 070b9cf0
...@@ -12,4 +12,4 @@ install: ...@@ -12,4 +12,4 @@ install:
- pip install . - pip install .
# command to run tests # command to run tests
script: nosetests -w tests/push/ --verbosity=2 script: nosetests tests/push tests/devices --verbosity=2
...@@ -14,6 +14,10 @@ JPush API Python Client ...@@ -14,6 +14,10 @@ JPush API Python Client
JPush's officially supported Python client library for accessing JPush APIs. JPush's officially supported Python client library for accessing JPush APIs.
JPush Rest API Documents: `http://docs.jpush.cn/display/dev/REST+API <http://docs.jpush.cn/display/dev/REST+API/>`_
You can download the latest release file here: `Releases <https://github.com/jpush/jpush-api-python-client/releases>`_
------------ ------------
Dependencies Dependencies
------------ ------------
...@@ -45,10 +49,50 @@ or from source: ...@@ -45,10 +49,50 @@ or from source:
$ sudo python setup.py install $ sudo python setup.py install
-------
Testing
-------
For running the tests, you need the standard `unittest` module, shipped
with Python.
To run jpush-api-python-client tests, simply:
.. code-block:: sh
$ nosetests tests/push tests/devices --verbosity=2
-------- --------
Examples Examples
-------- --------
Details refer to `examples <https://github.com/jpush/jpush-api-python-client/blob/master/examples>`_ You can see more examples in `examples <https://github.com/jpush/jpush-api-python-client/blob/master/examples>`_
Simple iOS Push
---------------
>>> import jpush as jpush
>>> from conf import app_key, master_secret
>>> _jpush = jpush.JPush(app_key, master_secret)
>>> push = _jpush.create_push()
>>> push.audience = jpush.all_
>>> ios_msg = jpush.ios(alert="Hello, IOS JPush!", badge="+1", sound="a.caf", extras={'k1':'v1'})
>>> push.notification = jpush.notification(alert="Hello, JPush!", android=android_msg, ios=ios_msg)
>>> push.options = {"time_to_live":86400, "sendno":12345,"apns_production":True}
>>> push.platform = jpush.platform("ios")
>>> push.send()
Get taglist
-----------------
>>> import jpush as jpush
>>> from conf import app_key, master_secret
>>> _jpush = jpush.JPush(app_key, master_secret)
>>> device = _jpush.create_device()
>>> device.get_taglist()
--------
Questions
--------
The best place to ask questions is our Q&A site:
http://www.jpush.cn/qa/
-------- --------
Thanks to Thanks to
......
Examples
========
Common setup:
.. code-block:: python
import jpush as jpush
_jpush = jpush.JPush(app_key, master_secret)
Simple broadcast to all devices
-------------------------------
.. code-block:: python
push = _jpush.create_push()
push.audience = jpush.all_
push.notification = jpush.notification(alert="Hello, world!")
push.platform = jpush.all_
push.send()
Complex audience with iOS & Android specifics
---------------------------------------------
.. code-block:: python
push = _jpush.create_push()
push.audience = jpush.audience(
jpush.tag("breakingnews"),
jpush.tag_and("sports"),
)
)
push.notification = jpush.notification(
ios=jpush.ios(
alert="JPush ios test",
badge="1",
extras={"articleid": "123456"}
),
android=jpush.android(
alert="Breaking Special Android News!",
extras={"articleid": "http://m.example.com/123456"}
)
)
push.platform = jpush.platform('ios', 'android')
push.send()
Single iOS push
---------------
.. code-block:: python
push = _jpush.create_push()
push.audience = jpush.registration_id('fffffffffff')
push.notification = jpush.notification(
ios=jpush.ios(alert="JPush powers your apps"))
push.platform = jpush.platform('ios')
push.send()
#!/usr/bin/env python #!/usr/bin/env python
#-*- coding:utf8 -*- #-*- coding:utf8 -*-
import sys
if 2 != sys.version_info[0]:
unicode = str
def add(*types): def add(*types):
"""Select a (list of) to be added objects(s) """Select a (list of) to be added objects(s)
......
...@@ -12,7 +12,7 @@ setup( ...@@ -12,7 +12,7 @@ setup(
description='JPush\'s officially supported Python client library', description='JPush\'s officially supported Python client library',
keywords=('JPush', 'JPush API', 'Android Push', 'iOS Push'), keywords=('JPush', 'JPush API', 'Android Push', 'iOS Push'),
license='MIT License', license='MIT License',
long_description=open("README", "r").read(), long_description=open("README.rst", "r").read(),
url='https://github.com/jpush/jpush-api-python-client', url='https://github.com/jpush/jpush-api-python-client',
author='jpush', author='jpush',
......
import unittest
import requests
import jpush
import unittest
import jpush
class TestEntity(unittest.TestCase):
def test_basic_entity(self):
entities = (
(jpush.add, 'tag1', {'add': ['tag1']}),
(jpush.remove, 'tag1', {'remove': ['tag1']}),
(jpush.device_tag, 'tag1', {'tags': 'tag1'}),
(jpush.device_alias, 'alias1', {'alias': 'alias1'}),
(jpush.device_regid, 'registration_id1', {'registration_ids': 'registration_id1'}),
)
for entity, value, result in entities:
self.assertEqual(entity(value), result)
def test_compound_entity(self):
self.assertEqual(
jpush.device_tag(jpush.add("tag1", "tag2")),
{'tags':{'add':['tag1', 'tag2']}})
self.assertEqual(
jpush.device_tag(jpush.remove("tag1", "tag2")),
{'tags':{'remove':['tag1', 'tag2']}})
self.assertEqual(
jpush.device_alias(jpush.add("alias1", "alias2"), jpush.remove("alias3", "alias4")),
{'alias':{'add':['alias1', 'alias2'], 'remove':['alias3', 'alias4']}})
self.assertEqual(
jpush.device_regid(jpush.add("regid1", "regid2"), jpush.remove("regid3", "regid4")),
{'registration_ids':{'add':['regid1', 'regid2'], 'remove':['regid3', 'regid4']}})
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