REST インタフェース
マッシュアップアプリケーションを作成できるよう、Sahana Edenの提供するリソースは、RESTURI を通じてアクセスできます。
JSON アップロードはhttp://server.domain/eden/module/resource.jsonに対する PUT で行います(server.domain/eden/ はお使いの Eden のサーバ環境に合わせて読み替えます。)
注意: JSON データを送信する場合、 (Internet Explorerがやるように) リストの末尾にコンマを入れないでください。 [これは SimpleJSON ライブラリの制限によるものです]
テストするには
RESTclientを使う場合
CURL を使う場合
CURL を使ってテストしたり PUT したりするには、以下の例に従ってください。
以下の例では、 name%40example.com をあなたのログインアカウント名、パスワードをあなたのパスワードに読み替えてください。
PUT するファイルの名前を person.xml とします。
curl -H 'content-type:application/xml' -T person.xml http://name%40example.com:password@localhost:8000/sahana/pr/person.xml&ignore_errors=False
WordPress との統合
timClicks より許可を得て転載しています。
この例では HumanityRoad の WordPress 向けに、 Sahan Eden 上の病院データをとり出しています:
<?php
$download_error = False;
$hospital_source_file = 'http://humanityroad.sahanafoundation.org/eden/hms/hospital.json';
$hospital_table_format = <<<HOSPITAL_TABLE_ROWS
<tr class="hospital-info">
<td>
<h4><a href="%s">%s</a></h4>
<p>%s<br />%s</p>
</td>
<td>
<h4> </h4>
<dl class="hospital-d">
<dt>Phone</dt>
<dd>%s</dd>
<dt>Website:</dt>
<dd>%s</dd>
<dt>Email:</dt>
<dd>%s</dd>
</dl>
</td>
<td>
<h4>Location</h4>
<dl class="hospital-d">
<dt>Latitude</dt>
<dd>%s</dd>
</dt>Longitude</dt>
<dd>%s</dd>
</dl>
</td>
</tr>
<tr class="hospital-comments">
<td colspan="3">
<dl class="hospital-d">
<dt>Comments:</dt>
<dd>%s</dd>
</dl>
</td>
</tr>
<tr class="hospital-tech-details">
<td colspan="3">
<span>Modified by:</span>
<span>%s</span> |
<span>Last Modified</span>
<span>%s</span> |
<span>Global Identifier:</span>
<span>%s</span>
</td>
</tr>
<tr>
<td colspan="3"><hr /></td>
</tr>
HOSPITAL_TABLE_ROWS;
$head = <<<HEAD
<!DOCTYPE html><html><head>
<style>
td {
margin: 1em 0;
padding: 0;
}
dt {
position: relative;
left: 0;
top: 1.1em;
width: 5em;
font-weight: bold;
font-family:monospace;
}
dl.hospital-d dd {
border-left: 1px solid #000;
margin: 0 0 0 6em;
padding: 0 0 .5em .5em;
}
.hospital-tech-details {
color:#aaa;
font-size:0.8em;
}
</style>
</head><body>
HEAD;
function process_comments($comment_string){
$a = explode("\r\n", $comment_string);
foreach($a as &$para){
$para = $para.'<br />';
};
return '<p>'.implode($a).'</p>';
};
// 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 '<h3>yo!</h3>';
$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 '<table border="0" style="padding:3px;">';
print implode($hospital_table);
print '</table>';
echo '</body>';
?>
UserGuidelines