@@ -37,7 +37,6 @@ exports.getApi = function(req, res) {
37
37
38
38
exports . getFoursquare = function ( req , res , next ) {
39
39
var token = _ . find ( req . user . tokens , { kind : 'foursquare' } ) ;
40
- console . log ( token ) ;
41
40
async . parallel ( {
42
41
trendingVenues : function ( callback ) {
43
42
foursquare . Venues . getTrending ( '40.7222756' , '-74.0022724' , { limit : 50 } , token . accessToken , function ( err , results ) {
@@ -71,7 +70,7 @@ exports.getFoursquare = function(req, res, next) {
71
70
* Tumblr API example.
72
71
*/
73
72
74
- exports . getTumblr = function ( req , res ) {
73
+ exports . getTumblr = function ( req , res , next ) {
75
74
var token = _ . find ( req . user . tokens , { kind : 'tumblr' } ) ;
76
75
var client = tumblr . createClient ( {
77
76
consumer_key : secrets . tumblr . consumerKey ,
@@ -80,6 +79,7 @@ exports.getTumblr = function(req, res) {
80
79
token_secret : token . tokenSecret
81
80
} ) ;
82
81
client . posts ( 'withinthisnightmare.tumblr.com' , { type : 'photo' } , function ( err , data ) {
82
+ if ( err ) return next ( err ) ;
83
83
res . render ( 'api/tumblr' , {
84
84
title : 'Tumblr API' ,
85
85
blog : data . blog ,
@@ -128,7 +128,7 @@ exports.getScraping = function(req, res, next) {
128
128
if ( err ) return next ( err ) ;
129
129
var $ = cheerio . load ( body ) ;
130
130
var links = [ ] ;
131
- $ ( " .title a[href^=' http' ], a[href^=' https']" ) . each ( function ( ) {
131
+ $ ( ' .title a[href^=" http" ], a[href^=" https"]' ) . each ( function ( ) {
132
132
links . push ( $ ( this ) ) ;
133
133
} ) ;
134
134
res . render ( 'api/scraping' , {
@@ -142,11 +142,13 @@ exports.getScraping = function(req, res, next) {
142
142
* GET /api/github
143
143
* GitHub API Example.
144
144
*/
145
- exports . getGithub = function ( req , res ) {
145
+
146
+ exports . getGithub = function ( req , res , next ) {
146
147
var token = _ . find ( req . user . tokens , { kind : 'github' } ) ;
147
148
var github = new Github ( { token : token . accessToken } ) ;
148
149
var repo = github . getRepo ( 'sahat' , 'requirejs-library' ) ;
149
150
repo . show ( function ( err , repo ) {
151
+ if ( err ) return next ( err ) ;
150
152
res . render ( 'api/github' , {
151
153
title : 'GitHub API' ,
152
154
repo : repo
@@ -174,7 +176,8 @@ exports.getAviary = function(req, res) {
174
176
exports . getNewYorkTimes = function ( req , res , next ) {
175
177
var query = querystring . stringify ( { 'api-key' : secrets . nyt . key , 'list-name' : 'young-adult' } ) ;
176
178
var url = 'http://api.nytimes.com/svc/books/v2/lists?' + query ;
177
- request . get ( url , function ( error , request , body ) {
179
+ request . get ( url , function ( err , request , body ) {
180
+ if ( err ) return next ( err ) ;
178
181
if ( request . statusCode === 403 ) return next ( Error ( 'Missing or Invalid New York Times API Key' ) ) ;
179
182
var bestsellers = JSON . parse ( body ) ;
180
183
res . render ( 'api/nyt' , {
@@ -194,7 +197,7 @@ exports.getLastfm = function(req, res, next) {
194
197
async . parallel ( {
195
198
artistInfo : function ( done ) {
196
199
lastfm . request ( 'artist.getInfo' , {
197
- artist : 'Sirenia ' ,
200
+ artist : 'The Pierces ' ,
198
201
handlers : {
199
202
success : function ( data ) {
200
203
done ( null , data ) ;
@@ -207,7 +210,7 @@ exports.getLastfm = function(req, res, next) {
207
210
} ,
208
211
artistTopTracks : function ( done ) {
209
212
lastfm . request ( 'artist.getTopTracks' , {
210
- artist : 'Sirenia ' ,
213
+ artist : 'The Pierces ' ,
211
214
handlers : {
212
215
success : function ( data ) {
213
216
var tracks = [ ] ;
@@ -224,7 +227,7 @@ exports.getLastfm = function(req, res, next) {
224
227
} ,
225
228
artistTopAlbums : function ( done ) {
226
229
lastfm . request ( 'artist.getTopAlbums' , {
227
- artist : 'Sirenia ' ,
230
+ artist : 'The Pierces ' ,
228
231
handlers : {
229
232
success : function ( data ) {
230
233
var albums = [ ] ;
@@ -283,19 +286,16 @@ exports.getTwitter = function(req, res, next) {
283
286
284
287
/**
285
288
* POST /api/twitter
286
- * @param tweet
289
+ * Post a tweet.
287
290
*/
288
291
289
292
exports . postTwitter = function ( req , res , next ) {
290
293
req . assert ( 'tweet' , 'Tweet cannot be empty.' ) . notEmpty ( ) ;
291
-
292
294
var errors = req . validationErrors ( ) ;
293
-
294
295
if ( errors ) {
295
296
req . flash ( 'errors' , errors ) ;
296
297
return res . redirect ( '/api/twitter' ) ;
297
298
}
298
-
299
299
var token = _ . find ( req . user . tokens , { kind : 'twitter' } ) ;
300
300
var T = new Twit ( {
301
301
consumer_key : secrets . twitter . consumerKey ,
@@ -304,6 +304,7 @@ exports.postTwitter = function(req, res, next) {
304
304
access_token_secret : token . tokenSecret
305
305
} ) ;
306
306
T . post ( 'statuses/update' , { status : req . body . tweet } , function ( err , data , response ) {
307
+ if ( err ) return next ( err ) ;
307
308
req . flash ( 'success' , { msg : 'Tweet has been posted.' } ) ;
308
309
res . redirect ( '/api/twitter' ) ;
309
310
} ) ;
@@ -317,7 +318,6 @@ exports.postTwitter = function(req, res, next) {
317
318
exports . getSteam = function ( req , res , next ) {
318
319
var steamId = '76561197982488301' ;
319
320
var query = { l : 'english' , steamid : steamId , key : secrets . steam . apiKey } ;
320
-
321
321
async . parallel ( {
322
322
playerAchievements : function ( done ) {
323
323
query . appid = '49520' ;
@@ -330,18 +330,18 @@ exports.getSteam = function(req, res, next) {
330
330
playerSummaries : function ( done ) {
331
331
query . steamids = steamId ;
332
332
var qs = querystring . stringify ( query ) ;
333
- request . get ( { url : 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?' + qs , json : true } , function ( error , request , body ) {
333
+ request . get ( { url : 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?' + qs , json : true } , function ( err , request , body ) {
334
334
if ( request . statusCode === 401 ) return done ( new Error ( 'Missing or Invalid Steam API Key' ) ) ;
335
- done ( error , body ) ;
335
+ done ( err , body ) ;
336
336
} ) ;
337
337
} ,
338
338
ownedGames : function ( done ) {
339
339
query . include_appinfo = 1 ;
340
340
query . include_played_free_games = 1 ;
341
341
var qs = querystring . stringify ( query ) ;
342
- request . get ( { url : 'http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?' + qs , json : true } , function ( error , request , body ) {
342
+ request . get ( { url : 'http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?' + qs , json : true } , function ( err , request , body ) {
343
343
if ( request . statusCode === 401 ) return done ( new Error ( 'Missing or Invalid Steam API Key' ) ) ;
344
- done ( error , body ) ;
344
+ done ( err , body ) ;
345
345
} ) ;
346
346
}
347
347
} ,
@@ -370,25 +370,23 @@ exports.getStripe = function(req, res) {
370
370
371
371
/**
372
372
* POST /api/stripe
373
- * @param stipeToken
374
- * @param stripeEmail
373
+ * Make a payment.
375
374
*/
376
375
377
376
exports . postStripe = function ( req , res , next ) {
378
377
var stripeToken = req . body . stripeToken ;
379
378
var stripeEmail = req . body . stripeEmail ;
380
-
381
379
stripe . charges . create ( {
382
380
amount : 395 ,
383
381
currency : 'usd' ,
384
382
card : stripeToken ,
385
383
description : stripeEmail
386
384
} , function ( err , charge ) {
387
385
if ( err && err . type === 'StripeCardError' ) {
388
- req . flash ( 'errors' , { msg : 'Your card has been declined.' } ) ;
386
+ req . flash ( 'errors' , { msg : 'Your card has been declined.' } ) ;
389
387
res . redirect ( '/api/stripe' ) ;
390
388
}
391
- req . flash ( 'success' , { msg : 'Your card has been charged successfully.' } ) ;
389
+ req . flash ( 'success' , { msg : 'Your card has been charged successfully.' } ) ;
392
390
res . redirect ( '/api/stripe' ) ;
393
391
} ) ;
394
392
} ;
@@ -406,28 +404,22 @@ exports.getTwilio = function(req, res) {
406
404
407
405
/**
408
406
* POST /api/twilio
409
- * Twilio API example.
410
- * @param number
411
- * @param message
407
+ * Send a text message using Twilio.
412
408
*/
413
409
414
410
exports . postTwilio = function ( req , res , next ) {
415
411
req . assert ( 'number' , 'Phone number is required.' ) . notEmpty ( ) ;
416
412
req . assert ( 'message' , 'Message cannot be blank.' ) . notEmpty ( ) ;
417
-
418
413
var errors = req . validationErrors ( ) ;
419
-
420
414
if ( errors ) {
421
415
req . flash ( 'errors' , errors ) ;
422
416
return res . redirect ( '/api/twilio' ) ;
423
417
}
424
-
425
418
var message = {
426
419
to : req . body . number ,
427
420
from : '+13472235148' ,
428
421
body : req . body . message
429
422
} ;
430
-
431
423
twilio . sendMessage ( message , function ( err , responseData ) {
432
424
if ( err ) return next ( err . message ) ;
433
425
req . flash ( 'success' , { msg : 'Text sent to ' + responseData . to + '.' } ) ;
@@ -448,8 +440,7 @@ exports.getClockwork = function(req, res) {
448
440
449
441
/**
450
442
* POST /api/clockwork
451
- * Clockwork SMS API example.
452
- * @param telephone
443
+ * Send a text message using Clockwork SMS
453
444
*/
454
445
455
446
exports . postClockwork = function ( req , res , next ) {
@@ -473,7 +464,6 @@ exports.postClockwork = function(req, res, next) {
473
464
exports . getVenmo = function ( req , res , next ) {
474
465
var token = _ . find ( req . user . tokens , { kind : 'venmo' } ) ;
475
466
var query = querystring . stringify ( { access_token : token . accessToken } ) ;
476
-
477
467
async . parallel ( {
478
468
getProfile : function ( done ) {
479
469
request . get ( { url : 'https://api.venmo.com/v1/me?' + query , json : true } , function ( err , request , body ) {
@@ -483,7 +473,6 @@ exports.getVenmo = function(req, res, next) {
483
473
getRecentPayments : function ( done ) {
484
474
request . get ( { url : 'https://api.venmo.com/v1/payments?' + query , json : true } , function ( err , request , body ) {
485
475
done ( err , body ) ;
486
-
487
476
} ) ;
488
477
}
489
478
} ,
@@ -499,32 +488,24 @@ exports.getVenmo = function(req, res, next) {
499
488
500
489
/**
501
490
* POST /api/venmo
502
- * @param user
503
- * @param note
504
- * @param amount
505
491
* Send money.
506
492
*/
507
493
508
494
exports . postVenmo = function ( req , res , next ) {
509
495
req . assert ( 'user' , 'Phone, Email or Venmo User ID cannot be blank' ) . notEmpty ( ) ;
510
496
req . assert ( 'note' , 'Please enter a message to accompany the payment' ) . notEmpty ( ) ;
511
497
req . assert ( 'amount' , 'The amount you want to pay cannot be blank' ) . notEmpty ( ) ;
512
-
513
498
var errors = req . validationErrors ( ) ;
514
-
515
499
if ( errors ) {
516
500
req . flash ( 'errors' , errors ) ;
517
501
return res . redirect ( '/api/venmo' ) ;
518
502
}
519
-
520
503
var token = _ . find ( req . user . tokens , { kind : 'venmo' } ) ;
521
-
522
504
var formData = {
523
505
access_token : token . accessToken ,
524
506
note : req . body . note ,
525
507
amount : req . body . amount
526
508
} ;
527
-
528
509
if ( validator . isEmail ( req . body . user ) ) {
529
510
formData . email = req . body . user ;
530
511
} else if ( validator . isNumeric ( req . body . user ) &&
@@ -533,7 +514,6 @@ exports.postVenmo = function(req, res, next) {
533
514
} else {
534
515
formData . user_id = req . body . user ;
535
516
}
536
-
537
517
request . post ( 'https://api.venmo.com/v1/payments' , { form : formData } , function ( err , request , body ) {
538
518
if ( err ) return next ( err ) ;
539
519
if ( request . statusCode !== 200 ) {
@@ -553,7 +533,6 @@ exports.postVenmo = function(req, res, next) {
553
533
exports . getLinkedin = function ( req , res , next ) {
554
534
var token = _ . find ( req . user . tokens , { kind : 'linkedin' } ) ;
555
535
var linkedin = Linkedin . init ( token . accessToken ) ;
556
-
557
536
linkedin . people . me ( function ( err , $in ) {
558
537
if ( err ) return next ( err ) ;
559
538
res . render ( 'api/linkedin' , {
@@ -570,10 +549,8 @@ exports.getLinkedin = function(req, res, next) {
570
549
571
550
exports . getInstagram = function ( req , res , next ) {
572
551
var token = _ . find ( req . user . tokens , { kind : 'instagram' } ) ;
573
-
574
552
ig . use ( { client_id : secrets . instagram . clientID , client_secret : secrets . instagram . clientSecret } ) ;
575
553
ig . use ( { access_token : token . accessToken } ) ;
576
-
577
554
async . parallel ( {
578
555
searchByUsername : function ( done ) {
579
556
ig . user_search ( 'richellemead' , function ( err , users , limit ) {
@@ -611,6 +588,7 @@ exports.getInstagram = function(req, res, next) {
611
588
* GET /api/yahoo
612
589
* Yahoo API example.
613
590
*/
591
+
614
592
exports . getYahoo = function ( req , res ) {
615
593
Y . YQL ( 'SELECT * FROM weather.forecast WHERE (location = 10007)' , function ( response ) {
616
594
var location = response . query . results . channel . location ;
0 commit comments