]> git.mjollnir.org Git - moodle.git/commitdiff
webservice MDL-20803 added REST POST parameters documentation
authorjerome mouneyrac <jerome@moodle.com>
Mon, 14 Dec 2009 06:01:13 +0000 (06:01 +0000)
committerjerome mouneyrac <jerome@moodle.com>
Mon, 14 Dec 2009 06:01:13 +0000 (06:01 +0000)
lang/en_utf8/webservice.php
webservice/wsdocrenderer.php

index d2c5d31b1e05a474338ad8f96578f6fb789b72fa..317ffcebc2b1293ff4c355438cdc688ec5c78008 100644 (file)
@@ -43,6 +43,7 @@ $string['required'] = 'Required';
 $string['requiredcapability'] = 'Required capability';
 $string['response'] = 'Response';
 $string['restcode'] = 'REST';
+$string['restparam'] = 'REST (POST parameters)';
 $string['restrictedusers'] = 'Authorised users only';
 $string['selectedcapabilitydoesntexit'] = 'The currently set required capability ($a) doesn\'t exist anymore. Please change it and save the changes.';
 $string['selectedcapability'] = 'Selected';
@@ -56,8 +57,7 @@ $string['testclient'] = 'Web service test client';
 $string['validuntil'] = 'Valid until';
 $string['webservices'] = 'Web services';
 $string['wsdocumentation'] = 'Web service documentation';
-$string['wsdocumentationintro'] = 'Following a listing of web service functions available for the username <b>$a</b>.<br/>In order to create a client we advice you to read the <a href=\"http://docs.moodle.org/en/Development:Creating_a_web_service_and_a_web_service_function#Create_your_own_client\">Moodle documentation</a>
-    <br/><br/>For REST parameters convert the XML-RPC structures into POST.';
+$string['wsdocumentationintro'] = 'Following a listing of web service functions available for the username <b>$a</b>.<br/>In order to create a client we advice you to read the <a href=\"http://docs.moodle.org/en/Development:Creating_a_web_service_and_a_web_service_function#Create_your_own_client\">Moodle documentation</a>';
 $string['wsdocumentationlogin'] = 'Enter your web service username and password.';
 $string['wspassword'] = 'Web service password';
 $string['wsusername'] = 'Web service username';
index 399e005dad66a117ca391ff9acea3267dd9c99a2..1f56a68089697ab89bf60bba62386ceed88ff54a 100644 (file)
@@ -189,6 +189,47 @@ EOF;
         return $restresponsehtml;
     }
 
+
+     /**
+     * Create indented REST param description
+     * @param object $paramdescription
+     * @param string $indentation composed by space only
+     * @return string the html to diplay
+     */
+    public function rest_param_description_html($paramdescription, $paramstring) {
+        $brakeline = <<<EOF
+
+
+EOF;
+        if ($paramdescription instanceof external_multiple_structure) {
+            $paramstring = $paramstring.'[0]';
+            $return = $this->rest_param_description_html($paramdescription->content, $paramstring);
+            return $return;
+        } else if ($paramdescription instanceof external_single_structure) {
+            $singlestructuredesc = "";
+            foreach ($paramdescription->keys as $attributname => $attribut) {
+                $paramstring = $paramstring.'['.$attributname.']';
+                $singlestructuredesc .= $this->rest_param_description_html($paramdescription->keys[$attributname], $paramstring);
+            }
+            return $singlestructuredesc;
+        } else {
+            $paramstring = $paramstring.'=';
+            switch($paramdescription->type) {
+                case PARAM_BOOL: // 0 or 1 only for now
+                case PARAM_INT:
+                    $type = 'int';
+                    break;
+                case PARAM_FLOAT;
+                    $type = 'double';
+                    break;
+                default:
+                    $type = 'string';
+            }
+            return $paramstring." ".$type.$brakeline;
+        }
+    }
+
+
     /**
      * This display all the documentation
      * @param array $functions contains all decription objects
@@ -241,6 +282,12 @@ EOF;
                 $documentationhtml .= "<div style=\"border:solid 1px #DEDEDE;background:#DFEEE7;color:#222222;padding:4px;\">";
                 $documentationhtml .= '<b>'.get_string('phpparam', 'webservice').'</b><br/>';
                 $documentationhtml .= $brakeline.'['.$paramname.'] =>'.htmlentities($this->xmlrpc_param_description_html($paramdesc)). $brakeline. $brakeline;
+                $documentationhtml .= "</div><br/>";
+                $documentationhtml .= "</pre>";
+                 $documentationhtml .= "<pre>";
+                $documentationhtml .= "<div style=\"border:solid 1px #DEDEDE;background:#FEEBE5;color:#222222;padding:4px;\">";
+                $documentationhtml .= '<b>'.get_string('restparam', 'webservice').'</b><br/>';
+                $documentationhtml .= $brakeline.htmlentities($this->rest_param_description_html($paramdesc,$paramname)). $brakeline. $brakeline;
                 $documentationhtml .= "</div>";
                 $documentationhtml .= "</pre>";
                 $documentationhtml .= "</span>";