Advertisement
Guest User

helpers.js

a guest
Jun 19th, 2014
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var MyHelpers = {
  2.     extend: function (out) {
  3.         out = out || {};
  4.  
  5.         for (var i = 1; i < arguments.length; i++) {
  6.             if (!arguments[i]) {
  7.                 continue
  8.             }
  9.  
  10.             for (var key in arguments[i]) {
  11.                 if (arguments[i].hasOwnProperty(key)) {
  12.                     out[key] = arguments[i][key]
  13.                 }
  14.             }
  15.         }
  16.  
  17.         return out
  18.     },
  19.  
  20.     readLocalSetting: function(key) {
  21.         var applicationData = Windows.Storage.ApplicationData.current
  22.           , localSettings   = applicationData.localSettings
  23.  
  24.         return localSettings.values[key]
  25.     },
  26.  
  27.     writeLocalSetting: function(key, value) {
  28.         var applicationData = Windows.Storage.ApplicationData.current
  29.           , localSettings   = applicationData.localSettings
  30.  
  31.         localSettings.values[key] = value
  32.     },
  33.  
  34.     dropbox: {
  35.         KEY: "0k6lggamswvcpeq",
  36.         SECRET: "chani4pw0g54tqk",
  37.  
  38.         getParams: function() {
  39.             return JSON.parse(MyHelpers.readLocalSetting('dropboxParams'))
  40.         },
  41.  
  42.         setParams: function(params) {
  43.             MyHelpers.writeLocalSetting('dropboxParams', JSON.stringify(params))
  44.         },
  45.  
  46.         getClient: function() {
  47.             var options = MyHelpers.extend({
  48.                 key: MyHelpers.dropbox.KEY,
  49.                 secret: MyHelpers.dropbox.SECRET
  50.             }, MyHelpers.dropbox.getParams())
  51.  
  52.             var client = new Dropbox.Client(options)
  53.  
  54.             if (options.access_token) {
  55.                 client._oauth.processRedirectParams(options)
  56.                 client.authStep = Dropbox.Client.DONE
  57.             }
  58.  
  59.             return client
  60.         },
  61.  
  62.         auth: function() {
  63.             var client = this.getClient()
  64.  
  65.             client.authDriver(new Dropbox.AuthDriver.WinRT())
  66.             client.authenticate()
  67.         },
  68.  
  69.         sync: function (callback) {
  70.             if (this.getClient().isAuthenticated()) {
  71.                 this.getClient().getAccountInfo(function (error, accountInfo) {
  72.                     console.log(accountInfo);
  73.                 });
  74.             } else {
  75.                 this.auth()
  76.             }
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement