Use Moodle Web services with Apache Thrift
The purpose of this project is to provide the tools required to use Moodle Web services with Apache Thrift. This package contains the following applications:
- Thrift file generator (thriftgenerator), used to generate .thrift files that match the Moodle Web services API.
- Wrapper generator (wrappergenerator), used to generate PHP implementations of Thrift generated interfaces that redirect the calls to Moodle Web service handlers.
- Documentation generator (docgenerator), used to generate Web service documentation in HTML format from Moodle source code.
Below is described how to use these applications to set up Moodle with Apache Thrift:
- Make sure your environment is capable of running Moodle and Apache Thrift (please refer to the websites of these projects for details).
- Download and unpack Moodle 2.3.2+ sources: http://download.moodle.org/
Steps to set up Moodle
- Preparations: create directory "thrift" inside moodle/local and copy directory "Thrift" from thrift/lib/php/lib to that directory (or make symbolic link). Create directory "packages" inside moodle/local/thrift (you'll have "Thrift" and "packages" directories under moodle/local/thrift).
- Edit config.php (in this package) to specify the directories where moodle source is unpacked and where to put/find the generated .thrift and .php files.
- Generate .thrift files for Moodle API using thriftgenerator (go to thriftgenerator directory and run
php -f generate.php).
- Generate thrift handlers for PHP, e.g.:
for i in *.thrift; do thrift --gen php:server $i; doneand copy the packages from gen-php to moodle/local/thrift/packages
- Generate API wrappers using wrappergenerator (go to wrappergenerator directory and run
php -f generate.php) and place the .php files in moodle/local/thrift.
- That is all, Moodle part is ready.
Using the API on client side
- Generate client classes for any language as required from the .thrift files e.g.:
for i in *.thrift; do thrift --gen js:jquery $i; done
- Include the generated files to your client application.
- Setup client class to use JSON protocol with the following URL:
var helloClient = new local_wstemplateClient(new Thrift.Protocol(new Thrift.Transport("http://localhost/mmoodle/local/thrift/local_wstemplate.php?token=" + token)))
- Client class is ready to use. E.g.:
Optionally, you can generate the API documentation in HTML format, with
type names used by Thrift. To do this, go to docgenerator directory and run
php -f generate.php - the documentation will be in the output directory,
under doc subdirectory.