Skip to main content

LimeSurvey RC2 API Web Services Client

Project description

LimeSurvey RC2 API Web Services Client

Introduction

This module provides a class which can be used as a client for interacting with LimeSurvey Remote Control 2 API.

Install

From pip:

pip install limesurveyrc2api

or from GitHub, for example using the master branch:

pip install https://github.com/lindsay-stevens/limesurveyrc2api/archive/master.zip

Example Usage

The 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.

from limesurveyrc2api.limesurvey import LimeSurvey

url = "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()
for survey in result:
    print(survey.get("sid"))

# Close the session.
api.close()

Implemented Methods

It's just a start, so the list of implemented methods is shorter than not.

  • Sessions
    • get_session_key (api.open)
    • release_session_key (api.close)
  • Survey
    • list_surveys
    • list_questions
  • Token
    • add_participants
    • delete_participants
    • get_participant_properties
    • get_summary
    • invite_participants
    • list_participants

Error Handling

Where possible, error messages from the RC2API are translated into Python exceptions (specifically, a LimeSurveyError), with the caller method and error message included in the exception message plus any other relevant info.

Development

Setup

# Get a copy of the repository.
mkdir -P ~/repos/limesurveyrc2api
cd ~/repos/limesurveyrc2api
git clone https://github.com/lindsay-stevens/limesurveyrc2api.git repo

# Create and activate a virtual environment for the install.
/usr/local/bin/python3.9 -m venv venv
source venv/bin/activate

# Install limesurveyrc2api, and it's development dependencies.
cd ~/repos/limesurveyrc2api/repo
pip install -e .
pip install -r dev_requirements.pip

# Leave the virtualenv.
deactivate 

References

Useful references for the RC2API:

Discovering Error Messages

If 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 Tests

  • Copy 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 instructions
    • Log in as admin, then go to Configuration -> Global Settings:
      • Enable the RC2API, under: Interfaces -> RPC interface enabled: JSON-RPC -> Save
      • Configure the test smtp host, under Email settings:
        • Email method: SMTP
        • SMTP host: localhost:10025
        • SMTP username, password: blank
        • Email batch size: 50
        • Save
    • Load at least 1 survey, by either:
      • Logging in as admin, then Surveys -> Create a new survey, then add groups and questions by hand
      • Logging in as admin, then Surveys -> Create a new survey, then import the .LSS file under tests/fixtures
      • Once the methods are implemented for it, create a survey programmatically
    • Activate the survey: Surveys -> SurveyName -> Activate this Survey
    • Initialise participants table: Survey -> SurveyName -> Survey Participants -> Initialise participants table
  • From the project root folder, run the tests either:
    • For minimal result info: python -m unittest
    • For more detailed info: python setup.py test

Test Problems

There 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 following php.ini setting is set: always_populate_raw_post_data = -1.

Intellij Setup

Project 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

limesurveyrc2api-2.0.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

limesurveyrc2api-2.0.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file limesurveyrc2api-2.0.0.tar.gz.

File metadata

  • Download URL: limesurveyrc2api-2.0.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for limesurveyrc2api-2.0.0.tar.gz
Algorithm Hash digest
SHA256 076738e836a75be491e088f08d5fce26e896959c4fcfff5d25904618168799e1
MD5 4489fd1a716df780780b6ac0bf4508c4
BLAKE2b-256 ce64101ab026b4d3000ad8a923c113272535b29712d7ef56d9674cc01e1b3fad

See more details on using hashes here.

File details

Details for the file limesurveyrc2api-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for limesurveyrc2api-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cd35a1e4e3b90e3056deeb79d96aba04cfc29c9fdf84c2b165da67fc6ffbc79a
MD5 5a1f0ee47b7d6823a89ac408363ed7ac
BLAKE2b-256 7d735559908d13cb10c26079881c51e65931f21932f47dfc2f8d533444c10397

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page