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
1b3f5d9d
Commit
1b3f5d9d
authored
Jun 20, 2014
by
hupantingxue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add audience payload;
parent
5fdb139b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
25 deletions
+39
-25
__init__.py
jpush/__init__.py
+5
-1
__init__.py
jpush/push/__init__.py
+4
-1
audience.py
jpush/push/audience.py
+12
-22
payload.py
jpush/push/payload.py
+18
-1
No files found.
jpush/__init__.py
View file @
1b3f5d9d
...
@@ -16,7 +16,9 @@ from .push import (
...
@@ -16,7 +16,9 @@ from .push import (
ios
,
ios
,
android
,
android
,
winphone
,
winphone
,
platform
,
platform
,
audience
,
options
,
message
,
message
,
)
)
...
@@ -36,6 +38,8 @@ __all__ = [
...
@@ -36,6 +38,8 @@ __all__ = [
winphone
,
winphone
,
message
,
message
,
platform
,
platform
,
audience
,
options
,
]
]
# Silence urllib3 INFO logging by default
# Silence urllib3 INFO logging by default
...
...
jpush/push/__init__.py
View file @
1b3f5d9d
...
@@ -14,6 +14,8 @@ from .payload import (
...
@@ -14,6 +14,8 @@ from .payload import (
platform
,
platform
,
notification
,
notification
,
message
,
message
,
audience
,
options
,
)
)
# Common selector for audience & platform
# Common selector for audience & platform
...
@@ -24,7 +26,6 @@ all_ = "all"
...
@@ -24,7 +26,6 @@ all_ = "all"
Used in both ``audience`` and ``platform``.
Used in both ``audience`` and ``platform``.
"""
"""
__all__
=
[
__all__
=
[
all_
,
all_
,
Push
,
Push
,
...
@@ -35,4 +36,6 @@ __all__ = [
...
@@ -35,4 +36,6 @@ __all__ = [
notification
,
notification
,
message
,
message
,
platform
,
platform
,
audience
,
options
,
]
]
jpush/push/audience.py
View file @
1b3f5d9d
...
@@ -2,32 +2,22 @@ import re
...
@@ -2,32 +2,22 @@ import re
# Value selectors; aliases, tags, etc.
# Value selectors; aliases, tags, etc.
def
tag
(
tag
):
def
tag
(
*
tags
):
"""Select a single tag."""
"""Select a single tag."""
return
{
"tag"
:
tag
}
vtag
=
[
t
for
t
in
tags
]
return
{
"tag"
:
vtag
}
def
tag_and
(
tag_and
):
def
tag_and
(
*
tag_ands
):
"""Select a single tag_and."""
"""Select a single tag_and."""
return
{
"tag_and"
:
tag_and
}
vtag_and
=
[
t
for
t
in
tag_ands
]
return
{
"tag_and"
:
vtag_and
}
def
alias
(
alias
):
def
alias
(
*
alias
):
"""Select a single alias."""
"""Select a single alias."""
return
{
"alias"
:
alias
}
valias
=
[
t
for
t
in
alias
]
return
{
"alias"
:
valias
}
def
registration_id
(
registration_id
):
def
registration_id
(
*
reg_ids
):
"""Select a (list of) registration_id(s)."""
"""Select a (list of) registration_id(s)."""
return
{
"registration_id"
:
registration_id
}
vregistration_id
=
[
t
for
t
in
reg_ids
]
return
{
"registration_id"
:
vregistration_id
}
def
audience
(
*
children
):
"""Select audience that match all of the given selectors.
>>> audience(tag('sports'), tag_and('business'))
{'audience': {'tag':'sports', 'tag_and':'business'}}
"""
if
len
(
types
)
==
1
and
types
[
0
]
==
'all'
:
return
{
'audience'
:
'all'
}
for
t
in
types
:
if
t
not
in
(
'tag'
,
'tag_and'
,
'alias'
,
'registration_id'
):
raise
ValueError
(
"Invalid platform '
%
s'"
%
t
)
return
[
t
for
t
in
types
]
jpush/push/payload.py
View file @
1b3f5d9d
...
@@ -84,7 +84,7 @@ def android(alert, title=None, builder_id=None, extras=None):
...
@@ -84,7 +84,7 @@ def android(alert, title=None, builder_id=None, extras=None):
payload
[
'title'
]
=
title
payload
[
'title'
]
=
title
if
builder_id
is
not
None
:
if
builder_id
is
not
None
:
payload
[
'builder_id'
]
=
builder_id
payload
[
'builder_id'
]
=
builder_id
if
extra
is
not
None
:
if
extra
s
is
not
None
:
payload
[
'extras'
]
=
extras
payload
[
'extras'
]
=
extras
return
payload
return
payload
...
@@ -149,3 +149,20 @@ def platform(*types):
...
@@ -149,3 +149,20 @@ def platform(*types):
def
options
(
options
):
def
options
(
options
):
"""Create options object."""
"""Create options object."""
return
{
"options"
:
options
}
return
{
"options"
:
options
}
def
audience
(
*
types
):
"""Select audience that match all of the given selectors.
>>> audience(tag('sports'), tag_and('business'))
{'audience': {'tag':['sports'], 'tag_and':['business']}}
"""
if
1
==
len
(
types
)
and
'all'
==
types
[
0
]:
return
"all"
audience
=
{}
for
t
in
types
:
for
key
in
t
:
if
key
not
in
(
'tag'
,
'tag_and'
,
'alias'
,
'registration_id'
):
raise
ValueError
(
"Invalid audience '
%
s'"
%
t
)
audience
[
key
]
=
t
[
key
]
return
audience
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