Created
February 5, 2014 11:02
-
-
Save cloverstd/8821241 to your computer and use it in GitHub Desktop.
boxcar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# http://boxcar.io | |
# send message to mobile | |
__author__ = "Cloverstd" | |
import urllib | |
import urllib2 | |
import json | |
class Boxcar: | |
BASE_URL = "https://new.boxcar.io/api/" | |
SOUND = ["beep-crisp", | |
"beep-soft", | |
"bell-modern", | |
"bell-one-tone", | |
"bell-simple", | |
"bell-triple", | |
"bird-1", | |
"bird-2", | |
"boing", | |
"cash", | |
"clanging", | |
"detonator-charge", | |
"digital-alarm", | |
"done", | |
"echo", | |
"flourish", | |
"harp", | |
"light", | |
"magic-chime", | |
"magic-coin", | |
"notifier-1", | |
"notifier-2", | |
"notifier-3", | |
"orchestral-long", | |
"orchestral-short", | |
"score", | |
"success", | |
"up"] | |
def __init__(self, access_token): | |
self.access_token = access_token | |
def notice(self, title, message, sound): | |
result = self._send_notification(title, message, sound) | |
return json.loads(result) | |
def _send_notification(self, title, long_message, sound): | |
data = {"user_credentials": self.access_token, | |
"notification[title]": title, | |
"notification[long_message]": long_message, | |
"notification[sound]": sound | |
} | |
notifications_url = self.BASE_URL + "notifications" | |
response = urllib2.urlopen(notifications_url, urllib.urlencode(data)) | |
return response.read() | |
if __name__ == '__main__': | |
boxcar = Boxcar("ACCESS_TOKEN") | |
print boxcar.notice("这是测试", "<a href='//ooxx.hui.lu'>测试一下</a>", Boxcar.SOUND[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment