Skip to content

Commit

Permalink
refactor examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Helperhaps committed Jul 18, 2017
1 parent 13cf99f commit f5ff233
Show file tree
Hide file tree
Showing 33 changed files with 234 additions and 278 deletions.
19 changes: 19 additions & 0 deletions examples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import jpush

from .conf import app_key, master_secret

from . import device_example
from . import push_example
from . import report_example
from . import schedule_example

__all__ = [
device_example,
push_example,
report_example,
schedule_example
]
2 changes: 1 addition & 1 deletion examples/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# please put your app_key and master_secret here
app_key = u'6be9204c30b9473e87bad4dc'
master_secret = u'9349ad7c90292a603c512e92'
master_secret = u'cae22120eed6835e486399a7'
54 changes: 54 additions & 0 deletions examples/device_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from . import jpush, app_key, master_secret

_jpush = jpush.JPush(app_key, master_secret)
_jpush.set_logging("DEBUG")
device = _jpush.create_device()

def alias_user():
alias = "alias1"
platform = "android,ios"
device.get_aliasuser(alias, platform)

def ctrl_tag():
reg_id = '090c1f59f89'
entity = jpush.device_tag("")
device.set_deviceinfo(reg_id, entity)

def get_device():
reg_id = '090c1f59f89'
device.get_deviceinfo(reg_id)

def delete_alias():
alias = "alias1"
platform = "android,ios"
device.delete_alias(alias, platform)

def delete_tag():
tag = "ddd"
platform = "android,ios"
device.delete_tag(tag, platform)

def check_tag():
tag = "ddd"
registration_id = '090c1f59f89'
device.check_taguserexist(tag, registration_id)

def tag_list():
device.get_taglist()

def tag_update_user():
tag = "ddd"
entity = jpush.device_regid(jpush.add("090c1f59f89"))
device.update_tagusers(tag, entity)

def update_device():
reg_id = '1507bfd3f7c466c355c'
entity = jpush.device_tag(jpush.add("ddd", "tageee"))
result=device.set_devicemobile(reg_id, entity)
print (result.status_code)
print (result.payload)

def update_device_mobile():
reg_id = '1507bfd3f7c466c355c'
entity = jpush.device_mobile("18588232140")
device.set_devicemobile(reg_id, entity)
8 changes: 0 additions & 8 deletions examples/device_examples/example_aliasuser.py

This file was deleted.

8 changes: 0 additions & 8 deletions examples/device_examples/example_clrtag.py

This file was deleted.

7 changes: 0 additions & 7 deletions examples/device_examples/example_getdevice.py

This file was deleted.

8 changes: 0 additions & 8 deletions examples/device_examples/example_rmalias.py

This file was deleted.

10 changes: 0 additions & 10 deletions examples/device_examples/example_rmtag.py

This file was deleted.

8 changes: 0 additions & 8 deletions examples/device_examples/example_tagexist.py

This file was deleted.

6 changes: 0 additions & 6 deletions examples/device_examples/example_taglist.py

This file was deleted.

8 changes: 0 additions & 8 deletions examples/device_examples/example_tagupduser.py

This file was deleted.

10 changes: 0 additions & 10 deletions examples/device_examples/example_updevice.py

This file was deleted.

8 changes: 0 additions & 8 deletions examples/device_examples/example_updevicemobile.py

This file was deleted.

109 changes: 109 additions & 0 deletions examples/push_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
from . import jpush, app_key, master_secret

_jpush = jpush.JPush(app_key, master_secret)
_jpush.set_logging("DEBUG")

def alias():
push = _jpush.create_push()
alias=["alias1", "alias2"]
alias1={"alias": alias}
print(alias1)
push.audience = jpush.audience(
jpush.tag("tag1", "tag2"),
alias1
)

push.notification = jpush.notification(alert="Hello world with audience!")
push.platform = jpush.all_
print (push.payload)
push.send()

def all():
push = _jpush.create_push()
push.audience = jpush.all_
push.notification = jpush.notification(alert="!hello python jpush api")
push.platform = jpush.all_
try:
response=push.send()
except common.Unauthorized:
raise common.Unauthorized("Unauthorized")
except common.APIConnectionException:
raise common.APIConnectionException("conn")
except common.JPushFailure:
print ("JPushFailure")
except:
print ("Exception")

def audience():
push = _jpush.create_push()

push.audience = jpush.audience(
jpush.tag("tag1", "tag2"),
jpush.alias("alias1", "alias2")
)


push.notification = jpush.notification(alert="Hello world with audience!")
push.platform = jpush.all_
print (push.payload)
push.send()


def notification():
push = _jpush.create_push()

push.audience = jpush.all_
push.platform = jpush.all_

ios = jpush.ios(alert="Hello, IOS JPush!", sound="a.caf", extras={'k1':'v1'})
android = jpush.android(alert="Hello, Android msg", priority=1, style=1, alert_type=1,big_text='jjjjjjjjjj', extras={'k1':'v1'})

push.notification = jpush.notification(alert="Hello, JPush!", android=android, ios=ios)

# pprint (push.payload)
result = push.send()

def options():
push = _jpush.create_push()
push.audience = jpush.all_
push.notification = jpush.notification(alert="Hello, world!")
push.platform = jpush.all_
push.options = {"time_to_live":86400, "sendno":12345,"apns_production":True}
push.send()

def platfrom_msg():
push = _jpush.create_push()
push.audience = jpush.all_
ios_msg = jpush.ios(alert="Hello, IOS JPush!", badge="+1", sound="a.caf", extras={'k1':'v1'})
android_msg = jpush.android(alert="Hello, android msg")
push.notification = jpush.notification(alert="Hello, JPush!", android=android_msg, ios=ios_msg)
push.message=jpush.message("content",extras={'k2':'v2','k3':'v3'})
push.platform = jpush.all_
push.send()


def silent():
push = _jpush.create_push()
push.audience = jpush.all_
ios_msg = jpush.ios(alert="Hello, IOS JPush!", badge="+1", extras={'k1':'v1'}, sound_disable=True)
android_msg = jpush.android(alert="Hello, android msg")
push.notification = jpush.notification(alert="Hello, JPush!", android=android_msg, ios=ios_msg)
push.platform = jpush.all_
push.send()


def sms():
push = _jpush.create_push()
push.audience = jpush.all_
push.notification = jpush.notification(alert="a sms message from python jpush api")
push.platform = jpush.all_
push.smsmessage=jpush.smsmessage("a sms message from python jpush api",0)
print (push.payload)
push.send()

def validate():
push = _jpush.create_push()
push.audience = jpush.all_
push.notification = jpush.notification(alert="Hello, world!")
push.platform = jpush.all_
push.send_validate()
17 changes: 0 additions & 17 deletions examples/push_examples/example_alias.py

This file was deleted.

23 changes: 0 additions & 23 deletions examples/push_examples/example_all.py

This file was deleted.

16 changes: 0 additions & 16 deletions examples/push_examples/example_audience.py

This file was deleted.

19 changes: 0 additions & 19 deletions examples/push_examples/example_notification.py

This file was deleted.

10 changes: 0 additions & 10 deletions examples/push_examples/example_options.py

This file was deleted.

12 changes: 0 additions & 12 deletions examples/push_examples/example_platformmsg.py

This file was deleted.

11 changes: 0 additions & 11 deletions examples/push_examples/example_silent.py

This file was deleted.

Loading

0 comments on commit f5ff233

Please sign in to comment.