From fa343212514f1e6f975e5cf5957e440555afb815 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 14 Apr 2016 14:14:34 -0400 Subject: example services --- examples/lib/okdumpfm/index.js | 39 ++++++++++++++++++++++++++++++++++++++ examples/lib/okdumpfm/package.json | 14 ++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 examples/lib/okdumpfm/index.js create mode 100644 examples/lib/okdumpfm/package.json (limited to 'examples/lib/okdumpfm') 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 diff --git a/examples/lib/okdumpfm/package.json b/examples/lib/okdumpfm/package.json new file mode 100644 index 0000000..17bcba2 --- /dev/null +++ b/examples/lib/okdumpfm/package.json @@ -0,0 +1,14 @@ +{ + "name": "okdumpfm", + "version": "1.0.0", + "description": "service to query the dump search API", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "okfocus ", + "license": "LNT", + "dependencies": { + "request": "^2.71.0" + } +} -- cgit v1.2.3-70-g09d2