= REST Interface = Resources are accessible via [wiki:S3/S3REST/URLFormat RESTful URIs] to allow the creation of Mash-ups: JSON uploads should be PUT to http://server.domain/eden/module/resource.json NB JSON must not include trailing commas in lists (just like Internet Explorer). [This is a SimpleJSON limitation] == Testing == === RESTclient === * http://code.google.com/p/rest-client/ Use pre-emptive authentication, when you need to login. === AJAX === Authenticate using: {{{ function make_base_auth(user, password) { var tok = user + ':' + pass; var hash = Base64.encode(tok); return 'Basic ' + hash; } var auth = make_basic_auth('username@example.com', 'password'); var url = 'http://host.domain/eden/controller/function?vars'; // RAW request = new XMLHttpRequest(); request.setRequestHeader('Authorization', auth); request.open('PUT', url, true); // async=true request.send(bodyContent); // ExtJS Ext.Ajax.request({ url : url, method : 'GET', headers : { Authorization : auth } }); // jQuery $.ajax({ url : url, method : 'GET', beforeSend : function(req) { req.setRequestHeader('Authorization', auth); } }); }}} Thanks to: * http://coderseye.com/2007/how-to-do-http-basic-auth-in-ajax.html === CURL === For testing/PUT using CURL follow the example In the example - name%40example.com represents your login name@example.com and password is to be replaced by your password. person.xml is the file name to PUT {{{ curl -H 'content-type:application/xml' -T person.xml http://name%40example.com:password@localhost:8000/sahana/pr/person.xml&ignore_errors=False }}} === WGET === Use the  --auth-no-challenge option in order to login to Eden. == !WordPress integration == Courtesy of timClicks. This example is for !HumanityRoad's !WordPress to pull in Hospitals data from Sahana Eden: {{{

%s

%s
%s

 

Phone
%s
Website:
%s
Email:
%s

Location

Latitude
%s
Longitude
%s
Comments:
%s
Modified by: %s | Last Modified %s | Global Identifier: %s
HOSPITAL_TABLE_ROWS; $head = << HEAD; function process_comments($comment_string){ $a = explode("\r\n", $comment_string); foreach($a as &$para){ $para = $para.'
'; }; return '

'.implode($a).'

'; }; // untested function check_and_set($item, $assoc_array) { if (array_key_exists($item, $assoc_array)) { $val = $assoc_array[$item]; } else { $val = ' '; }; return $val; }; function process_hospital_info($hospital) { global $hospital_table_format; $city = check_and_set('city', $hospital); $website = check_and_set('website', $hospital); $name = check_and_set('name', $hospital); $address = check_and_set('address', $hospital); $phone = check_and_set('phone', $hospital); $email = check_and_set('email', $hospital); $lat = check_and_set('@lat', $hospital['$k_location_id']); $lon = check_and_set('@lon', $hospital['$k_location_id']); $comments = check_and_set('comments', $hospital); $modified_by = check_and_set('@modified_by', $hospital); $last_modified = check_and_set('@modified_on', $hospital); $uuid = check_and_set('@uuid', $hospital); return sprintf($hospital_table_format, $website, $name, $address, $city, $phone, $website, $email, $lat, $lon, $comments, $modified_by, $last_modified, $uuid); }; echo $head; echo '

yo!

'; $hospital_json = file_get_contents($hospital_source_file); if ($hospital_json === False) { $download_error = True; } else { $hospitals = json_decode($hospital_json, True); }; foreach ($hospitals['$_hms_hospital'] as &$hospital) { $hospital_table[] = process_hospital_info($hospital); } print ''; print implode($hospital_table); print '
'; echo ''; ?> }}} ---- UserGuidelines