Skip to content

Commit

Permalink
Adding clockwork SMS to the API mix
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Roberts committed Feb 24, 2014
1 parent 4df8710 commit 5acf499
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var mongoose = require('mongoose');
var passport = require('passport');
var expressValidator = require('express-validator');



/**
* Load controllers.
*/
Expand Down Expand Up @@ -117,6 +119,8 @@ app.get('/api/paypal/cancel', apiController.getPayPalCancel);
app.get('/api/steam', apiController.getSteam);
app.get('/api/scraping', apiController.getScraping);
app.get('/api/twilio', apiController.getTwilio);
app.get('/api/clockwork', apiController.getClockwork);
app.post('/api/clockwork', apiController.postClockwork);
app.post('/api/twilio', apiController.postTwilio);
app.get('/api/foursquare', passportConf.isAuthenticated, passportConf.isAuthorized, apiController.getFoursquare);
app.get('/api/tumblr', passportConf.isAuthenticated, passportConf.isAuthorized, apiController.getTumblr);
Expand Down
8 changes: 6 additions & 2 deletions config/secrets.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ module.exports = {
},

twilio: {
sid: 'Your Account SID',
token: 'Your Auth Token'
sid: 'Your twilio SID',
token: 'Your twilio token'
},

clockwork: {
apiKey: 'Your clockwork SMS API Key'
},

tumblr: {
Expand Down
33 changes: 33 additions & 0 deletions controllers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var Github = require('github-api');
var Twit = require('twit');
var paypal = require('paypal-rest-sdk');
var twilio = require('twilio')(secrets.twilio.sid, secrets.twilio.token);
var clockwork = require('clockwork')({key: secrets.clockwork.apiKey});

/**
* GET /api
Expand Down Expand Up @@ -415,6 +416,38 @@ exports.postTwilio = function(req, res, next) {
});
};


/**
* GET /api/Clockwork
* Clockwork SMS API example.
*/

exports.getClockwork = function(req, res, next) {
res.render('api/clockwork', {
title: 'Clockwork SMS API'
});
};


/**
* POST /api/clockwork
* Clockwork SMS API example.
* @param telephone
*/

exports.postClockwork = function(req, res, next) {
var message = {
To: req.body.telephone,
From: 'Hackathon',
Content: 'Hello from the Hackathon Starter'
};
clockwork.sendSms(message, function(err, responseData) {
if (err) return next(err.message);
req.flash('success', { msg: 'Text sent to ' + responseData.SMS_Resp.To});
res.redirect('/api/clockwork');
});
};

exports.getVenmo = function(req, res, next) {
var token = _.findWhere(req.user.tokens, { kind: 'venmo' });
var query = querystring.stringify({ access_token: token.accessToken });
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"paypal-rest-sdk": "~0.6.4",
"connect-mongo": "~0.4.0",
"twilio": "~1.5.0",
"validator": "~3.2.1"
"validator": "~3.2.1",
"clockwork": "0.1.0"
}
}
29 changes: 29 additions & 0 deletions views/api/clockwork.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
extends ../layout

block content
.page-header
h2
i.fa.fa-phone
| Clockwork SMS API

.btn-group.btn-group-justified
a.btn.btn-primary(href='http://github.com/mediaburst/node-clockwork', target='_blank')
i.fa.fa-check-square-o
| Clockwork Node
//- a.btn.btn-primary(href='https://apigee.com/console/twilio', target='_blank')
//- i.fa.fa-laptop
//- | API Console
a.btn.btn-primary(href='http://www.clockworksms.com/doc/clever-stuff/xml-interface/send-sms/', target='_blank')
i.fa.fa-code-fork
| XML API

h4 Send a text message
.row
.col-sm-6
form(role='form', method='POST')
input(type='hidden', name='_csrf', value=token)
.form-group
.input-group
input.form-control(type='text', name='telephone', placeholder='Phone Number')
span.input-group-btn
button.btn.btn-success(type='submit') Send
2 changes: 2 additions & 0 deletions views/api/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ block content
a(href='/api/steam') Steam
li
a(href='/api/twilio') Twilio
li
a(href='/api/clockwork') Clockwork SMS
li
a(href='/api/tumblr') Tumblr
small ⇢ Login Required
Expand Down

0 comments on commit 5acf499

Please sign in to comment.