Permalink
Browse files

Merge pull request #14 from jplock/master

Simplified dependencies by using built-in modules. The package.json will be updated shortly based on the pull request from nathanwdavis made the other day.
  • Loading branch information...
2 parents 67fe959 + 166b3c7 commit ef0abc8685a472b2a8733093cea92c600905d21b @mansilladev mansilladev committed Mar 27, 2012
Showing with 13 additions and 10 deletions.
  1. +13 −8 app.js
  2. +0 −2 package.json
View
@@ -27,21 +27,20 @@
var express = require('express'),
util = require('util'),
fs = require('fs'),
- sys = require('sys'),
OAuth = require('oauth').OAuth,
query = require('querystring'),
url = require('url'),
http = require('http'),
+ crypto = require('crypto'),
redis = require('redis'),
- RedisStore = require('connect-redis')(express),
- hashlib = require('hashlib');
+ RedisStore = require('connect-redis')(express);
// Configuration
try {
var configJSON = fs.readFileSync(__dirname + "/config.json");
var config = JSON.parse(configJSON.toString());
} catch(e) {
- sys.puts("File config.json not found or is invalid. Try: `cp config.json.sample config.json`");
+ console.error("File config.json not found or is invalid. Try: `cp config.json.sample config.json`");
process.exit(1);
}
@@ -311,7 +310,7 @@ function processRequest(req, res, next) {
privateReqURL = apiConfig.protocol + '://' + apiConfig.baseURL + apiConfig.privatePath + methodURL + ((paramString.length > 0) ? '?' + paramString : ""),
options = {
headers: {},
- protocol: apiConfig.protocol,
+ protocol: apiConfig.protocol + ':',
host: baseHostUrl,
port: baseHostPort,
method: httpMethod,
@@ -470,21 +469,27 @@ function processRequest(req, res, next) {
// Add API Key to params, if any.
if (apiKey != '' && apiKey != 'undefined' && apiKey != undefined) {
- options.path += '&' + apiConfig.keyParam + '=' + apiKey;
+ if (options.path.indexOf('?') !== -1) {
+ options.path += '&';
+ }
+ else {
+ options.path += '?';
+ }
+ options.path += apiConfig.keyParam + '=' + apiKey;
}
// Perform signature routine, if any.
if (apiConfig.signature) {
if (apiConfig.signature.type == 'signed_md5') {
// Add signature parameter
var timeStamp = Math.round(new Date().getTime()/1000);
- var sig = hashlib.md5('' + apiKey + apiSecret + timeStamp + '', { asString: true });
+ var sig = crypto.createHash('md5').update('' + apiKey + apiSecret + timeStamp + '').digest('base64');
options.path += '&' + apiConfig.signature.sigParam + '=' + sig;
}
else if (apiConfig.signature.type == 'signed_sha256') { // sha256(key+secret+epoch)
// Add signature parameter
var timeStamp = Math.round(new Date().getTime()/1000);
- var sig = hashlib.sha256('' + apiKey + apiSecret + timeStamp + '', { asString: true });
+ var sig = crypto.createHash('sha256').update('' + apiKey + apiSecret + timeStamp + '').digest('base64');
options.path += '&' + apiConfig.signature.sigParam + '=' + sig;
}
}
View
@@ -23,10 +23,8 @@
"dependencies": {
"connect-redis": "1.0.6",
"express": "2.4.3",
- "hashlib": "1.0.1",
"jade": "0.13",
"oauth": "0.9.3",
- "querystring": "0.0.1",
"redis": "0.6.6"
},
"devDependencies": {},

0 comments on commit ef0abc8

Please sign in to comment.