commit 52b72f1372dc9009fc406ec70d4f5173582615ec Author: Matthias Kretschmann Date: Mon May 29 14:20:58 2017 +0200 💫 initial commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b64e0cd --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ + +# EditorConfig is awesome: http://EditorConfig.org + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +insert_final_newline = true +charset = utf-8 +trim_trailing_whitespace = true + +[*.json] +indent_size = 2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fad8828 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules +npm-debug.log +yarn.lock +package-lock.json diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..83a38c6 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: node_js +node_js: node + +notifications: + email: false diff --git a/index.js b/index.js new file mode 100755 index 0000000..449b6ff --- /dev/null +++ b/index.js @@ -0,0 +1,59 @@ +const fetch = require('node-fetch') +const ms = require('ms') +const chalk = require('chalk') + +let data = [] +const url = 'https://api.meetup.com/BigchainDB-IPDB-Meetup/events' + +const log = text => console.log(text) +const logError = text => console.log(chalk.bold.red(text)) + +// Response handling for all fetch calls +const handleResponse = res => { + if (res.status !== 200) { + return logError('Non-200 response code from Meetup: ' + res.status) + } + return res.json() +} + +// +// Fetch all upcoming meetups +// +const fetchMeetups = () => { + const start = Date.now() + + fetch(url) + .then(res => { + return handleResponse(res) + }) + .then(data_ => { + if (!data_) { + return + } + + data = data_ + + log(`Re-built meetups cache. ` + + `Total: ${data_.length} public meetups. ` + + `Elapsed: ${(new Date() - start)}ms`) + }) + .catch(err => { + logError('Error parsing response from Meetup: ' + err.stack) + }) +} + +// +// Let's roll, and roll again every X ms +// +fetchMeetups() +setInterval(fetchMeetups, ms('15m')) + +// +// Create the response +// +module.exports = async (req, res) => { + res.setHeader('Access-Control-Allow-Origin', '*') + res.setHeader('Access-Control-Allow-Methods', 'GET') + + return data +} diff --git a/license.md b/license.md new file mode 100755 index 0000000..af200da --- /dev/null +++ b/license.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 BigchainDB GmbH + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/media/repo-banner.sketch b/media/repo-banner.sketch new file mode 100644 index 0000000..d492435 Binary files /dev/null and b/media/repo-banner.sketch differ diff --git a/media/repo-banner@2x.png b/media/repo-banner@2x.png new file mode 100644 index 0000000..7d86707 Binary files /dev/null and b/media/repo-banner@2x.png differ diff --git a/package.json b/package.json new file mode 100644 index 0000000..e1c77af --- /dev/null +++ b/package.json @@ -0,0 +1,34 @@ +{ + "name": "bigchaindb-meetups", + "private": true, + "version": "1.0.0", + "scripts": { + "start": "micro", + "test": "xo && ava" + }, + "xo": { + "esnext": true, + "space": 4, + "semicolon": false, + "rules": { + "camelcase": 0 + } + }, + "dependencies": { + "chalk": "1.1.3", + "micro": "7.3.3", + "ms": "2.0.0", + "node-fetch": "1.6.3" + }, + "devDependencies": { + "ava": "^0.19.1", + "request": "^2.81.0", + "request-promise": "^4.2.1", + "test-listen": "^1.0.2", + "xo": "^0.18.2" + }, + "alias": "bigchaindb-meetups.now.sh", + "env": { + "NODE_ENV": "production" + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..4258ed2 --- /dev/null +++ b/readme.md @@ -0,0 +1,101 @@ +# [![meetups](media/repo-banner@2x.png)](https://www.bigchaindb.com) + +> Microservice to cache and expose [our upcoming Meetups](https://www.meetup.com/BigchainDB-IPDB-Meetup/) for use throughout [www.bigchaindb.com](https://www.bigchaindb.com). + +[![Build Status](https://travis-ci.org/bigchaindb/meetups.svg?branch=master)](https://travis-ci.org/bigchaindb/meetups) +[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo) +[![Greenkeeper badge](https://badges.greenkeeper.io/bigchaindb/meetups.svg)](https://greenkeeper.io/) + + + + +## API + +Endpoint: [`https://bigchaindb-meetups.now.sh`](https://bigchaindb-meetups.now.sh) + +### GET / + +**200**: Returns all upcoming meetups, e.g.: + +```json +[ + { + created: 1480492250000, + id: "235925067", + name: "Privacy on the Blockchain", + rsvp_limit: 55, + status: "upcoming", + time: 1496854800000, + updated: 1495634541000, + utc_offset: 7200000, + waitlist_count: 9, + yes_rsvp_count: 61, + venue: { + id: 24947394, + name: "BlueYard", + lat: 52.49262237548828, + lon: 13.413067817687988, + repinned: false, + address_1: "Grimmstraße 13, 10967 ", + city: "Berlin", + country: "de", + localized_country_name: "Germany" + }, + group: { + created: 1480330155000, + name: "BigchainDB & IPDB Meetup", + id: 21301439, + join_mode: "open", + lat: 52.52000045776367, + lon: 13.380000114440918, + urlname: "BigchainDB-IPDB-Meetup", + who: "Members" + }, + link: "https://www.meetup.com/BigchainDB-IPDB-Meetup/events/235925067/", + description: "" + visibility: "public" + }, + ... +] +``` + +## Development + +Install dependencies: + +```bash +npm install +``` + +And run the server: + +```bash +npm start +``` + +## Test + +Run the tests: + +```bash +npm test +``` + +## Deployment + +Deploy to [now](https://zeit.co/now), make sure to switch to BigchainDB org before deploying: + +```bash +# first run +now login +now switch + +# deploy +now +# switch alias to new deployment, e.g. +now alias bigchaindb-meetups-wxkyissxos bigchaindb-meetups +``` + +## Authors + +- Matthias Kretschmann ([@kremalicious](https://github.com/kremalicious)) - [BigchainDB](https://www.bigchaindb.com) diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..624b839 --- /dev/null +++ b/test/index.js @@ -0,0 +1,17 @@ +import micro from 'micro' +import test from 'ava' +import listen from 'test-listen' +import request from 'request-promise' + +test('it works', async t => { + const service = micro(async (req, res) => { + micro.send(res, 200, { + test: 'woot' + }) + }) + + const url = await listen(service) + const body = await request(url) + + t.deepEqual(JSON.parse(body).test, 'woot') +})