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
0cdb00d7
Commit
0cdb00d7
authored
Dec 02, 2014
by
hupantingxue
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev'
parents
03b5443d
070b9cf0
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
86 additions
and
62 deletions
+86
-62
.travis.yml
.travis.yml
+1
-1
README.rst
README.rst
+45
-1
examples.rst
docs/examples.rst
+0
-59
entity.py
jpush/device/entity.py
+4
-0
setup.py
setup.py
+1
-1
test_devices.py
tests/devices/test_devices.py
+3
-0
test_entity.py
tests/devices/test_entity.py
+32
-0
No files found.
.travis.yml
View file @
0cdb00d7
...
@@ -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
README.rst
View file @
0cdb00d7
...
@@ -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
...
...
docs/examples.rst
deleted
100644 → 0
View file @
03b5443d
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()
jpush/device/entity.py
View file @
0cdb00d7
#!/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)
...
...
setup.py
View file @
0cdb00d7
...
@@ -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'
,
...
...
tests/devices/test_devices.py
0 → 100644
View file @
0cdb00d7
import
unittest
import
requests
import
jpush
tests/devices/test_entity.py
0 → 100644
View file @
0cdb00d7
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'
]}})
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