Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

meetup api #119

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions functions/meetup-data-ingestion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
'use strict'

const PubSub = require('@google-cloud/pubsub')
const pubsub = PubSub()

const MEETUP_API_KEY = process.env.MEETUP_API_KEY || 'NO_KEY_SPECIFIED'
const meetup = require('meetup-api')({key: MEETUP_API_KEY})

/**
* Publishes a message to a Cloud Pub/Sub Topic.
* This is to be used along with a CRON job in the code that is part of hub app
*
* @example
* gcloud alpha functions call publish --data '{"topic":"[meetup_data_ingestion]","message":"Hello, world!"}'
*
* - Replace `[meetup_data_ingestion]` with your Cloud Pub/Sub topic name.
*
* @param {object} req Cloud Function request context.
* @param {object} req.body The request body.
* @param {string} req.body.topic Topic name on which to publish.
* @param {string} req.body.message Message to publish.
* @param {object} res Cloud Function response context.
*/
exports.publish = function publish (req, res) {
if (!req.body.topic) {
res.status(500).send(new Error('Topic not provided. Make sure you have a "topic" property in your request'))
return
} else if (!req.body.message) {
res.status(500).send(new Error('Message not provided. Make sure you have a "message" property in your request'))
return
}

console.log(`Publishing message to topic ${req.body.topic}`)

// References an existing topic
const topic = pubsub.topic(req.body.topic)

const message = {
data: {
message: req.body.message
}
}

// Publishes a message
return topic.publish(message)
.then(() => res.status(200).send('Message published.'))
.catch((err) => {
console.error(err)
res.status(500).send(err)
return Promise.reject(err)
})
}

/**
* Triggered from a message on a Cloud Pub/Sub topic.
* This will be used on functions where it will be listening to the publish event
*
* @param {object} event The Cloud Functions event.
* @param {object} event.data The Cloud Pub/Sub Message object.
* @param {string} event.data.data The "data" property of the Cloud Pub/Sub Message.
* @param {function} The callback function.
*/
exports.subscribe = function subscribe (event, callback) {
const pubsubMessage = event.data

// We're just going to log the message to prove that it worked!
console.log(Buffer.from(pubsubMessage.data, 'base64').toString())

// Don't forget to call the callback!
callback()
}

function getMyEvents () {
meetup.getEvents({'member_id': 'self'}, logger)
}

function logger (err, result) {
if (err) {
console.error(err)
} else {
console.log(result)
}
}

getMyEvents()
7 changes: 5 additions & 2 deletions lib/config/keys.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
'use strict'

module.exports = {
keys: {
Expand All @@ -13,6 +13,9 @@ module.exports = {
frisbee: {
serverClientId: process.env.SERVER_KEY_SECRET,
androidClientIds: process.env.ANDROID_CLIENT_IDS.split(',')
},
meetup: {
apiKey: process.env.MEETUP_API_KEY
}
}
};
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"version": "0.2.1",
"dependencies": {
"@google-cloud/pubsub": "^0.8.3",
"async": "1.4.2",
"body-parser": "1.17.1",
"burrito": "0.2.12",
Expand All @@ -36,6 +37,7 @@
"google-oauth-jwt": "0.1.7",
"googleapis": "0.8.0",
"lodash": "2.4.1",
"meetup-api": "^1.4.9",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but please always use pinned/fixed versions for reproducible builds.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a really bad approach, not to mention that it's ineffective. Almost all packages that are in Node ecosystem use semver approach. Even if we pin a dependency to be a fixed version, it's dependencies might not be fixed. Moreover, by using fixed dependency we are saying no to security and performance patches for that package.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel very strongly that the alternative approach is worse and I have a lot of experience with this to back my claims. It leads to developers not being able to build the app or having different bugs that other developers don't see. It leads to blocked deployments due to breaking changes since the NodeJS ecosystem doesn't actually follow semver and introduces breaking changes in minor/patch releases.

It's good to upgrade dependencies and get perf/security fixes frequently, but it's best to choose when you want your project to break rather than having some rogue developer push something to NPM which brings down apps/builds across the world. Using pinned dependencies, you are in control of when your project breaks and you can do it when you have time to manage the breaking changes rather than right before a major deadline/release when random issues block everything.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we already had these kind of problems in this repo couple of times already, I would also suggest to keep them strict for reproducable builds.

"method-override": "2.3.7",
"methods": "1.1.2",
"moment": "2.10.6",
Expand Down