Skip to content

Instantly share code, notes, and snippets.

@lbrenman
Last active August 16, 2019 03:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lbrenman/3785eafc5d27e9d02e485490f4177437 to your computer and use it in GitHub Desktop.
Save lbrenman/3785eafc5d27e9d02e485490f4177437 to your computer and use it in GitHub Desktop.
Node.js example of accessing Axway/Appcelerator MBaaS (ArrowDB/ACS) - user and photo API
var fs = require('fs');
var ArrowDBAppKey_Dev = '<ACS DEV APP KEY>';
var ArrowDBAppKey_Prod = '<ACS PROD APP KEY>';
var ArrowDB = require('arrowdb'),
arrowDBApp = new ArrowDB(ArrowDBAppKey_Prod);
var loginParams = {
login: 'a',
password: '1234'
};
arrowDBApp.usersLogin(loginParams, function(err, result) {
if (err) {
console.error("Login error:" + (err.message || result.reason));
} else {
console.log("Login successful!");
console.log("UserInfo: " + JSON.stringify(result.body.response.users[0]));
getPhotos();
}
});
function getPhotos() {
arrowDBApp.photosQuery({
limit: 10
}, function(err, result) {
if (err) {
console.error(err.message);
} else {
storePhoto();
result.body.response.photos.forEach(function (photo) {
console.log(photo);
});
}
});
}
function storePhoto() {
arrowDBApp.photosCreate({
photo: fs.createReadStream('photo.jpg'),
custom_fields: {
age: {
low: 22,
high: 34
},
gender: "female"
}
}, function(err, result) {
if (err) {
console.error(err.message);
} else {
console.log(result.body.response.photos[0]);
}
});
}
{
"name": "nodembaas",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"arrowdb": "^1.0.11"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment