PLEASE NOTE: This module has been replaced by a more general Javascript Drupal client:
https://github.com/jbeuckm/drupal-client
- An installation of Drupal 7.x
- Services Module 3.4+ (implements the CSRF token for updated REST security)
- REST Server module enabled
- A Titanium project - probably works with most versions since this only uses Ti.Network.HTTPClient
Create a Service and enable (at least) the Resources called "system" and "user". Rename config.js.example to config.js and enter the url of your Drupal install and your service endpoint.
var drupal = require('drupal');
drupal.systemConnect(
//success
function(sessionData) {
var uid = sessionData.user.uid;
Ti.API.info('session found for user '+uid);
},
//failure
function(error) {
Ti.API.error('boo :(');
}
);var user = {
name: 'my_new_username',
pass: 'my_new_password',
mail: 'my_email@titaniumdrupal.com'
};
drupal.createAccount(user,
//success
function(userData) {
Ti.API.info('yay!');
},
//failure
function(error) {
Ti.API.error('boo :(');
},
headers //optional
); var my_username = "<DRUPAL USERNAME>";
var my_password = "<DRUPAL PASSWORD>";
var userObject;
drupal.login(my_username, my_password,
function(userData) {
Ti.API.info('User ' + userData.uid + ' has logged in.');
userObject = userData;
},
function(err){
Ti.API.error('login failed.');
}
);This updates an account profile on the server. userObject is a user object that may have been received from a login request (see above).
drupal.putResource("user/"+userObject.uid, userObject,
function(userData) {
Ti.API.info('user has been updated.');
},
function(err){
Ti.API.error('user update failed.');
}
);
The workhorse function of the interface is makeAuthenticatedRequest(config, success, failure, headers). There are a few helper functions included for posting/getting nodes, getting views, uploading files, etc. But they typically all construct a call to makeAuthenticatedRequest. This function should facilitate most things that people want to do with Drupal in a mobile environment. It's also easy to use `makeAuthenticatedRequest' to make requests agaist custom Services.