Added Web Service Examples

Signed-off-by: Willy Sudiarto Raharjo <willysr@gmail.com>
This commit is contained in:
Willy Sudiarto Raharjo
2013-03-18 21:47:42 +07:00
parent 23f2f79a7a
commit 3cf3b24385
3 changed files with 286 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyBLsOKBo1cgE0ZbXaWHzbOA6JSeGYDdylw&sensor=false">
</script>
<script type="text/javascript">
function initialize() {
var myLatlng = new google.maps.LatLng(-7.78690, 110.37815);
var BethesdaLatlng = new google.maps.LatLng(-7.78346, 110.37844);
var myOptions = {
center: myLatlng,
zoom: 18,
mapTypeId: google.maps.MapTypeId.SATELLITE
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Duta Wacana Christian University!"
});
var marker = new google.maps.Marker({
position: BethesdaLatlng,
map: map,
title:"Bethesda Hospital"
});
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>
+164
View File
@@ -0,0 +1,164 @@
<?php
// Lakukan pemanggilan SOAP apabila ada permintaan berupa form yang disubmit
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$get = 0;
$post = 0;
$delete = 0;
$put = 0;
// Search Quotes
if (isset($_POST['keywordQuote']) && (trim($_POST['keywordQuote']) != ""))
{
$keyword = $_POST['keywordQuote'];
$result = new HttpRequest("http://lecturer.ukdw.ac.id/yuan/labs/quotes/find/$keyword", HttpRequest::METH_GET);
$get = 1;
}
else if (isset($_POST['idQuote']) && (trim($_POST['idQuote']) != ""))
{
$id = $_POST['idQuote'];
$result = new HttpRequest("http://lecturer.ukdw.ac.id/yuan/labs/quotes/id/$id", HttpRequest::METH_GET);
$get = 1;
}
else if (isset($_POST['authorQuote']) && (trim($_POST['authorQuote']) != ""))
{
$author = $_POST['authorQuote'];
$result = new HttpRequest("http://lecturer.ukdw.ac.id/yuan/labs/quotes/author/$author", HttpRequest::METH_GET);
$get = 1;
}
// Add New Quote
else if (isset($_POST['authorQuotePost']) && (trim($_POST['authorQuotePost']) != "") && (trim($_POST['quotePost']) != ""))
{
$newQuote = array("author", "quote");
$newQuote['author'] = $_POST['authorQuotePost'];
$newQuote['quote'] = $_POST['quotePost'];
$result = new HttpRequest("http://lecturer.ukdw.ac.id/yuan/labs/quotes/", HttpRequest::METH_POST);
$result->setPostFields($newQuote);
$post= 1;
}
// Delete
else if (isset($_POST['idQuoteDelete']) && (trim($_POST['idQuoteDelete']) != ""))
{
$id = $_POST['idQuoteDelete'];
$result = new HttpRequest("http://lecturer.ukdw.ac.id/yuan/labs/quotes/$id", HttpRequest::METH_DELETE);
$delete = 1;
}
// Update
else if (isset($_POST['idQuoteChange']) && (trim($_POST['idQuoteChange']) != "") && (trim($_POST['authorQuoteChange']) != "") && (trim($_POST['quoteChange']) != ""))
{
$id = $_POST['idQuoteChange'];
$author = $_POST['authorQuoteChange'];
$quote = $_POST['quoteChange'];
$result = new HttpRequest("http://lecturer.ukdw.ac.id/yuan/labs/quotes/", HttpRequest::METH_PUT);
$result->setPutData($id);
$result->setPutData($author);
$result->setPutData($quote);
$put = 1;
}
if ($get) {
try {
$result->send();
if ($result->getResponseCode() == 200) {
$xml = $result->getResponseBody();
$xmlResult = simplexml_load_string($xml);
foreach($xmlResult->quote as $k=>$v) {
echo "ID : " . $v->id . "<br/>";;
echo "Quote : " . $v->content . "<br/>";
echo "Author : " . $v->author . "<br/>";
echo "<hr/>";
}
}
}
catch (HttpException $ex) {
echo $ex;
}
}
else if ($post){
try {
$result->send();
if ($result->getResponseCode() == 200)
echo "Quote berhasil ditambahkan";
else
echo "Quote gagal ditambahkan";
}
catch (HttpException $ex) {
echo $ex;
}
}
else if ($delete){
try {
$result->send();
if ($result->getResponseCode() == 200)
echo "Quote berhasil dihapus";
else
echo "Quote gagal dihapus";
}
catch (HttpException $ex) {
echo $ex;
}
}
else if ($put){
try {
$result->send();
if ($result->getResponseCode() == 200)
echo "Quote berhasil diupdate";
else
echo "Quote gagal diupdate";
}
catch (HttpException $ex) {
echo $ex;
}
}
}
else // Tidak ada proses submit, berarti tampilkan form
{
?>
<html>
<head>
<title>Contoh Akses Web Service Berbasis RESTful API</title>
</head>
<body>
<h2>Mencari Quote</h2>
<form action="rest.php" method="post">
Masukkan Keyword Quotes
<input id="keywordQuote" name="keywordQuote" size="50" type="text"/>
<input id="submit" name="submit" type="submit" value="submit" />
</form>
<form action="rest.php" method="post">
Masukkan Nomor ID quotes
<input id="idQuote" name="idQuote" size="50" type="text"/>
<input id="submit" name="submit" type="submit" value="submit" />
</form>
<form action="rest.php" method="post">
Masukkan Nama Pembuat quote
<input id="authorQuote" name="authorQuote" size="50" type="text"/>
<input id="submit" name="submit" type="submit" value="submit" />
</form>
<h2>Menambahkan Quote Baru</h2>
<form action="rest.php" method="post" enctype="multipart/form-data">
Masukkan Nama Author <input id="authorQuotePost" name="authorQuotePost" size="50" type="text"/><br/>
Masukkan Quote Anda <input id="quotePost" name="quotePost" size="50" type="text"/>
<input id="submit" name="submit" type="submit" value="submit" />
</form>
<h2>Menghapus Quote</h2>
<form action="rest.php" method="post"">
Masukkan ID Quote <input id="idQuoteDelete" name="idQuoteDelete" size="50" type="text"/>
<input id="submit" name="submit" type="submit" value="submit" />
</form>
<h2>Mengganti Quote</h2>
<form action="rest.php" method="post">
Masukkan ID Quote <input id="idQuoteChange" name="idQuoteChange" size="50" type="text"/><br/>
Masukkan Nama Author Baru <input id="authorQuoteChange" name="authorQuoteChange" size="50" type="text"/><br/>
Masukkan Quote Baru <input id="quoteChange" name="quoteChange" size="50" type="text"/>
<input id="submit" name="submit" type="submit" value="submit" />
</form>
</body>
</html>
<?php
}
?>
+80
View File
@@ -0,0 +1,80 @@
<?php
// Lakukan pemanggilan SOAP apabila ada permintaan berupa form yang disubmit
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$client = new SoapClient("http://library.ukdw.ac.id/ws/index.php?wsdl");
// Mengambil data sesuai dengan form yang dikirimkan
if (isset($_POST['judul']) && (trim($_POST['judul']) != ""))
{
$judul = $_POST['judul'];
$result = $client->getBukuByJudul("$judul", 0);
}
else if (isset($_POST['pengarang']) && (trim($_POST['pengarang']) != ""))
{
$pengarang = $_POST['pengarang'];
$result = $client->getBukuByPengarang("$pengarang", 0);
}
else if (isset($_POST['penerbit']) && (trim($_POST['penerbit']) != ""))
{
$penerbit = $_POST['penerbit'];
$result = $client->getBukuByPenerbit("$penerbit", 0);
}
// Proses array
foreach($result as $k=>$v)
{
print "
<table>
<tr>
<td align='left'>No: " . ($k+1) . "</td>
</tr>
<tr>
<td align='left'>No. Ref: " . $v->norefb . "</td>
</tr>
<tr>
<td align='left'>Call Number: " . $v->callnumb . "</td>
</tr>
<tr>
<td align='left'>Pengarang " . $v->pengarang . "</td>
</tr>
<tr>
<td>Judul: " . $v->judul . "</td>
</tr>
<tr>
<td align='left'>Penerbit: " . $v->penerbit . "</td>
</tr>
<tr><td><hr/></td></tr>
</table>";
}
}
else // Tidak ada proses submit, berarti tampilkan form
{
?>
<html>
<head>
<title>Contoh Akses Web Service Perpustakaan UKDW Menggunakan SOAP</title>
</head>
<body>
<form action="soap.php" method="post">
Masukkan Judul Buku yang hendak Dicari?
<input id="judul" name="judul" size="50" type="text"/>
<input id="submit" name="submit" type="submit" value="submit" />
</form>
<form action="soap.php" method="post">
Masukkan nama pengarang buku hendak Dicari?
<input id="pengarang" name="pengarang" size="50" type="text"/>
<input id="submit" name="submit" type="submit" value="submit" />
</form>
<form action="soap.php" method="post">
Masukkan nama penerbit buku hendak Dicari?
<input id="pengarang" name="penerbit" size="50" type="text"/>
<input id="submit" name="submit" type="submit" value="submit" />
</form>
</body>
</html>
<?php
}
?>