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

Commit

Permalink
init for meetup api
Browse files Browse the repository at this point in the history
- For #101
  • Loading branch information
VikramTiwari committed Mar 22, 2017
1 parent 91d80ca commit 7b3a9eb
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
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",
"method-override": "2.3.7",
"methods": "1.1.2",
"moment": "2.10.6",
Expand Down

0 comments on commit 7b3a9eb

Please sign in to comment.