Created
May 20, 2014 19:15
-
-
Save jedahan/1e29c040bc64c4dcfaf7 to your computer and use it in GitHub Desktop.
I have no idea how to use generators, eh...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
q = require 'q' | |
request = q.denodeify require 'request' | |
xml2js = require 'xml2js' | |
parser = new xml2js.Parser() | |
parseString = q.denodeify parser.parseString | |
api = "http://www.metmuseum.org/collection/the-collection-online/search" | |
getEndpoint = (endpoint) -> | |
(next) --> | |
start = Date.now() | |
yield request api+endpoint | |
delta = Math.ceil(Date.now() - start) | |
@set 'X-Response-Time-Upstream', delta + 'ms' | |
getObject = (next) --> | |
xml = yield getEndpoint "/#{@params['id']}?xml=1" | |
@body = yield parseString xml | |
koa = require 'koa' | |
logger = require 'koa-logger' | |
router = require 'koa-router' | |
app = koa() | |
app.use logger() | |
app.use router(app) | |
app.get '/object/:id', getObject | |
app.get '/search/:term', getIds | |
app.listen process.env.PORT or 5000, -> | |
console.log "[#{process.pid}] listening on port #{+@_connectionKey.split(':')[2]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "collections-api", | |
"homepage": "http://scrAPI.org", | |
"bugs": "http://github.com/jedahan/collections-api/issues", | |
"contributors": [ | |
"Jonathan Dahan" | |
], | |
"licenses": [ | |
"ISC" | |
], | |
"version": "0.0.9", | |
"description": "frontend api services", | |
"author": "Jonathan Dahan <jonathan@jonathan.is>", | |
"keywords": [ | |
"scrape", | |
"api", | |
"museum" | |
], | |
"dependencies": { | |
"coffee-script": "https://github.com/xixixao/coffee-script/tarball/master", | |
"koa": "^0.6.1", | |
"koa-logger": "^1.2.1", | |
"koa-router": "^3.1.4", | |
"q": "^1.0.1", | |
"request": "^2.35.0", | |
"xml2js": "^0.4.2" | |
}, | |
"engines": { | |
"node": "^0.11.13", | |
"npm": "^1.4.9" | |
}, | |
"scripts": { | |
"start": "coffee --nodejs --harmony server.coffee" | |
}, | |
"repository": { | |
"type": "git", | |
"url": "http://github.com/jedahan/collections-api.git" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment