refactor(github) uploadFile, login, getUserData

This commit is contained in:
coderaiser 2014-03-05 11:18:26 -05:00
parent a0c4ebca0f
commit dabd9f6814

View file

@ -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);