Skip to content

Commit

Permalink
Removed debug logs and fixed oauth signature
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdremstrup committed Jul 6, 2015
1 parent f776ad6 commit e87b6bc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 58 deletions.
5 changes: 2 additions & 3 deletions lib/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ function getNonce(len) {
// Utility: URL encoding is slightly complex in the OAuth spec
function uriEncode(s) {
var s= encodeURIComponent(s);
return s.replace(/\!/g, "%21")
s = s.replace(/\!/g, "%21")
.replace(/\'/g, "%27")
.replace(/\(/g, "%28")
.replace(/\)/g, "%29")
.replace(/\*/g, "%2A");
return s;
}

// Utility: Mix content of one object into another (1:1 dublicate from restler.js; can be eliminated)
Expand Down Expand Up @@ -79,7 +80,6 @@ exports.signature = function(url, options){

// 3. Create a base string for signatures
var signatureBaseString = [options.method.toUpperCase(), uriEncode(normalizedURL), uriEncode(normalizedParams)].join('&');
//console.log(signatureBaseString);

// 4. And actually sign the string
var signatureSecret = [uriEncode(options.oauthConsumerSecret||''), uriEncode(options.oauthAccessTokenSecret||'')].join('&');
Expand All @@ -100,7 +100,6 @@ exports.signature = function(url, options){
normalizedHeaderParts.push(['oauth_signature="', hash, '"'].join(''));
normalizedHeader = 'OAuth ' + normalizedHeaderParts.join(', ');

console.log(normalizedHeader);
// 6. Finally return our header
return(normalizedHeader);
}
80 changes: 25 additions & 55 deletions lib/visualplatform.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ as their second and third parameters.

var OAuthAuthentication = require('./authentication');
var Promise = require("promise");
var oauth = require('./oauth');
var url = require('url');
var querystring = require('querystring');


module.exports = Visualplatform = function(domain, key, secret, callback_url){
Expand All @@ -48,65 +51,32 @@ module.exports = Visualplatform = function(domain, key, secret, callback_url){
data['raw'] = '1';
access_token = access_token||'';
access_secret = access_secret||'';

// Set up the request with callbacks
rest.post('http://'+$.serviceDomain+method, {
oauthConsumerKey: $.consumer_key,
oauthConsumerSecret: $.consumer_secret,
oauthAccessToken: access_token,
oauthAccessTokenSecret: access_secret,
data:data
}).on('success', function(res) {
res = JSON.parse(res);
if(!res.status == 'ok') return reject(res.message);
else return fulfill(res);
}).on('error', function(err) {
err = JSON.parse(err);
return reject(err.message);
}).on('timeout', function(ms) {
return reject('Timeout: ' + ms);
});

rest.post('https://'+$.serviceDomain+method, {
data:data,
headers: {
Authorization: oauth.signature(url.parse('https://'+$.serviceDomain+':443'+method+'?'+querystring.stringify(data)), {
oauthConsumerKey: $.consumer_key,
oauthConsumerSecret: $.consumer_secret,
oauthAccessToken: access_token,
oauthAccessTokenSecret: access_secret,
method: 'POST'
})
}
}).on('success', function(res) {
res = JSON.parse(res);
if(!res.status == 'ok') return reject(res.message);
else return fulfill(res);
}).on('error', function(err) {
err = JSON.parse(err);
return reject(err.message);
}).on('timeout', function(ms) {
return reject('Timeout: ' + ms);
});
});
}

$.concatenate = function(methods, access_token, access_secret){
return new Promise(function(fulfill, reject) {
methods = methods||[];
data = data||{};
data['format'] = 'json';
data['raw'] = '1';
access_token = access_token||'';
access_secret = access_secret||'';
var objectNames = [];
var objectCallbacks = {};
var i = 0;
$.each(methods, function(i,o){
var name = o.name||o.method.split('/').slice(2).join('') + '_' + (i++);
objectNames.push(name);
objectCallbacks[name] = o.callback || function(){};
data[name] = o.method + (o.data ? ('?'+$.param(o.data)) : '');
});

// Set up the request with callbacks
rest.post('http://'+$.serviceDomain+'/api/concatenate', {
oauthConsumerKey: $.consumer_key,
oauthConsumerSecret: $.consumer_secret,
oauthAccessToken: access_token,
oauthAccessTokenSecret: access_secret,
data:data
}).on('success', function(res) {
res = JSON.parse(res);
if(!res.status == 'ok') return reject(res.message);
else return fulfill(res);
}).on('error', function(err) {
err = JSON.parse(err);
return reject(err.message);
}).on('timeout', function(ms) {
return reject('Timeout: ' + ms);
});
});
}

// Map entire Visualplatform API
var methods = ['/api/analytics/report/event', '/api/analytics/report/play', '/api/analytics/extract/play-details', '/api/analytics/extract/play-totals', '/api/album/create', '/api/album/delete', '/api/album/list', '/api/album/update', '/api/comment/add', '/api/comment/delete', '/api/comment/list', '/api/photo/coordinate/add', '/api/photo/coordinate/delete', '/api/distribution/ios/push-notification', '/api/distribution/ios/register-device', '/api/distribution/ios/unregister-device', '/api/license/list', '/api/live/create', '/api/live/delete', '/api/live/list', '/api/live/update', '/api/live/upload-image', '/api/live/start-recording', '/api/live/stop-recording', '/api/photo/delete', '/api/photo/frame', '/api/photo/get-upload-token', '/api/photo/list', '/api/photo/rate', '/api/photo/redeem-upload-token', '/api/photo/replace', '/api/photo/update', '/api/photo/update-upload-token', '/api/photo/upload', '/api/player/list', '/api/player/settings', '/api/photo/section/create', '/api/photo/section/delete', '/api/photo/section/list', '/api/photo/section/set-thumbnail', '/api/photo/section/update', '/api/session/get-token', '/api/session/redeem-token', '/api/site/get', '/api/photo/subtitle/list', '/api/tag/list', '/api/tag/related', '/api/echo', '/api/user/create', '/api/user/get-login-token', '/api/user/list', '/api/user/redeem-login-token'];

Expand Down

0 comments on commit e87b6bc

Please sign in to comment.