https://github.com/twistedstack/titanium-drupal-adapter
https://github.com/twistedstack/titanium-drupal-adapter
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/twistedstack/titanium-drupal-adapter
- Owner: twistedstack
- Created: 2023-10-15T09:51:19.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-15T10:42:52.000Z (over 2 years ago)
- Last Synced: 2025-03-17T20:26:24.983Z (about 1 year ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
PLEASE NOTE: This module has been replaced by a more general Javascript Drupal client:
https://github.com/jbeuckm/drupal-client
[](http://github.com/badges/stability-badges)
# Requirements
1. An installation of Drupal 7.x
2. Services Module 3.4+ (implements the CSRF token for updated REST security)
3. REST Server module enabled
4. A Titanium project - probably works with most versions since this only uses Ti.Network.HTTPClient
# Usage
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.
### Get a session
```javascript
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 :(');
}
);
```
### Create an account
```javascript
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
);
```
### Login
```javascript
var my_username = "";
var my_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.');
}
);
```
### Modify User Info
This updates an account profile on the server. `userObject` is a user object that may have been received from a login request (see above).
```javascript
drupal.putResource("user/"+userObject.uid, userObject,
function(userData) {
Ti.API.info('user has been updated.');
},
function(err){
Ti.API.error('user update failed.');
}
);
```
### Make Requests
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.