public
Created

smsified-node-coffee

  • Download Gist
smsified-node.coffee
CoffeeScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
http = require 'http'
express = require 'express'
querystring = require 'querystring'
app = express.createServer()
 
app.configure( ->
app.use express.bodyParser()
)
 
app.post('/', (req, res) ->
post_data = querystring.stringify({
'address' : 'xxxxxxxxxx'
'message': "callerID: #{req.body['inboundSMSMessageNotification']['inboundSMSMessage']['senderAddress']} said: #{req.body['inboundSMSMessageNotification']['inboundSMSMessage']['message']}"
})
post_options = {
host: 'api.smsified.com'
port: '80'
path: '/v1/smsmessaging/outbound/xxxxxxxxxx/requests'
method: 'POST'
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
'Content-Length': post_data.length
'Authorization':"Basic "+ new Buffer('username' + ":" + "password").toString('base64')
}
}
post_req = http.request(post_options, (res) ->
res.setEncoding 'utf8'
)
post_req.write post_data
post_req.end()
res.end()
)
app.listen(10085)

Warning UN-TESTED

Same as above but implemented in Meryl and Fermata

meryl = require 'meryl'
fermata = require 'fermata'
# https://github.com/andyet/fermata
api = fermata.api 
  url: 'http://api.smsified.com/v1/smsmessaging/outbound/xxxxxxxxxx/requests'
  user: 'username'
  password: 'password'


meryl
  .post '/', (req, res) ->
    # get posted data
    request_data = JSON.parse(req.postdata.toString())
    # build restful post data
    data = JSON.stringify
      address: 'xxxxxxxxxxxx'
      message:
        callerID: request_data.inboundSMSMessageNotification.inboundSMSMessage.senderAddress
        said: request_data.inboundSMSMessageNotification.inboundSMSMessage.message

    # send restful data
    api.post data, (err, result) ->
      res.end()
  .run(10085)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.