Created
July 20, 2016 21:31
-
-
Save devintyler/9a899fb35bb286e4b89c1e09c3bb0811 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// New Syncano Declaration - note the DataObject Declaration | |
var Syncano = require('syncano'); | |
var Syncano = require("syncano"); // CommonJS | |
var account = Syncano({accountKey: "ACCOUNT_KEY", defaults: {instanceName: "INSTANCE_NAME"}}); | |
var DataObject = account.DataObject; // for managing data | |
var Script = connection.Script; // for running "codeboxes" aka Scripts | |
// NOTE: New JS library returns objects inside response object | |
// this means instead of 'res.objects[i]' you can use just 'res[i]' | |
// LISTING Data Objects from Class | |
var data = { | |
className: "CLASS_name" // can be passed inside 'defaults' above | |
}; | |
// ** OLD ** | |
account.instance('INSTANCE').class('CLASS').dataobject().list().then(...) | |
// ** NEW ** | |
DataObject.please().list(data).then(function(res){console.log("data:", res);}); | |
// UPDATING Data Objects | |
// ** OLD ** | |
account.instance('INSTANCE').class('user_profile').dataobject(userId).update(details, function(err, res) {...} | |
// ** NEW ** | |
var query = { | |
id: userId, | |
className: "user_profile" | |
}; | |
var details = { | |
phone: phone | |
}; | |
DataObject.please().update(query, details).then(function(res) { | |
console.log("data", res) | |
}); | |
// FILTERING Data Objects | |
var data2 = { | |
className: "CLASS_name" // can be passed inside 'defaults' above | |
}; | |
var filter = { | |
"query": {"subscribed":{"_eq":true}} | |
}; | |
// ** OLD ** | |
account.instance('INSTANCE').class('user_profile').dataobject().list(filter, function(err, res) {...}) | |
// ** NEW ** | |
DataObject.please().list(data2).filter(filter).then(function(res2){...}); | |
// CODEBOX Change | |
// ** OLD ** | |
account.instance('INSTANCE').codebox(2).run(payload, function(err, res) { | |
console.log('Just sent that SMS out.'); | |
}); | |
// ** NEW ** | |
var query = { | |
id: 2 | |
} | |
var payload = {"payload":{'body': messageToSend, 'to_number': user.phone}}; | |
Script.please().run(query, payload).then(function(result) { | |
console.log("result", result); | |
}); | |
// USERS adding etc. | |
// ** OLD ** | |
instance.user().add({"username": username, "password": password}) | |
// ** NEW ** | |
var userConnection = Syncano({apiKey: API_KEY_WITH_ALLOW_USER_CREATE_FLAG}); | |
var User = userConnection.User; | |
var options = { | |
username: USERNAME, | |
password: PASSWORD, | |
}; | |
User.please().create(options).then(callback); | |
// TO BE CONTINUED |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment