Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #11 from peri18/NODEJS-1103-GENERIC-METHOD-ACS

Nodejs 1103 providing a generic method for ACS rest api calls NODEJS-1133 Removing global variable to store session_id
  • Loading branch information...
commit dba329b85b17a531f5e3ec8b00e46745ed923209 2 parents e8aab23 + f35db9f
@baobeimm baobeimm authored
Showing with 635 additions and 145 deletions.
  1. +42 −41 README.md
  2. +1 −0  examples/UserWithACSAPI/README.md
  3. +14 −0 examples/UserWithACSAPI/app.js
  4. +13 −0 examples/UserWithACSAPI/config.json
  5. +15 −0 examples/UserWithACSAPI/controllers/application.js
  6. +96 −0 examples/UserWithACSAPI/controllers/user.js
  7. 0  examples/UserWithACSAPI/logs/users.log
  8. +24 −0 examples/UserWithACSAPI/package.json
  9. +102 −0 examples/UserWithACSAPI/public/css/style.css
  10. BIN  examples/UserWithACSAPI/public/images/favicon.ico
  11. +15 −0 examples/UserWithACSAPI/views/index.ejs
  12. +11 −0 examples/UserWithACSAPI/views/login.ejs
  13. +14 −0 examples/UserWithACSAPI/views/signup.ejs
  14. +10 −0 examples/UserWithACSAPI/views/update.ejs
  15. +1 −0  examples/UserWithREST/README.md
  16. +14 −0 examples/UserWithREST/app.js
  17. +13 −0 examples/UserWithREST/config.json
  18. +15 −0 examples/UserWithREST/controllers/application.js
  19. +116 −0 examples/UserWithREST/controllers/user.js
  20. 0  examples/UserWithREST/logs/users.log
  21. +24 −0 examples/UserWithREST/package.json
  22. +19 −0 examples/UserWithREST/public/css/style.css
  23. BIN  examples/UserWithREST/public/images/favicon.ico
  24. +15 −0 examples/UserWithREST/views/index.ejs
  25. +11 −0 examples/UserWithREST/views/login.ejs
  26. +14 −0 examples/UserWithREST/views/signup.ejs
  27. +10 −0 examples/UserWithREST/views/update.ejs
  28. +26 −4 lib/acs.js
  29. +0 −6 lib/util/utils.js
  30. +0 −43 test/object.js
  31. +0 −7 test/places.js
  32. +0 −44 test/users.js
View
83 README.md
@@ -11,50 +11,51 @@ Usage
Example 1, do ACS user login:
-- var ACS = require('acs-node');
-- function login(req, res) {
-- var un = req.body.username;
-- var pw = req.body.password;
-- ACS.Users.login({login: un, password: pw}, function(data) {
-- if(data.success) {
-- var user = data.users[0];
-- if(user.first_name && user.last_name) {
-- user.name = user.first_name + ' ' + user.last_name;
-- } else {
-- user.name = user.username;
-- }
-- req.session.user = user;
-- res.redirect('/');
-- } else {
-- res.render('login', {message: data.message});
-- }
-- });
-- }
+~~~
+var ACS = require('acs-node');
+ACS.initACS('<App Key>');
+function login(req, res) {
+ var data = {
+ login: req.body.username,
+ password: req.body.password
+ };
+ ACS.Users.login(data, function(data){
+ if(data.success) {
+ console.log("Successful to login.");
+ console.log("UserInfo: " + JSON.stringify(data.users[0], null, 2))
+ } else {
+ console.log("Error to login: " + data.message);
+ }
+ }, req, res);
+}
+~~~
Example 2, a generic method show how to operate an ACS user:
-- var ACS = require('acs-node');
-- var sdk = ACS.initACS('', '');
-- var user_id = null;
-- var useSecure = true;
-- sdk.sendRequest('users/create.json', 'POST', {
-- username:'test1',
-- password:'test1',
-- password_confirmation:'test1',
-- first_name: 'test_firstname',
-- last_name: 'test_lastname'
-- }, function(data){
-- user_id = data.response.users[0].id;
-- sdk.sendRequest('users/logout.json', 'DELETE',null, function(data){
-- sdk.sendRequest('users/login.json', 'POST', {login:'test1', password:'test1'}, function(data){
-- sdk.sendRequest('users/update.json', 'PUT', {first_name: 'firstname'}, function(data){
-- }, useSecure);
-- }, useSecure);
-- }, useSecure);
-- }, useSecure);
-
-
-More examples, please look up in the folder test.
+~~~
+var ACS = require('acs-node');
+var sdk = ACS.initACS('<App Key>');
+function login(req, res) {
+ var data = {
+ login: req.body.username,
+ password: req.body.password
+ };
+ sdk.rest('users/login.json', 'POST', data, function(data){
+ if(data && data.meta) {
+ if(data.meta.status == 'ok') {
+ console.log("Successful to login.");
+ console.log("UserInfo: " + JSON.stringify(data.response.users[0], null, 2))
+ } else {
+ console.log("Error to login: " + data.meta.message);
+ }
+ } else {
+ console.log("Error to login, try again later.");
+ }
+ }, req, res);
+}
+~~~
+
+More examples, please look up in the folder examples with the command 'acs run'.
Legal
View
1  examples/UserWithACSAPI/README.md
@@ -0,0 +1 @@
+This sample Node.ACS MVC based project uses node-sdk building user api to communicate with ACS.
View
14 examples/UserWithACSAPI/app.js
@@ -0,0 +1,14 @@
+// initialize app
+function start(app, express) {
+ //use connect.session
+ app.use(express.cookieParser());
+ app.use(express.session({ key: 'node.acs', secret: "my secret" }));
+
+ //set favicon
+ app.use(express.favicon(__dirname + '/public/images/favicon.ico'));
+}
+
+// release resources
+function stop() {
+
+}
View
13 examples/UserWithACSAPI/config.json
@@ -0,0 +1,13 @@
+{
+ "routes":
+ [
+ { "path": "/", "callback": "application#index" },
+ { "path": "/login", "method": "get", "callback": "application#login" },
+ { "path": "/login", "method": "post", "callback": "user#login" },
+ { "path": "/update", "method": "get", "callback": "application#update" },
+ { "path": "/update", "method": "post", "callback": "user#update" },
+ { "path": "/logout", "method": "get", "callback": "user#logout" },
+ { "path": "/signup", "method": "get", "callback": "application#signup" },
+ { "path": "/signup", "method": "post", "callback": "user#signup" }
+ ]
+}
View
15 examples/UserWithACSAPI/controllers/application.js
@@ -0,0 +1,15 @@
+function index(req, res) {
+ res.render('index', {user: req.session.user});
+}
+
+function login(req, res) {
+ res.render('login');
+}
+
+function update(req, res) {
+ res.render('update');
+}
+
+function signup(req, res) {
+ res.render('signup');
+}
View
96 examples/UserWithACSAPI/controllers/user.js
@@ -0,0 +1,96 @@
+var ACS = require('acs').ACS;
+var logger = require('acs').logger;
+var sdk = ACS.initACS('<App Key>');
+
+//create a new user
+function signup(req, res) {
+ var data = {
+ first_name: req.body.first_name,
+ last_name: req.body.last_name,
+ email: req.body.email,
+ password: req.body.password,
+ password_confirmation: req.body.password_confirmation
+ };
+
+ ACS.Users.create(data, function(data) {
+ logger.debug("######Create######");
+ logger.debug(JSON.stringify(data, null, 2));
+ if(data.success) {
+ var user = data.users[0];
+ if(user.first_name && user.last_name) {
+ user.name = user.first_name + ' ' + user.last_name;
+ } else {
+ user.name = user.username;
+ }
+ logger.info('Created user: ' + user.name);
+ req.session.user = user;
+ res.redirect('/');
+ } else {
+ logger.info("Create user error: " + data.meta.message);
+ res.render('signup', {message: data.message});
+ }
+ }, req, res);
+}
+
+//do ACS user login
+function login(req, res) {
+ var data = {
+ login: req.body.username,
+ password: req.body.password
+ };
+ ACS.Users.login(data, function(data){
+ logger.debug("######login######");
+ logger.debug(JSON.stringify(data, null, 2));
+ if(data.success) {
+ var user = data.users[0];
+ if(user.first_name && user.last_name) {
+ user.name = user.first_name + ' ' + user.last_name;
+ } else {
+ user.name = user.username;
+ }
+ req.session.user = user;
+ res.redirect('/');
+ } else {
+ logger.info("Login error: " + data.meta.message);
+ res.render('login', {message: data.meta.message});
+ }
+ }, req, res);
+}
+
+function update(req, res) {
+ var data = {
+ first_name: req.body.first_name,
+ last_name: req.body.last_name,
+ };
+ ACS.Users.update(data, function(data) {
+ logger.debug("######update######");
+ logger.debug(JSON.stringify(data, null, 2));
+ if(data.success) {
+ var user = data.users[0];
+ if(user.first_name && user.last_name) {
+ user.name = user.first_name + ' ' + user.last_name;
+ } else {
+ user.name = user.username;
+ }
+ req.session.user = user;
+ res.redirect('/');
+ } else {
+ logger.info("Update user error: " + data.meta.message);
+ res.render('update', {message: data.meta.message});
+ }
+ }, req, res);
+}
+
+function logout(req, res) {
+ ACS.Users.logout(function(data) {
+ logger.debug("######logout######");
+ logger.debug(JSON.stringify(data, null, 2));
+ if(data.success) {
+ delete req.session.user;
+ res.redirect('/');
+ } else {
+ logger.info("Logout error: " + data.meta.message);
+ res.render('/', {message: data.meta.message});
+ }
+ }, req, res);
+}
View
0  examples/UserWithACSAPI/logs/users.log
No changes.
View
24 examples/UserWithACSAPI/package.json
@@ -0,0 +1,24 @@
+{
+ "name": "UserWithACSAPI",
+ "version": "0.1.0",
+ "description": "",
+ "framework": "mvc",
+ "main": "app.js",
+ "logfile" : "users.log",
+ "keywords": [
+ ],
+ "author": "",
+ "maintainers": [
+ ],
+ "contributors": [
+ ],
+ "repository": {
+ "type": "git",
+ "url": ""
+ },
+ "preferGlobal": false,
+ "dependencies": {
+ },
+ "license":"",
+ "private": true
+}
View
102 examples/UserWithACSAPI/public/css/style.css
@@ -0,0 +1,102 @@
+* {
+ font:400 14px/20px "helvetica neue", arial, sans-serif;
+}
+
+.clr{clear:both;}
+
+#ic {
+ width:100%;
+ border:1px solid #ccc;
+ border-bottom:0;
+}
+#ic span{
+ display:block;
+ padding:5px 10px;
+}
+
+#ctnr{
+ padding:10px;
+}
+
+#chat-ctnr {
+ width:100%;
+ height:70%;
+ overflow:auto;
+ border:1px solid #ccc;
+}
+
+#incomingChatMessages {
+ padding:5px;
+ margin:0;
+ list-style:none;
+}
+
+#incomingChatMessages li{
+ position:relative;
+ width:100%;
+}
+
+#incomingChatMessages li .icmb{
+ padding:2px;
+}
+
+#incomingChatMessages li .cu{
+ float:left;
+ width:15%;
+ margin:2px 1% 2px 0;
+}
+
+#incomingChatMessages li .cu span{
+ display:block;
+ padding:3px;
+}
+
+#incomingChatMessages li .cm{
+ width:83%;
+ float:left;
+ -webkit-border-radius:3px;
+ -moz-border-radius:3px;
+ border-radius:3px;
+ background:#f5f5f5;
+ margin:2px 0;
+ transition:all .3s;
+ -moz-transition:all .3s;
+ -webkit-transition:all .3s;
+ -o-transition:all .3s;
+}
+#incomingChatMessages li .cm span{
+ display:block;
+ float:left;
+ padding:3px;
+}
+
+#incomingChatMessages li .cm time{
+ float:right;
+ background:#fff;
+ margin:2px 3px 0;
+ font:400 10px/14px "helvetica neue", arial, sans-serif;
+ -webkit-border-radius:3px;
+ -moz-border-radius:3px;
+ border-radius:3px;
+}
+
+#incomingChatMessages li.alert span{
+ font-weight:bold;
+ padding:4px;
+}
+
+#incomingChatMessages li.active {
+ background:#ddffdd;
+}
+
+#outgoingChatMessage {
+ margin:5px 0;
+ padding:5px;
+ outline:none;
+ border:1px solid #ccc;
+ width:100%;
+}
+
+#outgoingChatMessage:focus {
+ border:1px solid #1c94c4;
+}
View
BIN  examples/UserWithACSAPI/public/images/favicon.ico
Binary file not shown
View
15 examples/UserWithACSAPI/views/index.ejs
@@ -0,0 +1,15 @@
+<html>
+<body>
+<% var message;
+ if(message) { %>
+ <%= message %>
+<% } %>
+
+<% if(user) {%>
+ <div>Welcome, <%= user.name %>! <a href="/logout">logout</a></div>
+ <a href="/update">update your info</a>
+<% } else {%>
+ <%- include login %>
+<% } %>
+</body>
+</html>
View
11 examples/UserWithACSAPI/views/login.ejs
@@ -0,0 +1,11 @@
+<% var message;
+ if(message) { %>
+ <%= message %>
+<% } %>
+
+<form action="/login" method="post">
+<div><input name="username" placeholder="user name" title="username" required/></div>
+<div><input name="password" placeholder="password" type="password" title="password" required/></div>
+<div><input type="submit" value="login"/></div>
+</form>
+<div><a href="/signup">signup</div>
View
14 examples/UserWithACSAPI/views/signup.ejs
@@ -0,0 +1,14 @@
+<% var message;
+ if(message) { %>
+ <%= message %>
+<% } %>
+
+<form action="signup" method="post">
+<div><input name="email" placeholder="email" title="email" required/></div>
+<div><input name="first_name" placeholder="first name" title="first name" required/></div>
+<div><input name="last_name" placeholder="last name" title="last name" required/></div>
+<div><input name="password" placeholder="password" type="password" title="password" required/></div>
+<div><input name="password_confirmation" placeholder="password confirmation" type="password" title="password confirmation" required/></div>
+<div><input type="submit" value="signup"/></div>
+</form>
+<div><a href="/login">login</div>
View
10 examples/UserWithACSAPI/views/update.ejs
@@ -0,0 +1,10 @@
+<% var message;
+ if(message) { %>
+ <%= message %>
+<% } %>
+
+<form action="update" method="post">
+<div><input name="first_name" placeholder="first name" title="first name" required/></div>
+<div><input name="last_name" placeholder="last name" title="last name" required/></div>
+<div><input type="submit" value="update"/></div>
+</form>
View
1  examples/UserWithREST/README.md
@@ -0,0 +1 @@
+This sample Node.ACS MVC based project uses node-sdk generic REST methods to communicate with ACS
View
14 examples/UserWithREST/app.js
@@ -0,0 +1,14 @@
+// initialize app
+function start(app, express) {
+ //use connect.session
+ app.use(express.cookieParser());
+ app.use(express.session({ key: 'node.acs', secret: "my secret" }));
+
+ //set favicon
+ app.use(express.favicon(__dirname + '/public/images/favicon.ico'));
+}
+
+// release resources
+function stop() {
+
+}
View
13 examples/UserWithREST/config.json
@@ -0,0 +1,13 @@
+{
+ "routes":
+ [
+ { "path": "/", "callback": "application#index" },
+ { "path": "/login", "method": "get", "callback": "application#login" },
+ { "path": "/login", "method": "post", "callback": "user#login" },
+ { "path": "/update", "method": "get", "callback": "application#update" },
+ { "path": "/update", "method": "post", "callback": "user#update" },
+ { "path": "/logout", "method": "get", "callback": "user#logout" },
+ { "path": "/signup", "method": "get", "callback": "application#signup" },
+ { "path": "/signup", "method": "post", "callback": "user#signup" }
+ ]
+}
View
15 examples/UserWithREST/controllers/application.js
@@ -0,0 +1,15 @@
+function index(req, res) {
+ res.render('index', {user: req.session.user});
+}
+
+function login(req, res) {
+ res.render('login');
+}
+
+function update(req, res) {
+ res.render('update');
+}
+
+function signup(req, res) {
+ res.render('signup');
+}
View
116 examples/UserWithREST/controllers/user.js
@@ -0,0 +1,116 @@
+var ACS = require('acs').ACS;
+var logger = require('acs').logger;
+var sdk = ACS.initACS('<App Key>');
+
+//create a new user
+function signup(req, res) {
+ var data = {
+ first_name: req.body.first_name,
+ last_name: req.body.last_name,
+ email: req.body.email,
+ password: req.body.password,
+ password_confirmation: req.body.password_confirmation
+ };
+
+ sdk.rest('users/create.json', 'POST', data, function(data) {
+ logger.debug("######Create######");
+ logger.debug(JSON.stringify(data, null, 2));
+ if(data && data.meta) {
+ if(data.meta.status == 'ok') {
+ var user = data.response.users[0];
+ if(user.first_name && user.last_name) {
+ user.name = user.first_name + ' ' + user.last_name;
+ } else {
+ user.name = user.username;
+ }
+ logger.info('Created user: ' + user.name);
+ req.session.user = user;
+ res.redirect('/');
+ } else {
+ logger.info("Create user error: " + data.meta.message);
+ res.render('signup', {message: data.meta.message});
+ }
+ } else {
+ logger.error("Create user error, try again later.");
+ res.render('signup', {message: "Create user error, try again later."});
+ }
+ }, req, res);
+}
+
+//do user login with rest
+function login(req, res) {
+ var data = {
+ login: req.body.username,
+ password: req.body.password
+ };
+ sdk.rest('users/login.json', 'POST', data, function(data){
+ logger.debug("######login######");
+ logger.debug(JSON.stringify(data, null, 2));
+ if(data && data.meta) {
+ if(data.meta.status == 'ok') {
+ var user = data.response.users[0];
+ if(user.first_name && user.last_name) {
+ user.name = user.first_name + ' ' + user.last_name;
+ } else {
+ user.name = user.username;
+ }
+ req.session.user = user;
+ res.redirect('/');
+ } else {
+ logger.info("Login error: " + data.meta.message);
+ res.render('login', {message: data.meta.message});
+ }
+ } else {
+ logger.error("Login error, try again later.");
+ res.render('login', {message: "Login error, try again later."});
+ }
+ }, req, res);
+}
+
+function update(req, res) {
+ var data = {
+ first_name: req.body.first_name,
+ last_name: req.body.last_name,
+ };
+ sdk.rest('users/update.json', 'PUT', data, function(data) {
+ logger.debug("######update######");
+ logger.debug(JSON.stringify(data, null, 2));
+ if(data && data.meta) {
+ if(data.meta.status == 'ok') {
+ var user = data.response.users[0];
+ if(user.first_name && user.last_name) {
+ user.name = user.first_name + ' ' + user.last_name;
+ } else {
+ user.name = user.username;
+ }
+ req.session.user = user;
+ res.redirect('/');
+ } else {
+ logger.info("Update user error: " + data.meta.message);
+ res.render('update', {message: data.meta.message});
+ }
+ } else {
+ logger.error("Update user error, try again later.");
+ res.render('update', {message: "Update user error, try again later."});
+ }
+ }, req, res);
+}
+
+function logout(req, res) {
+ sdk.rest('users/logout.json', 'DELETE', null, function(data) {
+ logger.debug("######logout######");
+ logger.debug(JSON.stringify(data, null, 2));
+ if(data && data.meta) {
+ if(data.meta.status == 'ok') {
+ delete req.session.user;
+ res.redirect('/');
+ } else {
+ logger.info("Logout error: " + data.meta.message);
+ res.render('/', {message: data.meta.message});
+ }
+ } else {
+ logger.error("Error to logout, try again later.");
+ res.render('/', {message: "Error to logout, try again later."});
+ }
+ }, req, res);
+}
View
0  examples/UserWithREST/logs/users.log
No changes.
View
24 examples/UserWithREST/package.json
@@ -0,0 +1,24 @@
+{
+ "name": "UserWithREST",
+ "version": "0.1.0",
+ "description": "",
+ "framework": "mvc",
+ "main": "app.js",
+ "logfile" : "users.log",
+ "keywords": [
+ ],
+ "author": "",
+ "maintainers": [
+ ],
+ "contributors": [
+ ],
+ "repository": {
+ "type": "git",
+ "url": ""
+ },
+ "preferGlobal": false,
+ "dependencies": {
+ },
+ "license":"",
+ "private": true
+}
View
19 examples/UserWithREST/public/css/style.css
@@ -0,0 +1,19 @@
+* {
+ font:400 14px/20px "helvetica neue", arial, sans-serif;
+}
+
+.clr{clear:both;}
+
+#ic {
+ width:100%;
+ border:1px solid #ccc;
+ border-bottom:0;
+}
+#ic span{
+ display:block;
+ padding:5px 10px;
+}
+
+#ctnr{
+ padding:10px;
+}
View
BIN  examples/UserWithREST/public/images/favicon.ico
Binary file not shown
View
15 examples/UserWithREST/views/index.ejs
@@ -0,0 +1,15 @@
+<html>
+<body>
+<% var message;
+ if(message) { %>
+ <%= message %>
+<% } %>
+
+<% if(user) {%>
+ <div>Welcome, <%= user.name %>! <a href="/logout">logout</a></div>
+ <a href="/update">update your info</a>
+<% } else {%>
+ <%- include login %>
+<% } %>
+</body>
+</html>
View
11 examples/UserWithREST/views/login.ejs
@@ -0,0 +1,11 @@
+<% var message;
+ if(message) { %>
+ <%= message %>
+<% } %>
+
+<form action="/login" method="post">
+<div><input name="username" placeholder="user name" title="username" required/></div>
+<div><input name="password" placeholder="password" type="password" title="password" required/></div>
+<div><input type="submit" value="login"/></div>
+</form>
+<div><a href="/signup">signup</div>
View
14 examples/UserWithREST/views/signup.ejs
@@ -0,0 +1,14 @@
+<% var message;
+ if(message) { %>
+ <%= message %>
+<% } %>
+
+<form action="signup" method="post">
+<div><input name="email" placeholder="email" title="email" required/></div>
+<div><input name="first_name" placeholder="first name" title="first name" required/></div>
+<div><input name="last_name" placeholder="last name" title="last name" required/></div>
+<div><input name="password" placeholder="password" type="password" title="password" required/></div>
+<div><input name="password_confirmation" placeholder="password confirmation" type="password" title="password confirmation" required/></div>
+<div><input type="submit" value="signup"/></div>
+</form>
+<div><a href="/login">login</div>
View
10 examples/UserWithREST/views/update.ejs
@@ -0,0 +1,10 @@
+<% var message;
+ if(message) { %>
+ <%= message %>
+<% } %>
+
+<form action="update" method="post">
+<div><input name="first_name" placeholder="first name" title="first name" required/></div>
+<div><input name="last_name" placeholder="last name" title="last name" required/></div>
+<div><input type="submit" value="update"/></div>
+</form>
View
30 lib/acs.js
@@ -78,7 +78,7 @@ ACSLIB.prototype.sendRequest = function(url, method, data, callback, useSecure)
var apiMethod = method ? method.toUpperCase() : utils.get_method;
data[utils.suppressCode] = 'true';
- sessionId = this.session_id;
+ var sessionId = data['session_id']; // Get Session from data which user can send it as a parameter in data
if (sessionId) {
if(reqURL.indexOf("?") != -1) {
@@ -180,6 +180,31 @@ ACSLIB.prototype.sendRequest = function(url, method, data, callback, useSecure)
}
};
+// A generic method with the provided data, executing the provided callback when we get a response.
+// This function could use req & res to send and receive the data which is supported by the module
+// of express from server. The session data has been include in res & req,
+// so that could make the option easier.
+ACSLIB.prototype.rest = function(url, method, data, callback, req, res) {
+ if(req && res) {
+ if(req.cookies[COOKIE_NAME]) {
+ if(!data) {
+ data = {};
+ }
+ data['session_id'] = req.cookies[COOKIE_NAME];
+ }
+ }
+ this.sendRequest(url, method, data, function handleResponse(evt) {
+ if (!callback)
+ return;
+ if (evt.meta && evt.meta.status == 'ok') {
+ if(evt.meta.session_id && req && res) {
+ res.cookie(COOKIE_NAME, evt.meta.session_id);
+ }
+ }
+ callback(evt);
+ }, true);
+};
+
function initACS(key, secret, baseUrl) {
apiKey = key;
consumerKey = key;
@@ -705,9 +730,6 @@ function defineCloud(Cloud) {
if(!session)
return;
- //clear last session
- session.session_id = null;
-
if(data) {
if(data['session_id']) {
if(url.indexOf("?") != -1) {
View
6 lib/util/utils.js
@@ -238,12 +238,6 @@ function APIResponseHandler(sdk, callback) {
return callback(buildErrResponse(statusCode, resbody));
}
- if(data && data.meta) {
- if(data.meta.session_id) {
- var sessionId = data.meta.session_id;
- sdk.session_id = sessionId;
- }
- }
callback(data);
}
View
43 test/object.js
@@ -1,43 +0,0 @@
-var acs = require('../lib/acs');
-
-var sdk = acs.initACS('');
-
-var login = {
- "login": "test",
- "password": "test"
- };
-
- var data = {
- "firstName": "Steve",
- "lastname": "Jobs",
- "phone": {
- "work": "123-456-7890",
- "mobile": "098-765-4321",
- "home": "111-222-3333"
- }
- };
-
- console.log("Login");
- sdk.sendRequest('users/login.json', 'POST', login, function(e){
- console.log(e);
- console.log("Sending REST Create");
- sdk.sendRequest('objects/Provider/create.json',
- 'POST',
- {fields: JSON.stringify(data)},
- callback);
- });
-
-
-
- function callback(data) {
- console.log("Entering sendRequest callback");
- console.log(data);
- if (data) {
- if (data.meta) {
- var meta = data.meta;
- if (meta.status == 'ok' && meta.code == 200 && meta.method_name == 'createObject') {
- console.log("Hell Ya!")
- }
- }
- }
- }
View
7 test/places.js
@@ -1,7 +0,0 @@
-var acs = require('../lib/acs');
-
-var sdk = acs.initACS('', '');
-
-sdk.sendRequest('places/query.json', 'GET', {page:1, per_page:2}, function(data){
- console.log(JSON.stringify(data, null, 2));
-}, true);
View
44 test/users.js
@@ -1,44 +0,0 @@
-var acs = require('../lib/acs');
-
-var sdk = acs.initACS('', '');
-
-var user_id = null;
-var filePath = "/Users/bill/2012-07.xls";
-var photoPath = "/Users/bill/photo.JPG";
-var useSecure = true;
-
-sdk.sendRequest('users/create.json', 'POST', {username:'test1', password:'test1', password_confirmation:'test1'}, function(data){
- console.log(JSON.stringify(data, null, 2));
- user_id = data.response.users[0].id;
-
- sdk.sendRequest('files/create.json', 'POST', {name: 'abcd', file: filePath}, function(data){
- console.log(JSON.stringify(data, null, 2));
-
- sdk.sendRequest('users/logout.json', 'DELETE',null, function(data){
- console.log(JSON.stringify(data, null, 2));
-
- sdk.sendRequest('users/login.json', 'POST', {login:'test1', password:'test1'}, function(data){
- console.log(JSON.stringify(data, null, 2));
-
- sdk.sendRequest('photos/create.json', 'POST', {photo: photoPath}, function(data){
- console.log(JSON.stringify(data, null, 2));
-
- sdk.sendRequest('users/update.json', 'PUT', {first_name: 'abcd'}, function(data){
- console.log(JSON.stringify(data, null, 2));
-
- sdk.sendRequest('users/delete.json', 'DELETE', null, function(data){
- console.log(JSON.stringify(data, null, 2));
-
- sdk.sendRequest('users/show.json', 'GET', {'user_id': user_id}, function(data){
- console.log(JSON.stringify(data, null, 2));
-
- }, useSecure);
- }, useSecure);
- }, useSecure);
- }, useSecure);
- }, useSecure);
- }, useSecure);
- }, useSecure);
-}, useSecure);
-
-
Please sign in to comment.
Something went wrong with that request. Please try again.