diff --git a/controllers/api.js b/controllers/api.js index 09c073efc1..2da5c03b09 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -186,19 +186,50 @@ exports.getLastfm = function(req, res) { secret: '4ae76d10d76cf680cebf4f0c8dea1aa4' }); - lastfm.request("artist.getInfo", { - artist: 'Evanescence', - handlers: { - success: function(data) { - console.log(data); - }, - error: function(error) { - console.log(error.message); - } - } + res.render('api/lastfm', { + title: 'Last.fm API', + }); }; +/** + * POST /api/lastfm + * Form submission to retrieve artist/track information + * Accessed via AJAX + */ +exports.postLastfm = function(req, res) { + if (req.body.track) { + lastfm.request("track.getInfo", { + artist: 'Evanescence', + track: 'My Immortal', + handlers: { + success: function(data) { + console.log(data); + return data; + }, + error: function(error) { + console.log(error.message); + return error.message; + } + } + }); + } + + if (req.body.artist) { + lastfm.request("artist.getInfo", { + artist: 'Evanescence', + handlers: { + success: function(data) { + console.log(data); + }, + error: function(error) { + console.log(error.message); + } + } + }); + } +}; + /** * GET /api/twitter * Twiter API example diff --git a/views/api/lastfm.jade b/views/api/lastfm.jade index a95f64a3d1..993b276a2a 100644 --- a/views/api/lastfm.jade +++ b/views/api/lastfm.jade @@ -16,4 +16,35 @@ block content i.fa.fa-file-text-o | Documentation - p last.fm api \ No newline at end of file + h3.text-primary Artist Information + form.form-horizontal(role='form', method='POST') + .form-group + label(class='col-sm-2 control-label', for='artist') Artist + .col-sm-4 + input.form-control(type='text', name='artist', id='artist') + .form-group + .col-sm-offset-2.col-sm-4 + button.btn.btn-primary-outline(type='submit') Submit + + .panel.panel-default + .panel-heading + h3.title #{artist.name} + .panel-body + .row + .col-xs-3 + img(src='#{artist.image}') + .col-xs-9 + strong Artist Bio + br + p= artist.bio + + + h3.text-primary Song Information + form.form-horizontal(role='form', method='POST') + .form-group + label(class='col-sm-2 control-label', for='artist') Song + .col-sm-4 + input.form-control(type='text', name='artist', id='artist') + .form-group + .col-sm-offset-2.col-sm-4 + button.btn.btn-primary-outline(type='submit') Submit