Last active
August 16, 2019 03:03
-
-
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
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
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]); | |
} | |
}); | |
} |
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
{ | |
"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