Example #1
0
def authenticate_user(
    redvox_config: RedVoxConfig,
    authentication_request: AuthReq,
    session: Optional[requests.Session] = None,
    timeout: Optional[float] = None,
) -> AuthResp:
    """
    Attempts to authenticate a RedVox user.
    :param redvox_config: Api configuration.
    :param authentication_request: An instance of an authentication request.
    :param session: An (optional) session for re-using an HTTP client.
    :param timeout: An (optional) timeout.
    :return: An instance of an authentication response.
    """
    # noinspection Mypy
    # pylint: disable=E1101
    handle_resp: Callable[
        [requests.Response], AuthResp
    ] = lambda resp: AuthResp.from_dict(resp.json())
    res: Optional[AuthResp] = post_req(
        redvox_config,
        RoutesV1.AUTH_USER,
        authentication_request,
        handle_resp,
        session,
        timeout,
    )

    return res if res else AuthResp(401, None, None)
Example #2
0
def request_station_stats(
    redvox_config: RedVoxConfig,
    station_stat_req: StationStatReq,
    session: Optional[requests.Session] = None,
    timeout: Optional[float] = None,
) -> Optional[StationStatsResp]:
    """
    Requests timing statistics with the given parameters.
    :param redvox_config: The cloud configuration.
    :param station_stat_req: The request.
    :param session: The optional session.
    :param timeout: The optional timeout.
    :return: A StationStatsResp.
    """
    # noinspection Mypy
    handle_resp: Callable[
        [requests.Response], StationStatResp
    ] = lambda resp: StationStatResp.from_dict(resp.json()).into_station_stats_resp()
    return post_req(
        redvox_config,
        RoutesV1.STATION_STATS,
        station_stat_req,
        handle_resp,
        session,
        timeout,
    )
Example #3
0
def validate_token(
    redvox_config: RedVoxConfig,
    validate_token_req: ValidateTokenReq,
    session: Optional[requests.Session] = None,
    timeout: Optional[float] = None,
) -> Optional[ValidateTokenResp]:
    """
    Attempt to validate the provided auth token.
    :param redvox_config: The Api config.
    :param validate_token_req: A validation token req.
    :param session: An (optional) session for re-using an HTTP client.
    :param timeout: An (optional) timeout.
    :return: A ValidateTokenResp when the token is valid, None otherwise.
    """
    # noinspection Mypy
    # pylint: disable=E1101
    handle_resp: Callable[
        [requests.Response], ValidateTokenResp
    ] = lambda resp: ValidateTokenResp.from_dict(resp.json())
    return post_req(
        redvox_config,
        RoutesV1.VALIDATE_TOKEN,
        validate_token_req,
        handle_resp,
        session,
        timeout,
    )
Example #4
0
def refresh_token(
    redvox_config: RedVoxConfig,
    refresh_token_req: RefreshTokenReq,
    session: Optional[requests.Session] = None,
    timeout: Optional[float] = None,
) -> Optional[RefreshTokenResp]:
    """
    Attempt to refresh the given authentication token.
    :param redvox_config: The Api config.
    :param refresh_token_req: The request.
    :param session: An (optional) session for re-using an HTTP client.
    :param timeout: An (optional) timeout.
    :return: An instance of a RefreshTokenResp.
    """
    # noinspection Mypy
    # pylint: disable=E1101
    handle_resp: Callable[
        [requests.Response], RefreshTokenResp
    ] = lambda resp: RefreshTokenResp.from_dict(resp.json())
    return post_req(
        redvox_config,
        RoutesV1.REFRESH_TOKEN,
        refresh_token_req,
        handle_resp,
        session,
        timeout,
    )
Example #5
0
def request_report_data(
    redvox_config: RedVoxConfig,
    report_data_req: ReportDataReq,
    session: Optional[requests.Session] = None,
    timeout: Optional[float] = None,
) -> Optional[ReportDataResp]:
    """
    Makes an API call to generate a signed URL of a RedVox report.
    :param redvox_config: An API config.
    :param report_data_req: The request.
    :param session: An (optional) session for re-using an HTTP client.
    :param timeout: An (optional) timeout.
    :return: The response.
    """
    # noinspection Mypy
    # pylint: disable=E1101
    handle_resp: Callable[
        [requests.Response],
        ReportDataResp] = lambda resp: ReportDataResp.from_dict(resp.json())
    return post_req(
        redvox_config,
        RoutesV1.DATA_REPORT_REQ,
        report_data_req,
        handle_resp,
        session,
        timeout,
    )
Example #6
0
def request_metadata_m(
    redvox_config: RedVoxConfig,
    packet_metadata_req: MetadataReq,
    session: Optional[requests.Session] = None,
    timeout: Optional[float] = None,
) -> Optional[MetadataRespM]:
    """
    Requests generic metadata from the cloud API.
    :param redvox_config: An instance of the API config.
    :param packet_metadata_req: An instance of a metadata request.
    :param session: An (optional) session for re-using an HTTP client.
    :param timeout: An (optional) timeout.
    :return: A metadata response on successful call or None if there is an error.
    """
    # noinspection Mypy
    handle_resp: Callable[
        [requests.Response], MetadataRespM
    ] = lambda resp: MetadataRespM.from_json(resp.json())
    return post_req(
        redvox_config,
        RoutesV1.METADATA_REQ_M,
        packet_metadata_req,
        handle_resp,
        session,
        timeout,
    )
Example #7
0
def request_timing_metadata(
    redvox_config: RedVoxConfig,
    timing_req: TimingMetaRequest,
    session: Optional[requests.Session] = None,
    timeout: Optional[float] = None,
) -> TimingMetaResponse:
    """
    Retrieve timing metadata.
    :param redvox_config: An instance of the API configuration.
    :param timing_req: An instance of a timing request.
    :param session: An (optional) session for re-using an HTTP client.
    :param timeout: An (optional) timeout.
    :return: An instance of a timing response.
    """

    def handle_resp(resp) -> TimingMetaResponse:
        json_content: List[Dict] = resp.json()
        # noinspection Mypy
        # pylint: disable=E1101
        items: List[TimingMeta] = list(map(TimingMeta.from_dict, json_content))
        return TimingMetaResponse(items)

    res: Optional[TimingMetaResponse] = post_req(
        redvox_config,
        RoutesV1.TIMING_METADATA_REQ,
        timing_req,
        handle_resp,
        session,
        timeout,
    )

    return res if res else TimingMetaResponse([])
Example #8
0
def request_station_statuses(
    redvox_config: RedVoxConfig,
    station_status_req: StationStatusReq,
    session: Optional[requests.Session] = None,
    timeout: Optional[float] = None,
) -> Optional[StationStatusResp]:
    # noinspection Mypy
    handle_resp: Callable[
        [requests.Response], StationStatusResp
    ] = lambda resp: StationStatusResp.from_dict(resp.json())
    return post_req(
        redvox_config,
        RoutesV1.STATION_STATUS_TIMELINE,
        station_status_req,
        handle_resp,
        session,
        timeout,
    )
Example #9
0
def request_range_data(
    redvox_config: RedVoxConfig,
    data_range_req: DataRangeReq,
    session: Optional[requests.Session] = None,
    timeout: Optional[float] = None,
    req_type: DataRangeReqType = DataRangeReqType.API_900,
) -> DataRangeResp:
    """
    Requests signed URLs for a range of RedVox packets.
    :param redvox_config: An API config.
    :param data_range_req: The request.
    :param session: An (optional) session for re-using an HTTP client.
    :param timeout: An (optional) timeout.
    :param req_type: (Optional) defines which type of RedVox data should be requested
    :return: A DataRangeResp.
    """
    # noinspection Mypy
    # pylint: disable=E1101
    handle_resp: Callable[
        [requests.Response],
        DataRangeResp] = lambda resp: DataRangeResp.from_dict(resp.json())

    # API 900
    if req_type == DataRangeReqType.API_900:
        res: Optional[DataRangeResp] = post_req(
            redvox_config,
            RoutesV1.DATA_RANGE_REQ,
            data_range_req,
            handle_resp,
            session,
            timeout,
        )

        return res if res else DataRangeResp([])
    # API 1000
    elif req_type == DataRangeReqType.API_1000:
        res = post_req(
            redvox_config,
            RoutesV1.DATA_RANGE_REQ_M,
            data_range_req,
            handle_resp,
            session,
            timeout,
        )

        return res if res else DataRangeResp([])
    # API 900 and 1000
    else:
        res_900: Optional[DataRangeResp] = post_req(
            redvox_config,
            RoutesV1.DATA_RANGE_REQ,
            data_range_req,
            handle_resp,
            session,
            timeout,
        )

        res_1000: Optional[DataRangeResp] = post_req(
            redvox_config,
            RoutesV1.DATA_RANGE_REQ_M,
            data_range_req,
            handle_resp,
            session,
            timeout,
        )

        res_900_final: DataRangeResp = DataRangeResp(
            []) if res_900 is None else res_900
        res_1000_final: DataRangeResp = (DataRangeResp([])
                                         if res_1000 is None else res_1000)

        return res_900_final.append(res_1000_final)