mitodl / pylti

PyLTI implementation
BSD 2-Clause "Simplified" License
58 stars 44 forks source link

Other request types other than posting a grade #44

Open velochy opened 9 years ago

velochy commented 9 years ago

The standard (http://www.imsglobal.org/LTI/v1p1p1/ltiIMGv1p1p1.html#_Toc330273035) specifies a few other types of interaction besides just posting the grade. 6.1.2 "readResult" for getting the grade from the LTI Consumer, for instance.

generating the message can be done with generate_request_xml setting operation to "readResult" but posting it with post_message will just yield "success" but not the actual grade

Currently, this can be worked around by calling the internal _post_patched_request directly but I feel this is more than somewhat hackish.

Would be happy to implement a fix to this if you explain how you want it in terms of architecture. My proposal would be to have post_message return either False when request fails but the response xml when it is successful, but there are quite a few other ways this issue could be approached.

velochy commented 9 years ago

For reference, a working readResult function using _post_patched_request:

xml = generate_request_xml(message_id, 'readResult', sourced_id, None)

(_, content) = _post_patched_request(
    PYLTI_CONFIG["consumers"],
    key,
    xml,
    session['lis_outcome_service_url'],
    'POST',
    'application/xml',
)
is_success = "<imsx_codeMajor>success</imsx_codeMajor>" in content

if not is_success:
    return None

from xml.etree import ElementTree
xml_tree = ElementTree.XML(content)

ns = {'ns0':'http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0'}
rscore = float(xml_tree.findtext('ns0:imsx_POXBody/ns0:readResultResponse/'+
               'ns0:result/ns0:resultScore/ns0:textString',None,ns))

return rscore