source: trunk/tools/ws.htm @ 19820

Last change on this file since 19820 was 18957, checked in by rvelices, 12 years ago

remove unused files + web service explorer uses same jquery version as the core

  • Property svn:eol-style set to LF
File size: 19.2 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2   "http://www.w3.org/TR/html4/strict.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" lang="en" dir="ltr">
4<head>
5  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6  <title>Piwigo web API (web-services) explorer</title>
7 
8  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
9 
10  <style type="text/css">
11  /* BEGIN CSS RESET
12    http://meyerweb.com/eric/tools/css/reset
13    v2.0 | 20110126 | License: none (public domain) */
14  html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code,
15  del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li,
16  fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, 
17  figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video
18  {margin:0;padding:0;border:0;font-size:100%;vertical-align:baseline;}
19
20  article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {display:block;}
21  body {line-height:1.1;}
22  blockquote, q {quotes:none;}
23  blockquote:before, blockquote:after, q:before, q:after {content:'';content:none;}
24  table {border-collapse:collapse;border-spacing:0;}
25  /* END CSS RESET */
26
27  html {font-family:"Corbel","Lucida Grande","Verdana",sans-serif;color:#222;font-size:13px;}
28
29  a {color:#247EBF;text-decoration:none;}
30  a:hover {color:#EB9C39;border-bottom-width:1px;border-style:dotted;
31    text-shadow:1px 1px 0 #ddd;-moz-text-shadow:1px 1px 0 #ddd;-webkit-text-shadow:1px 1px 0 #ddd;
32  }
33  blockquote {border:1px solid #cdcdcd;background:#F9F9F9;padding:8px;}
34  hr {margin:10px 30px;color:#fff;}
35  ul {margin-left:25px;}
36  p {margin:8px 0;}
37
38  h1 {color:#fff;font-size:26px;padding:10px 15px;
39    text-shadow:1px 1px 0 #999;-moz-text-shadow:1px 1px 0 #999;-webkit-text-shadow:1px 1px 0 #999;
40    background:#45484d;background:-moz-linear-gradient(top, #45484d 0%, #333333 100%);background:-webkit-gradient(linear, left top, left bottom, color-stop(0%,#45484d), color-stop(100%,#333333));background:-webkit-linear-gradient(top, #45484d 0%,#333333 100%);background:-o-linear-gradient(top, #45484d 0%,#333333 100%);background:-ms-linear-gradient(top, #45484d 0%,#333333 100%);background:linear-gradient(to bottom, #45484d 0%,#333333 100%);filter:progid:DXImageTransform.Microsoft.gradient( startColorstr='#45484d', endColorstr='#333333',GradientType=0 );
41  }
42  h2 {color:#fff;font-size:20px;padding:5px 10px;
43    text-shadow:1px 1px 0 #555;-moz-text-shadow:1px 1px 0 #555;-webkit-text-shadow:1px 1px 0 #555;
44    background:#f2a841;background:-moz-linear-gradient(top, #f2a841 0%, #ef6b13 100%);background:-webkit-gradient(linear, left top, left bottom, color-stop(0%,#f2a841), color-stop(100%,#ef6b13));background:-webkit-linear-gradient(top, #f2a841 0%,#ef6b13 100%);background:-o-linear-gradient(top, #f2a841 0%,#ef6b13 100%);background:-ms-linear-gradient(top, #f2a841 0%,#ef6b13 100%);background:linear-gradient(to bottom, #f2a841 0%,#ef6b13 100%);filter:progid:DXImageTransform.Microsoft.gradient( startColorstr='#f2a841', endColorstr='#ef6b13',GradientType=0 );
45  }
46  h2#errorWrapper {color:#F42C00;font-weight:normal;
47    background:#eaeaea;background:-moz-linear-gradient(top, #eaeaea 0%, #afafaf 100%);background:-webkit-gradient(linear, lefttop, leftbottom, color-stop(0%,#eaeaea), color-stop(100%,#afafaf));background:-webkit-linear-gradient(top, #eaeaea 0%, #afafaf 100%);background:-o-linear-gradient(top, #eaeaea 0%, #afafaf 100%);background:-ms-linear-gradient(top, #eaeaea 0%, #afafaf 100%);background:linear-gradient(tobottom, #eaeaea 0%, #afafaf 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#eaeaea', endColorstr='#afafaf', GradientType=0);
48  }
49  h3 {display:inline-block;padding:5px 10px;color:#555;font-weight:bold;text-align:center;
50    border-radius:8px 8px 0 0;-moz-border-radius:8px 8px 0 0;-webkit-border-radius:8px 8px 0 0;
51    text-shadow:1px 1px 0 #bbb;-moz-text-shadow:1px 1px 0 #bbb;-webkit-text-shadow:1px 1px 0 #bbb;
52    background:#f2f2f2;background:-moz-linear-gradient(top, #f2f2f2 0%, #cecece 100%);background:-webkit-gradient(linear, left top, left bottom, color-stop(0%,#f2f2f2), color-stop(100%,#cecece));background:-webkit-linear-gradient(top, #f2f2f2 0%,#cecece 100%);background:-o-linear-gradient(top, #f2f2f2 0%,#cecece 100%);background:-ms-linear-gradient(top, #f2f2f2 0%,#cecece 100%);background:linear-gradient(to bottom, #f2f2f2 0%,#cecece 100%);filter:progid:DXImageTransform.Microsoft.gradient( startColorstr='#f2f2f2', endColorstr='#cecece',GradientType=0 );
53  }
54
55  #the_header {border-bottom:1px solid #cdcdcd;margin-bottom:1px;}
56  #the_footer {background:#EAEAEA;border-top:1px solid #cdcdcd;padding:10px;clear:both;}
57
58  #the_methods {width:250px;float:left;border-style:solid;border-color:#cdcdcd;border-width:1px 1px 0 0;
59    background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAADCAIAAADZSiLoAAAAH0lEQVQImSXHMQEAMAwCMOrfK0jIjuVL2gLBzyHJtgd7wBdU3Vt/7AAAAABJRU5ErkJggg==);
60  }
61  #the_methods ul {font-size:1.1em;margin:5px 0 10px 10px;list-style:none;}
62  #the_methods li:before {content:"\203A\00A0";font-weight:bold;color:#EB9C39;font-size:1.1em;}
63  #the_methods li:hover:before {content:"\00A0\203A";}
64
65  #the_page {margin-left:252px;border-style:solid;border-color:#cdcdcd;border-width:1px 0 0 1px;}
66  #the_content {padding:10px;}
67
68  #methodParams {display:inline-block;}
69  #methodParams thead td {background:#DEE3E9;font-weight:bold;padding:2px 5px;}
70  #methodParams td {padding:2px;border:1px solid #cdcdcd;vertical-align:middle;}
71  #methodParams tbody tr:nth-child(even) {background:#f7f7f7;}
72  #methodParams tbody tr td:first-child {font-family:monospace;font-size:0.95em;}
73  #methodParams td.mini {width:0px;text-align:center;}
74  #methodParams tfoot {font-size:0.95em;}
75  #methodParams td.input {text-align:center;}
76  #methodParams td.input input[type="text"] {width:97%;font-size:0.9em;background:#f7f7f7;border:1px solid #ccc;
77    border-radius:2px;-moz-border-radius:2px;-webkit-border-radius:2px;
78  }
79  #methodParams td.input input[type="text"]:hover, #methodParams td.input input[type="text"]:focus {border-color:#C7E2F1;border-top-color:#96BCD7;background:#fff;}
80
81  #testForm {display:inline-block;margin-left:15px;}
82  #testForm td {padding:2px 0;}
83  #testForm tr:last-child td {padding:8px 0 5px 0;}
84  #testForm blockquote {width:200px;}
85 
86  #introMessage {font-size:1.1em;}
87  #urlForm {margin-bottom:10px;}
88
89  a.button {color:#fff;padding:3px 8px;border:1px solid #91bb5c;font-size:0.9em;margin-right:3px;display:inline-block;
90    border-radius:5px;-moz-border-radius:5px;-webkit-border-radius:5px;
91    text-shadow:1px 1px 0 #666;-moz-text-shadow:1px 1px 0 #666;-webkit-text-shadow:1px 1px 0 #666;
92    background:#84bb3c;background:-moz-linear-gradient(top, #84bb3c 0%, #3f5a1d 100%);background:-webkit-gradient(linear, lefttop, leftbottom, color-stop(0%,#84bb3c), color-stop(100%,#3f5a1d));background:-webkit-linear-gradient(top, #84bb3c 0%, #3f5a1d 100%);background:-o-linear-gradient(top, #84bb3c 0%, #3f5a1d 100%);background:-ms-linear-gradient(top, #84bb3c 0%, #3f5a1d 100%);background:linear-gradient(tobottom, #84bb3c 0%, #3f5a1d 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#84bb3c', endColorstr='#3f5a1d', GradientType=0);
93  }
94  a.button:hover {color:#E5FF00;}
95 
96  #iframeWrapper {width:100%;height:300px;padding:3px 3px 20px 3px;background:#F9F9F9;border:1px solid #cdcdcd;overflow:hidden;position:relative;}
97  iframe {width:100%;height:100%;background:#fff;}
98  </style>
99 
100</head>
101
102<body>
103
104<div id="the_header">
105  <h1>Piwigo web API (web-services) explorer</h1>
106</div> <!-- the_header -->
107
108<div id="the_methods">
109  <h2>Available methods</h2>
110 
111  <ul id="methodsList">
112  </ul>
113</div> <!-- the_methods -->
114
115<div id="the_page">
116  <h2 id="methodName" style="display:none;"></h2>
117  <h2 id="errorWrapper" style="display:none;"></h2>
118 
119  <div id="the_content">
120    <form id="urlForm" style="display:none;">
121      <input type="text" name="ws_url" size="60">
122      <input type="submit" value="Go!">
123    </form>
124   
125    <blockquote id="introMessage">
126      <p>
127        <b>API = Application Programming Interface.</b><br>
128        This is the way other applications can communicate with Piwigo. This feature is also know as Web Services.
129      </p>
130
131      <p>Examples:</p>
132      <ul>
133        <li>Wordpress (web blog software) can display random photos from a Piwigo gallery in its sidebar</li>
134        <li>Lightroom (photo management software for desktop) can create albums and upload photos to Piwigo</li>
135      </ul>
136
137      <p>
138        This page lists all API methods available on your Piwigo installation, part of the Piwigo core or added by third-party plugins.
139        For each method you can consult required and optional parameters, and even test them in direct live!
140      </p>
141
142      <p>
143        For more information you can consult our Wiki <a href="http://piwigo.org/doc/doku.php?id=dev:webapi:start" target="_blank">Piwigo Web API</a> and <a href="http://piwigo.org/forum" target="_blank">our forums</a>.
144      </p>
145    </blockquote> <!-- introMessage -->
146
147
148    <form id="methodWrapper" style="display:none;">
149      <div id="methodDescription" style="display:none;">
150        <h3>Description</h3>
151        <blockquote>
152        </blockquote>
153        <br>
154      </div> <!-- methodDescription -->
155     
156      <div id="methodParams">
157        <h3>Method parameters</h3>
158        <table>
159          <thead>
160            <tr>
161              <td style="width:150px;">Name</td>
162              <td class="mini">Extra</td>
163              <td style="width:300px;">Value</td>
164              <td class="mini">Send</td>
165            </tr>
166          </thead>
167         
168          <tbody>
169          </tbody>
170         
171          <tfoot>
172            <tr>
173              <td colspan="4"><b>*</b>: required parameter, <b>?</b>: optional parameter, <b>[]</b>: parameter can be an array (use a pipe | to split values)</td>
174            </tr>
175          </tfoot>
176        </table>
177      </div> <!-- methodParams -->
178     
179      <div id="testForm">
180        <h3>Test</h3>
181        <blockquote>
182          <table>
183            <tr>
184              <td>Request format :</td>
185              <td>
186                <select id="requestFormat">
187                  <option value="get" selected="selected">GET</option>
188                  <option value="post">POST</option>
189                </select>
190              </td>
191            </tr>
192            <tr>
193              <td>Response format :</td>
194              <td>
195                <select id="responseFormat">
196                  <option value="rest" selected="selected">REST (xml)</option>
197                  <option value="json">JSON</option>
198                  <option value="php">PHP serial</option>
199                  <option value="xmlrpc">XML RPC</option>
200                </select>
201              </td>
202            </tr>
203            <tr>
204              <td colspan="2">
205                <a href="#" class="button" id="invokeMethod">INVOKE</a>
206                <a href="#" class="button" id="invokeMethodBlank">INVOKE (new window)</a>
207              </td>
208            </tr>
209          </table>
210        </blockquote>
211      </div> <!-- testForm -->
212     
213      <br><br>
214     
215      <h3>Result</h3>
216      <div id="iframeWrapper">
217        <iframe src="" id="invokeFrame" name="invokeFrame"></iframe>
218        <a href="#bottom" id="increaseIframe"><b>&darr;</b> increase height</a> &#8226; <a href="#bottom" id="decreaseIframe"><b>&uarr;</b> decrease height</a>
219        <a name="bottom"></a>
220      </div>
221    </form> <!-- iframeWrapper -->
222   
223    <!-- hidden form for POST submition -->
224    <form method="post" action="" target="" id="invokeForm" style="display:none;"></form>
225   
226  </div> <!-- the_content -->
227
228</div> <!-- the_page -->
229
230<div id="the_footer">
231  Copyright © 2002-2012 <a href="http://piwigo.org">Piwigo Team</a>
232</div> <!-- the_footer -->
233
234
235<script type="text/javascript"> 
236// global vars
237var cachedMethods = new Array;
238var ws_url = "http://";
239
240// automatic detection of ws_url
241match = document.location.toString().match(/^(https?.*\/)tools\/ws\.html?/);
242if (match==null) {
243  askForUrl();
244}
245else {
246  ws_url = match[1]+'ws.php';
247  getMethodList();
248}
249
250// manual set of ws_url
251$("#urlForm").submit(function() {
252  ws_url = $(this).children("input[name='ws_url']").val();
253  getMethodList();
254  return false;
255});
256
257// invoke buttons
258$("#invokeMethod").click(function() {
259  invokeMethod($("#methodName").html(), false);
260  return false;
261});
262$("#invokeMethodBlank").click(function() {
263  invokeMethod($("#methodName").html(), true);
264  return false;
265});
266
267// resizable iframe
268$("#increaseIframe").click(function() {
269  $("#iframeWrapper").css('height', $("#iframeWrapper").height()+100);
270  adaptHeight();
271});
272$("#decreaseIframe").click(function() {
273  if ($("#iframeWrapper").height() > 200) {
274    $("#iframeWrapper").css('height', $("#iframeWrapper").height()-100);
275    adaptHeight();
276  }
277});
278
279// mask all wrappers
280function resetDisplay() {
281  $("#errorWrapper").hide();
282  $("#methodWrapper").hide();
283  $("#methodName").hide();
284  $("#urlForm").hide();
285  $("#methodDescription").hide();
286  $("#invokeFrame").attr('src','');
287}
288
289// give the same size to methods list and main page
290function adaptHeight()
291{
292  $("#the_page").css('height', 'auto');
293  $("#the_methods").css('height', 'auto');
294 
295  min_h = $(window).height()-$("#the_header").outerHeight()-$("#the_footer").outerHeight()-3;
296  h = Math.max(min_h, Math.max($("#the_methods").height(), $("#the_page").height()));
297 
298  $("#the_page").css('height', h);
299  $("#the_methods").css('height', h);
300}
301
302// display error wrapper
303function displayError(error) {
304  resetDisplay();
305  $("#errorWrapper").html("<b>Error:</b> "+ error).show();
306  adaptHeight();
307}
308
309// display ws_url form
310function askForUrl() {
311  if ($("#urlForm input[name='ws_url']").val() == "") {
312    $("#urlForm input[name='ws_url']").val(ws_url);
313  }
314  $("#urlForm").show();
315  displayError("can't contact web-services, please give absolute url to 'ws.php'");
316}
317
318// parse Piwigo JSON
319function parsePwgJSON(json) {
320  try {
321    resp = jQuery.parseJSON(json);
322    if (resp==null | resp.result==null | resp.stat==null | resp.stat!='ok') {
323      throw new Error();
324    }
325  }
326  catch(e) {
327    displayError("unable to parse JSON string");
328    resp = {"stat": "ko", "result": "null"};
329  }
330 
331  return resp.result;
332}
333
334// fetch methods list
335function getMethodList() {
336  resetDisplay();
337 
338  $.ajax({
339    type: "GET",
340    url: ws_url,
341    data: { format: "json", method: "reflection.getMethodList" }
342  }).done(function(result) {
343    result = parsePwgJSON(result);
344   
345    if (result!=null) {
346      methods = result.methods;
347     
348      var ml = '';
349      for (var i=0; i<methods.length; i++)
350      {
351        ml += '<li><a href="#">'+ methods[i]+'</a></li>';
352      }
353      $("#methodsList").html(ml).show();
354     
355      adaptHeight();
356     
357      // trigger method selection
358      $("#methodsList li a").click(function() {
359        selectMethod($(this).html());
360        return false;
361      });
362    }
363  }).error(function(jqXHR, textStatus, errorThrown) {
364    askForUrl();
365  });
366}
367
368// select method
369function selectMethod(methodName) {
370  $("#introMessage").hide();
371 
372  if (cachedMethods[ methodName ]) {
373    fillNewMethod(methodName);
374  }
375  else {
376    $.ajax({
377      type: "GET",
378      url: ws_url,
379      data: { format: "json", method: "reflection.getMethodDetails", methodName: methodName }
380    }).done(function(result) { 
381      result = parsePwgJSON(result);
382   
383      if (result!=null) {
384        cachedMethods[ methodName ] = result;
385        fillNewMethod(methodName);
386      }
387    }).error(function(jqXHR, textStatus, errorThrown) {
388      displayError("unknown error");
389    });
390  }
391}
392
393// display method details
394function fillNewMethod(methodName) {
395  resetDisplay();
396 
397  method = cachedMethods[ methodName ];
398 
399  $("#methodName").html(method.name).show();
400 
401  if (method.description != "") {
402    $("#methodDescription blockquote").html(method.description);
403    $("#methodDescription").show();
404  }
405 
406  var methodParams = '';
407  if (method.params && method.params.length>0) {
408    for (var i=0; i<method.params.length; i++) {
409      var isOptional = method.params[i].optional;
410      var acceptArray = method.params[i].acceptArray;
411      var defaultValue = method.params[i].defaultValue == null ? '' : method.params[i].defaultValue;
412     
413      // if an array is direclty printed, the delimiter is a comma where we use a pipe
414      if (typeof defaultValue == 'object') {
415        defaultValue = defaultValue.join('|');
416      }
417
418      methodParams+= '<tr>'+
419        '<td>'+ method.params[i].name +'</td>'+
420        '<td class="mini">'+ (isOptional ? '?':'*') + (acceptArray ? ' []':'') +'</td>'+
421        '<td class="input"><input type="text" class="methodParameterValue" data-id="'+ i +'" value="'+ defaultValue +'"></td>'+
422        '<td class="mini"><input type="checkbox" class="methodParameterSend" data-id="'+ i +'" '+ (isOptional ? '':'checked="checked"') +'></td>'+
423      '</tr>';
424    }
425        }
426  else {
427    methodParams = '<tr><td colspan="4">This method takes no parameters</td></tr>';
428  }
429 
430  $("#methodParams tbody").html(methodParams);
431  $("#methodWrapper").show(); 
432 
433  adaptHeight();
434 
435  // trigger field modification
436  $("input.methodParameterValue").change(function() {
437    $("input.methodParameterSend[data-id='"+ $(this).data('id') +"']").attr('checked', 'checked');
438  });
439}
440
441// invoke method
442function invokeMethod(methodName, newWindow) {
443        var method = cachedMethods[ methodName ];
444
445  var reqUrl = ws_url +"?format="+ $("#responseFormat").val();
446 
447  // GET
448  if ($("#requestFormat").val() == 'get') {
449    reqUrl+= "&method="+ methodName;
450   
451    for (var i=0; i<method.params.length; i++) {
452      if (! $("input.methodParameterSend[data-id='"+ i +"']").is(":checked")) {
453        continue;
454      }
455
456      var paramValue = $("input.methodParameterValue[data-id='"+ i +"']").val();
457     
458      var paramSplitted = paramValue.split('|');
459      if (method.params[i].acceptArray &&  paramSplitted.length > 1) {
460        $.each(paramSplitted, function(v) {
461          reqUrl+= '&'+ method.params[i].name +'[]='+ paramSplitted[v];
462        });
463      }
464      else {
465        reqUrl+= '&'+ method.params[i].name +'='+ paramValue;
466      }
467    }
468   
469    if (newWindow) {
470      window.open(reqUrl);
471    }
472    else {
473      $("#invokeFrame").attr('src', reqUrl);
474    }
475  }
476  // POST
477  else {
478    var form = $("#invokeForm");
479    form.attr('action', reqUrl);
480   
481    var t = '<input type="hidden" name="method" value="'+ methodName +'">';
482   
483    for (var i=0; i<method.params.length; i++) {
484      if (! $("input.methodParameterSend[data-id='"+ i +"']").is(":checked")) {
485        continue;
486      }
487
488      var paramValue = $("input.methodParameterValue[data-id='"+ i +"']").val();
489
490      var paramSplitted = paramValue.split('|');
491      if (method.params[i].acceptArray &&  paramSplitted.length > 1) {
492        $.each(paramSplitted, function(v) {
493          t+= '<input type="hidden" name="'+ method.params[i].name +'[]" value="'+ paramSplitted[v] +'">';
494        });
495      }
496      else {
497        t+= '<input type="hidden" name="'+ method.params[i].name +'" value="'+ paramValue +'">';
498      }
499    }
500   
501    form.html(t);
502    form.attr('target', newWindow ? "_blank" : "invokeFrame");
503    form.submit();
504  }
505 
506  return false;
507}
508</script>
509
510</body>
511</html>
Note: See TracBrowser for help on using the repository browser.