summaryrefslogtreecommitdiff
path: root/examples/lib
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-08-17 02:18:49 -0400
committerJules Laplace <jules@okfoc.us>2016-08-17 02:18:49 -0400
commit7bb493d94240513635fca668d169256aa502d009 (patch)
tree1ac9c5fa78041c8f05f2092127b4d2d529d251f8 /examples/lib
parent071fdf9d53becb08b6a54c8c49effcb6c1a23e98 (diff)
parent6ca70643c18df738fbad5a4e13b1c48fab9ea430 (diff)
Merge branch 'twohustlers' of github.com:okfocus/okcms into twohustlers
Diffstat (limited to 'examples/lib')
-rw-r--r--examples/lib/okdumpfm/index.js39
-rw-r--r--examples/lib/okdumpfm/package.json14
-rw-r--r--examples/lib/okexample/index.js49
-rw-r--r--examples/lib/okexample/package.json11
4 files changed, 113 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
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 <frontdesk@okfoc.us>",
+ "license": "LNT",
+ "dependencies": {
+ "request": "^2.71.0"
+ }
+}
diff --git a/examples/lib/okexample/index.js b/examples/lib/okexample/index.js
new file mode 100644
index 0000000..04c5984
--- /dev/null
+++ b/examples/lib/okexample/index.js
@@ -0,0 +1,49 @@
+
+/**
+ * Example service to show how these things should be set up.
+ *
+ * Services should be added to index.js in the proper area,
+ * with any configuration parameters that you want passed in:
+ *
+ * services: {
+ * example: {
+ * lib: require("./lib/okexample"),
+ * stuff: "things",
+ * }
+ * },
+ *
+ * The service will be mounted on /_services/example
+ *
+ * This binds to route '*' but you can specify e.g. "/thing",
+ * and it will be mounted on /_services/example/thing
+ */
+
+function OKExample (options) {
+ if (!(this instanceof OKExample)) return new OKExample(options)
+ options = options || {}
+ if (!options.express)
+ throw new Error('Express not provided to OKExample');
+ if (!options.config)
+ throw new Error('Configuration not provided to OKExample');
+
+ var express = options.express
+ var router = express.Router()
+ var config = options.config
+ var db = options.db
+
+ router.get('*', function (req, res) {
+ res.send(config.stuff)
+ })
+
+ router.post('*', function (req, res) {
+ throw new Error('OKExample POST requests not implemented')
+ })
+
+ this._router = router
+}
+
+OKExample.prototype.middleware = function () {
+ return this._router
+}
+
+module.exports = OKExample
diff --git a/examples/lib/okexample/package.json b/examples/lib/okexample/package.json
new file mode 100644
index 0000000..2b2a47c
--- /dev/null
+++ b/examples/lib/okexample/package.json
@@ -0,0 +1,11 @@
+{
+ "name": "okexample",
+ "version": "1.0.0",
+ "description": "example service",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "author": "okfocus <frontdesk@okfoc.us>",
+ "license": "LNT"
+}