Created
July 8, 2013 05:33
-
-
Save ErinCall/5946426 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var auth, querystring, sha1, sign, strftime, test_auth; | |
| strftime = require('strftime'); | |
| querystring = require('querystring'); | |
| sha1 = require('sha1'); | |
| module.exports = function(robot) { | |
| return robot.respond(/test/, function(msg) { | |
| return test_auth(robot, function(response) { | |
| return msg.send(response); | |
| }); | |
| }); | |
| }; | |
| test_auth = function(robot, cb) { | |
| var endpoint, params, query, signature, time; | |
| endpoint = "/test_authorization"; | |
| params = {}; | |
| time = strftime('%Y%m%dT%H:%M:%S'); | |
| signature = sign(time, endpoint, params); | |
| params.time = time; | |
| params.signature = signature; | |
| params.user_id = auth.user_id; | |
| query = querystring.stringify(params); | |
| console.log(params); | |
| return robot.http("http://www.radlibs.info" + endpoint).post(query)(function(err, res, body) { | |
| return cb(body); | |
| }); | |
| }; | |
| auth = { | |
| api_key: process.env.HUBOT_RADLIBS_API_KEY, | |
| user_id: process.env.HUBOT_RADLIBS_USER_ID | |
| }; | |
| sign = function(time, endpoint, params) { | |
| var plaintext; | |
| plaintext = time; | |
| plaintext += "\n"; | |
| Object.keys(params).sort().forEach(function(key) { | |
| return plaintext += key + params[key] + "\n"; | |
| }); | |
| plaintext += endpoint + "\n"; | |
| plaintext += auth.api_key; | |
| console.log(plaintext); | |
| return sha1(plaintext); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment