diff --git a/lib/client/storage/_skydrive.js b/lib/client/storage/_skydrive.js new file mode 100644 index 00000000..5d8f1871 --- /dev/null +++ b/lib/client/storage/_skydrive.js @@ -0,0 +1,78 @@ +//http://isdk.dev.live.com/ISDK.aspx?category=scenarioGroup_skyDrive&index=0 +var CloudCommander, Util, DOM, WL; + +(function(CloudCmd, Util, DOM){ + 'use strict'; + + var SkyDrive = {}; + + /* PRIVATE FUNCTIONS */ + + /** + * load google api library + */ + function load(pCallBack){ + console.time('SkyDrive'); + var lUrl = '//js.live.net/v5.0/wl.js'; + + DOM.jsload(lUrl, function(){ + console.timeEnd('SkyDrive load'); + DOM.Images.hideLoad(); + + Util.exec(pCallBack); + }); + + } + + function auth(pCallBack){ + CloudCmd.getModules(function(pModules){ + var lStorage = Util.findObjByNameInArr(pModules, 'storage'), + lSkyDrive = Util.findObjByNameInArr(lStorage, 'SkyDrive'), + lSkyDriveKey = lSkyDrive && lSkyDrive.id; + + WL.init({ + client_id: lSkyDriveKey, + redirect_uri: CloudCmd.HOST, + }); + + WL.login({ + scope: ["wl.skydrive wl.signin"] + }).then( + function(response) { + Util.log(response); + }, + function(response) { + Util.log("Failed to authenticate."); + }); + + WL.Event.subscribe("auth.login", onLogin); + }); + } + + + function onLogin(session) { + var strGreeting = ""; + WL.api({ + path: "me", + method: "GET" + }, + + function (response) { + if (!response.error) { + strGreeting = "Hi, " + response.first_name + "!"; + Util.log(strGreeting); + } + }); + } + + SkyDrive.init = function(pCallBack){ + Util.loadOnLoad([ + Util.retExec(pCallBack), + auth, + load + ]); + }; + + CloudCmd.SkyDrive = SkyDrive; + +})(CloudCommander, Util, DOM);