summaryrefslogtreecommitdiff
path: root/examples/lib/okdumpfm/index.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-09-02 13:24:55 -0400
committerJules Laplace <jules@okfoc.us>2016-09-02 13:24:55 -0400
commit8def9579f2a78e80652d1e5e6f1eda510ae9a5dd (patch)
treec56d664f04d55f0d75c6d4f5e2d6fc567054498d /examples/lib/okdumpfm/index.js
parent4ed81fa59119cee66b0413c5662639ec81fea4dc (diff)
parent5052d51aa4c55eabc736b3c76a783db2f5208289 (diff)
merge changes from twohustlers
Diffstat (limited to 'examples/lib/okdumpfm/index.js')
-rw-r--r--examples/lib/okdumpfm/index.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/examples/lib/okdumpfm/index.js b/examples/lib/okdumpfm/index.js
new file mode 100644
index 0000000..4dc5461
--- /dev/null
+++ b/examples/lib/okdumpfm/index.js
@@ -0,0 +1,39 @@
+var request = require('request')
+
+/**
+ * Example service which queries the Dump search.
+ */
+function OKDumpfm (options) {
+ if (!(this instanceof OKDumpfm)) return new OKDumpfm(options)
+ options = options || {}
+ if (!options.express)
+ throw new Error('Express not provided to OKDumpfm');
+
+ var express = options.express
+ var router = express.Router()
+
+ router.get('*', function (req, res) {
+ var query = req.query.q
+ request('http://dump.fm/cmd/search/' + query, function (err, response, body) {
+ if (err || response.statusCode !== 200) {
+ res.status(response.statusCode)
+ res.send(err)
+ } else {
+ res.set('Content-Type', 'application/json; charset=utf-8')
+ res.send(body)
+ }
+ })
+ })
+
+ router.post('*', function (req, res) {
+ throw new Error('OKDumpfm POST requests not implemented')
+ })
+
+ this._router = router
+}
+
+OKDumpfm.prototype.middleware = function () {
+ return this._router
+}
+
+module.exports = OKDumpfm