Skip to content

Instantly share code, notes, and snippets.

View dmfenton's full-sized avatar

Daniel Fenton dmfenton

  • JLL Technologies
  • Washington, DC
  • X @Dmfenton
View GitHub Profile
@dmfenton
dmfenton / index.js
Last active March 2, 2017 15:22
Example Koop Index.js
module.exports = {
name: 'agol', // Required, the name of this provider and the start of all its URLS
type: 'provider', // Required, the type of Koop Plugin this is
version: require('./package.json').version, // Required, the version of this provider
Model: require('./agol'), // Required contains getData and other functions called by controller
hosts: true, // Optional, whether or not `getData` should receive a `host` parameter
disableIdParam: false, // Optional, whether or not `getData` should receive an `id` parameter
routes: require('./routes'), // Optional, any additional routes that should be handled by this provider
Controller: require('./controller'), // Optional, a controller to support unique routes
}
/*
Example request: http://koop.com/craigslist/washingtondc/apartments/FeatureServer/0/query?where=price>20&f=geojson
Req is the express request object: https://expressjs.com/en/4x/api.html#req
req.params = {
host: 'washingtondc',
id: 'apartments'
}
req.query = {
where: 'price > 20',
f: geojson
@dmfenton
dmfenton / routes.js
Last active February 23, 2017 22:33
module.exports = [
{
path: '/agol/:id/datasets',
methods: ['get'],
handler: 'get'
},
{
path: '/agol/:id/datasets/:dataset.:format',
methods: ['get'],
handler: 'get'
module.exports = function (model) {
this.model = model
/**
* returns a list of the registered hosts and their ids
*/
this.get = function (req, res) {
this.model.log.debug({route: 'dataset:get', params: req.params, query: req.query})
if (req.params.dataset) this._getDataset(req, res)
else this._getDatasets(req, res)
}
'use strict'
const ttl = 60 * 60
const request = require('request').defaults({gzip: true})
const types = require('./mappings/types.js')
module.exports = function (koop) {
// This is our one public function it's job its to fetch data from craigslist and return as a feature collection
this.getData = function (req, callback) {
const key = `craigslist::${req.params.host}::${req.params.id}`
koop.cache.retrieve(key, req.query, (err, geojson) => {
if (geojson) {
const Koop = require('koop')
const koop = new Koop()
koop.server.listen(80)
const express = require('express')
const app = express()
const Koop = new Koop()
app.use(koop.server)
app.listen(80)
//clean shutdown
process.on('SIGINT', () => process.exit(0))
process.on('SIGTERM', () => process.exit(0))
// Initialize Koop
const Koop = require('koop')
const koop = new Koop()
// Install the Yelp Provider
const yelp = require('yelp')
{
"name": "koop-trimet",
"version": "1.0.8",
"description": "A Trimet provider for koop",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"start": "node server.js",
@dmfenton
dmfenton / REST
Last active August 25, 2017 13:58
Koop Aggregator
GET /:provider/:id
DELETE /:provider/:id
PUT /:provider/:id Content-Type: application/json
{
name:
description:
schemas: {
georgia: {
},