Created
August 27, 2015 20:25
-
-
Save MrCoffey/6a8f8319ff7441db587d to your computer and use it in GitHub Desktop.
Product hunter
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
Slack = require('slack-node') | |
os = require('os') | |
jsonHttp = require('json-http') | |
#Slack stuff | |
webhookUri = 'https://hooks.slack.com/services/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' | |
slack = new Slack | |
slack.setWebhook webhookUri | |
#Kimono uri | |
productsUrl = 'http://www.kimonolabs.com/api/92bh1m08?apikey=K62btvEgWDCF5tcbDcSTgoT4Bu0FIJCX' | |
#Get products form kimono | |
jsonHttp.getJson productsUrl, (err, response) -> | |
if err isnt "null" | |
productsArray = response["results"]["products"] #Return an array with all the products | |
productsList(productsArray) | |
else | |
console.log "Houston we have an error: " + err | |
#Parse the array which contains the products | |
productsList = (productsArray) -> | |
attachments = [] | |
productsArray.forEach (product)-> | |
pNumber = product["index"] | |
pName = product["name"].text | |
pUrl = product["name"].href | |
pPlatform = product["platform"] | |
pVotes = product["votes"].text | |
attachments.push({ | |
"fallback": pName, | |
"title_link": pUrl, | |
"text": pPlatform, | |
"text": pVotes, | |
"color": "#7CD197" | |
}) | |
#Send attachament object to the slack room | |
slack.webhook productsObject(attachments), (err, response) -> | |
console.log 'Listo ☕' | |
#Return the string that will be prompted into the slack room | |
productsObject = (attachments) -> | |
{ | |
channel: '#home', | |
username: '@jorge', | |
attachments: attachments | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment