示例#1
0
def load_discussions(request_client: RequestClient, section_id: str,
                     discussions: List[Dict]) -> List[Dict]:
    """
    Load a list of discussions via the Schoology API.

    Parameters
    ----------
    request_client : RequestClient
        A RequestClient initialized for access to the Schoology API
    section_id: str
        The Schoology id of the section that the discussions are associated with
    discussions: List[Dict]
        A list of JSON-like discussion objects in a form suitable for submission
        to the Schoology discussion create endpoint.

    Returns
    -------
    List[Dict]
        A list of JSON-like discussion objects incorporating the response values from the
        Schoology API, e.g. resource ids and status from individual POSTing
    """
    logger.info("Creating %s discussions via Schoology API", len(discussions))

    post_responses: List[Dict] = []
    for discussion in discussions:
        response: Dict = request_client.post(
            f"sections/{section_id}/discussions", discussion)
        post_responses.append(response)

    logger.info("Successfully created %s discussions", len(post_responses))
    return post_responses
示例#2
0
def load_assignments(request_client: RequestClient, section_id: str,
                     assignments: List[Dict]) -> List[Dict]:
    """
    Load a list of assignments via the Schoology API.

    Parameters
    ----------
    request_client : RequestClient
        A RequestClient initialized for access to the Schoology API
    section_id: str
        The Schoology id of the section that the assignments are associated with
    assignments: List[Dict]
        A list of JSON-like assignment objects in a form suitable for submission to the
        Schoology assignment creation endpoint.

    Returns
    -------
    List[Dict]
        A list of JSON-like assignment objects incorporating the response values from the
        Schoology API, e.g. resource ids and status from individual POSTing
    """
    assert (len(assignments) > 0 and len(assignments) < 51
            ), "Number of assignments must be between 1 and 50"

    logger.info("Creating %s assignments via Schoology API", len(assignments))

    post_responses: List[Dict] = []
    for assignment in assignments:
        response: Dict = request_client.post(
            f"sections/{section_id}/assignments", assignment)
        post_responses.append(response)

    logger.info("Successfully created %s assignments", len(post_responses))
    return post_responses