From dabd9f6814e11f4b85543f63ee6eb549c3249f53 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 5 Mar 2014 11:18:26 -0500 Subject: [PATCH] refactor(github) uploadFile, login, getUserData --- lib/client/storage/_github.js | 73 ++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/lib/client/storage/_github.js b/lib/client/storage/_github.js index 0f1debd8..6f24c0a5 100644 --- a/lib/client/storage/_github.js +++ b/lib/client/storage/_github.js @@ -89,31 +89,32 @@ var CloudCmd, Util, DOM, CloudFunc, Github, cb; }); }; - GitHub.getUserData = function(pCallBack) { - User.show(null, function(pError, pData) { - if (!pError) { - var lName = pData.name; - Util.log('Hello ' + lName + ' :)!'); - } - else + GitHub.getUserData = function(callback) { + User.show(null, function(error, data) { + var name; + + if (!error) { + name = data.name; + Util.log('Hello ' + name + ' :)!'); + } else DOM.Storage.remove('token'); }); - Util.exec(pCallBack); + Util.exec(callback); }; /* PUBLIC FUNCTIONS */ - GitHub.basicLogin = function(pUser, pPasswd) { + GitHub.basicLogin = function(user, passwd) { GH = new Github({ - username: pUser, - password: pPasswd, + username: user, + password: passwd, auth : 'basic' }); }; - GitHub.Login = function(pToken) { + GitHub.Login = function(token) { GH = new Github({ - token : pToken, + token : token, auth : 'oauth' }); @@ -123,39 +124,41 @@ var CloudCmd, Util, DOM, CloudFunc, Github, cb; /** * function creates gist */ - GitHub.uploadFile = function(pParams, pCallBack) { - var lContent = pParams.data, - lName = pParams.name; + GitHub.uploadFile = function(params, callback) { + var gist, files, host, options, + content = params.data, + name = params.name; - if (lContent) { + if (content) { DOM.Images.showLoad(); - if (!lName) - lName = Util.getDate(); - var lGist = GH.getGist(), - lFiles = {}, - lHost = CloudCmd.HOST, - lOptions = { - description: 'Uplouded by Cloud Commander from ' + lHost, - public: true - }; + if (!name) + name = Util.getDate(); - lFiles[lName] ={ - content: lContent + gist = GH.getGist(), + files = {}, + host = CloudCmd.HOST, + options = { + description: 'Uplouded by Cloud Commander from ' + host, + public: true }; - lOptions.files = lFiles; + files[name] ={ + content: content + }; - lGist.create(lOptions, function(pError, pData) { - DOM.Images.hideLoad(); - Util.log(pError || pData); - Util.log(pData && pData.html_url); + options.files = files; + + gist.create(options, function(error, data) { + Util.log(error || data); + Util.log(data && data.html_url); - Util.exec(pCallBack); + Util.exec(callback); + DOM.Images.hideLoad(); }); } - return lContent; + return content; }; init(callback);