Package: limesurveyrc2api
LimeSurvey RC2 API Web Services ClientIntroductionThis module provides a class which can be used as a client for interacting with LimeSurvey Remote Control 2 API.InstallFrom pip:pipinstalllimesurveyrc2apior from GitHub, for example using the master branch:pipinstallhttps://github.com/lindsay-stevens/limesurveyrc2api/archive/master.zipExample UsageThe tests are a good place to refer to for api usage, until proper docs are written, anyway. Here is how to get a list of surveys.fromlimesurveyrc2api.limesurveyimportLimeSurveyurl="http://localhost:443/limesurvey/index.php/admin/remotecontrol"username="admin"password="admin"# Open a session.api=LimeSurvey(url=url,username=username)api.open(password=password)# Get a list of surveys the admin can see, and print their IDs.result=api.survey.list_surveys()forsurveyinresult:print(survey.get("sid"))# Close the session.api.close()Implemented MethodsIt's just a start, so the list of implemented methods is shorter than not.Sessionsget_session_key (api.open)release_session_key (api.close)Surveylist_surveyslist_questionsTokenadd_participantsdelete_participantsget_participant_propertiesget_summaryinvite_participantslist_participantsError HandlingWhere possible, error messages from the RC2API are translated into Python exceptions (specifically, aLimeSurveyError), with the caller method and error message included in the exception message plus any other relevant info.DevelopmentSetup# Get a copy of the repository.mkdir-P~/repos/limesurveyrc2apicd~/repos/limesurveyrc2api
gitclonehttps://github.com/lindsay-stevens/limesurveyrc2api.gitrepo# Create and activate a virtual environment for the install./usr/local/bin/python3.9-mvenvvenvsourcevenv/bin/activate# Install limesurveyrc2api, and it's development dependencies.cd~/repos/limesurveyrc2api/repo
pipinstall-e.
pipinstall-rdev_requirements.pip# Leave the virtualenv.deactivateReferencesUseful references for the RC2API:Handler scriptServer scriptManual pageGenerated api docDiscovering Error MessagesIf extending or maintaining this project, be aware that discovering error messages to raise an exception from is a relatively tedious process. It involves reading through the handler script, looking for lines like the following.return array('status' => 'No permission');Whether or not the message is an error depends on the context of the line and the message text. For example, some RC2API methods that delete objects return a message that looks like an error but indicate success, e.g. "status": "OK".Running TestsCopy tests/config.ini.tmpl to tests/config.ini and edit it with the details of a RC2API enabled LimeSurvey installation.LimeSurvey instance setup steps:Install LimeSurvey by following the manual instructionsLog in as admin, then go to Configuration -> Global Settings:Enable the RC2API, under: Interfaces -> RPC interface enabled: JSON-RPC -> SaveConfigure the test smtp host, under Email settings:Email method: SMTPSMTP host: localhost:10025SMTP username, password: blankEmail batch size: 50SaveLoad at least 1 survey, by either:Logging in as admin, then Surveys -> Create a new survey, then add groups and questions by handLogging in as admin, then Surveys -> Create a new survey, then import the .LSS file under tests/fixturesOnce the methods are implemented for it, create a survey programmaticallyActivate the survey: Surveys -> SurveyName -> Activate this SurveyInitialise participants table: Survey -> SurveyName -> Survey Participants -> Initialise participants tableFrom the project root folder, run the tests either:For minimal result info:python -m unittestFor more detailed info:python setup.py testTest ProblemsThere is a PHP 5.6.0+ issue where the API response value includes a deprecation warning, which breaks the JSON response parsing. To deal with this, ensure that the followingphp.inisetting is set:always_populate_raw_post_data = -1.Intellij SetupProject setup for IDEA requires defining a "project SDK", under File -> Project Structure -> Project. Since this is a Python project, the SDK is the interpreter you want to use, which could (should) be a virtual environment interpreter.Since the SDK setting is user specific, it'll need to be created the first time you load up this project. This should create an entry under Platform Settings -> Global Libraries; and a file /.idea/misc.xml, containing the name of the global library (SDK) selected for this project.