This repository has been archived by the owner on Sep 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
meetup api #119
Open
VikramTiwari
wants to merge
2
commits into
develop
Choose a base branch
from
feature/vikram/meetup_api_poc
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
meetup api #119
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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() |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.