Skip to content

Instantly share code, notes, and snippets.

@mattsacks
Created September 26, 2011 20:51
Show Gist options
  • Save mattsacks/1243374 to your computer and use it in GitHub Desktop.
Save mattsacks/1243374 to your computer and use it in GitHub Desktop.

Requires Coffeescript and Node.js

Use with cake -t 'The Terminal' -s 'message sent!' ping or any combination of options to send a push notification.

https = require 'https'
url = require 'url'
querystring = require 'querystring'
credentials = 'sekret'
option '-m', '--message [MESSAGE]', 'message to send'
option '-t', '--title [TITLE]', 'title in the notification'
option '-l', '--longmessage [LONGMESSAGE]', 'longmessage to send'
option '-s', '--subtitle [SUBTITLE]', 'subtitle of the notification'
option '-n', '--notification [SOUND]', 'sound to ring with'
request =
host: 'www.appnotifications.com'
port: 443
path: '/account/notifications.json' +
url.format(search: "user_credentials=#{credentials}")
method: 'POST'
task 'ping', 'ping my iphone something', (options)->
request.path += '&' + querystring.stringify
'notification[sound]': options.notification or '02'
'notification[message]': options.message or 'message'
'notification[title]': options.title or 'title'
'notification[long_message]': options.longmessage or 'long_message'
'notification[subtitle]': options.subtitle or 'subtitle'
'notification[silent]': options.silent or 'false'
req = https.request request, (res) ->
console.log request
res.on 'data', (d) ->
process.stdout.write d
req.end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment