Created
June 25, 2011 05:12
-
-
Save NuckChorris/1046173 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
exports.flex_get = function(key, secret, path) { | |
return function(req, res, next) { | |
var apisig = crypto.createHash('md5').update(secret + 'ApiKey' + key + 'ServicePath/v1' + path + 'AuthToken' + req.flex_auth_token).digest('hex'); | |
var options = { | |
host: 'api.website.com', | |
port: 443, | |
path: '/v1' + path + '?AuthToken=' + req.flex_auth_token + '&ApiSig=' + apisig, | |
method: 'GET' | |
}; | |
var request = https.request(options, function(response) { | |
response.setEncoding('utf8'); | |
var body = ''; | |
response.on('data', function(d) { | |
body += d; | |
}); | |
response.on('end',function(){ | |
req.flex_data = body; | |
next(); | |
}); | |
}); | |
request.end(); | |
request.on('error', function(e) { | |
console.error(e); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment