Skip to content

Instantly share code, notes, and snippets.

@brunofarache
Last active August 29, 2015 13:57
Show Gist options
  • Save brunofarache/9723712 to your computer and use it in GitHub Desktop.
Save brunofarache/9723712 to your computer and use it in GitHub Desktop.
var Liferay = require('liferay');
// Session
var session = new Liferay.Session('http://localhost:8080', 'test@liferay.com', 'test'),
service = new Liferay.Calendar(session);
service.deleteCalendar(1, function (err, data) {
console.log(err, data);
});
// Batch
var session = new Liferay.BatchSession('http://localhost:8080', 'test@liferay.com', 'test'),
service = new Liferay.Calendar(session);
service.deleteCalendar(1);
service.deleteCalendar(2);
service.deleteCalendar(3);
session.invoke(function (err, array) {
console.log(err, array);
});
// Separate error from success callbacks
session.invoke(function (array) {
console.log(array);
}, function (err) {
console.error(err);
});
// Response as params instead of array
session.invoke(function (err, data1, data2, data3) {
console.log(arguments);
});
// Batch === Session
var session = new Liferay.Session('http://localhost:8080', 'test@liferay.com', 'test'),
service = new Liferay.Calendar();
session.invoke(service.deleteCalendar(1), function (err, array) {
console.log(err, array);
});
var commands = [service.deleteCalendar(1), service.deleteCalendar(2), service.deleteCalendar(3)];
session.invoke(commands, function (err, array) {
console.log(err, array);
});
// Static
var liferay = require('liferay');
var session = liferay.auth('http://localhost:8080', 'test@liferay.com', 'test');
var service = session.calendar();
session.invoke(service.deleteCalendar(1), function (err, array) {
console.log(err, array);
});
// Passing object instead of params
service.deleteCalendar({
calendarId: 1
}, function (err, data) {
console.log(err, data);
});
// Works on both 6.1 and 6.2
session.invoke([{
"/calendar/delete-calendar": {
calendarId: 1
}
}], function (err, data) {
console.log(err, data);
});
// Promises
service
.deleteCalendar(1)
.deleteCalendar(2)
.done(function (array) {
console.log(array);
})
.fail(function (err) {
console.error(err);
});
// Separate services by modules
var calendar = require('./v62/calendar.js');
var user = require('./v62/user.js');
// Example of generated module
'use strict';
function CalendarService(session) {
this.session = session;
}
CalendarService.prototype.deleteCalendar = function (calendarId, type) {
return {
"/calendar/delete-calendar": {
"calendarId": calendarId,
"type": type
}
}
};
exports.CalendarService = CalendarService;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment