Пример #1
0
def validateRequest(request,type):

    # validate the key
    devStoreKey = api_utils.validateDevKey(request.get('key'))
    if devStoreKey is None:
        api_utils.recordDeveloperRequest(None,api_utils.GETSTOPS,request.query_string,request.remote_addr,'illegal developer key specified');
        return None

    return devStoreKey
Пример #2
0
def validateRequest(request):

    # validate the key
    devStoreKey = api_utils.validateDevKey(request.get('key'))
    if devStoreKey is None:
        api_utils.recordDeveloperRequest(None, api_utils.GETARRIVALS,
                                         request.query_string,
                                         request.remote_addr,
                                         'illegal developer key specified')
        return None
    stopID = request.get('stopID')
    routeID = request.get('routeID')
    vehicleID = request.get('vehicleID')

    # give up if someone asked for stop 0, which seems to be popular for some reason
    #logging.debug('validating stopID %s' % stopID);
    if stopID == '' or stopID is '0' or stopID is '0000':
        return None

    # a stopID or routeID is required
    if stopID is None and routeID is None:
        api_utils.recordDeveloperRequest(
            devStoreKey, api_utils.GETARRIVALS, request.query_string,
            request.remote_addr,
            'either a stopID or a routeID must be included')
        return None

    # the routeID requires either a vehicleID or stopID
    if routeID is not None:
        if vehicleID is None and stopID is None:
            api_utils.recordDeveloperRequest(
                devStoreKey, api_utils.GETARRIVALS, request.query_string,
                request.remote_addr,
                'if routeID is specified, either a vehicleID or stopID is required'
            )
            return None

    # the vehicleID requires a routeID
    if vehicleID is not None:
        if routeID is None:
            api_utils.recordDeveloperRequest(
                devStoreKey, api_utils.GETVEHICLE, request.query_string,
                request.remote_addr,
                'if a vehicleID is specified, you must include a routeID')
            return False

    # we've noticed some flagrant abuses of the API where the format
    # of the request parameters are just bogus. check those here
    if len(stopID) > 4:
        return None

    #logging.debug("successfully validated command parameters")
    return devStoreKey
Пример #3
0
def validateRequest(request, type):

    # validate the key
    devStoreKey = api_utils.validateDevKey(request.get('key'))
    if devStoreKey is None:
        logging.debug('... illegal developer key %s' % request.get('key'))
        api_utils.recordDeveloperRequest(None, api_utils.GETSTOPS,
                                         request.query_string,
                                         request.remote_addr,
                                         'illegal developer key specified')
        return None

    if type == api_utils.GETSTOPS:
        routeID = request.get('routeID')
        destination = request.get('destination').upper()

        # a routeID is required
        if routeID is None or routeID is '':
            api_utils.recordDeveloperRequest(devStoreKey, type,
                                             request.query_string,
                                             request.remote_addr,
                                             'a routeID must be included')
            return None
        elif destination is not None and routeID is '':
            api_utils.recordDeveloperRequest(
                devStoreKey, type, request.query_string, request.remote_addr,
                'if a destination is specified, a routeID must be included')
            return None
    elif type == api_utils.GETSTOPLOCATION:
        stopID = api_utils.conformStopID(request.get('stopID'))
        if stopID == '' or stopID == '0' or stopID == '00':
            return None
    elif type == api_utils.GETNEARBYSTOPS:
        lat = request.get('lat')
        lon = request.get('lon')
        radius = request.get('radius')
        # lat/long is required
        if lat is None or lon is None:
            api_utils.recordDeveloperRequest(
                devStoreKey, type, request.query_string, request.remote_addr,
                'both latitude and longitude values must be specified')
            return None
        elif radius is not None and radius is not '' and radius > '5000':
            logging.error(
                'unable to validate getnearbystops call. illegal radius value of %s'
                % radius)
            api_utils.recordDeveloperRequest(devStoreKey, type,
                                             request.query_string,
                                             request.remote_addr,
                                             'radius must be less than 5,000')
            return None

    return devStoreKey
Пример #4
0
def validateRequest(request, type):

    # validate the key
    devStoreKey = api_utils.validateDevKey(request.get('key'))
    if devStoreKey is None:
        api_utils.recordDeveloperRequest(None, api_utils.GETSTOPS,
                                         request.query_string,
                                         request.remote_addr,
                                         'illegal developer key specified')
        return None

    return devStoreKey
Пример #5
0
def validateRequest(request):

    # validate the key
    devStoreKey = api_utils.validateDevKey(request.get('key'))
    if devStoreKey is None:
        api_utils.recordDeveloperRequest(None, api_utils.GETSTOPS, request.query_string, request.remote_addr, 'illegal developer key specified');
        return None

    routeID = request.get('routeID')
    if routeID is None or routeID is '':
        api_utils.recordDeveloperRequest(devStoreKey,type,request.query_string,request.remote_addr,'a routeID must be included');
        return None

    return devStoreKey
Пример #6
0
def validateRequest(request):

    # validate the key
    devStoreKey = api_utils.validateDevKey(request.get('key'))
    if devStoreKey is None:
        api_utils.recordDeveloperRequest(None, api_utils.GETSTOPS,
                                         request.query_string,
                                         request.remote_addr,
                                         'illegal developer key specified')
        return None

    routeID = request.get('routeID')
    if routeID is None or routeID is '':
        api_utils.recordDeveloperRequest(devStoreKey, type,
                                         request.query_string,
                                         request.remote_addr,
                                         'a routeID must be included')
        return None

    return devStoreKey
Пример #7
0
def validateRequest(request):

    # validate the key
    devStoreKey = api_utils.validateDevKey(request.get('key'))
    if devStoreKey is None:
        api_utils.recordDeveloperRequest(None,api_utils.GETARRIVALS,request.query_string,request.remote_addr,'illegal developer key specified');
        return None
    stopID = request.get('stopID')
    routeID = request.get('routeID')
    vehicleID = request.get('vehicleID')

    # give up if someone asked for stop 0, which seems to be popular for some reason
    #logging.debug('validating stopID %s' % stopID);
    if stopID == '' or stopID is '0' or stopID is '0000':
        return None

    # a stopID or routeID is required
    if stopID is None and routeID is None:
        api_utils.recordDeveloperRequest(devStoreKey,api_utils.GETARRIVALS,request.query_string,request.remote_addr,'either a stopID or a routeID must be included');
        return None

    # the routeID requires either a vehicleID or stopID
    if routeID is not None:
        if vehicleID is None and stopID is None:
            api_utils.recordDeveloperRequest(devStoreKey,api_utils.GETARRIVALS,request.query_string,request.remote_addr,'if routeID is specified, either a vehicleID or stopID is required');
            return None

    # the vehicleID requires a routeID
    if vehicleID is not None:
        if routeID is None:
            api_utils.recordDeveloperRequest(devStoreKey,api_utils.GETVEHICLE,request.query_string,request.remote_addr,'if a vehicleID is specified, you must include a routeID');
            return False

    # we've noticed some flagrant abuses of the API where the format
    # of the request parameters are just bogus. check those here
    if len(stopID) > 4:
        return None

    #logging.debug("successfully validated command parameters")
    return devStoreKey
Пример #8
0
def validateRequest(request,type):
    
    # validate the key
    devStoreKey = api_utils.validateDevKey(request.get('key'))
    if devStoreKey is None:
        logging.debug('... illegal developer key %s' % request.get('key'))
        api_utils.recordDeveloperRequest(None,api_utils.GETSTOPS,request.query_string,request.remote_addr,'illegal developer key specified');
        return None
    
    if type == api_utils.GETSTOPS:
        routeID = request.get('routeID')
        destination = request.get('destination').upper()
        
        # a routeID is required
        if routeID is None or routeID is '':
            api_utils.recordDeveloperRequest(devStoreKey,type,request.query_string,request.remote_addr,'a routeID must be included');
            return None
        elif destination is not None and routeID is '':
            api_utils.recordDeveloperRequest(devStoreKey,type,request.query_string,request.remote_addr,'if a destination is specified, a routeID must be included');
            return None
    elif type == api_utils.GETSTOPLOCATION:
        stopID = api_utils.conformStopID(request.get('stopID'))
        if stopID == '' or stopID == '0' or stopID == '00':
            return None            
    elif type == api_utils.GETNEARBYSTOPS:
        lat = request.get('lat')
        lon = request.get('lon')
        radius = request.get('radius')
        # lat/long is required
        if lat is None or lon is None:
            api_utils.recordDeveloperRequest(devStoreKey,type,request.query_string,request.remote_addr,'both latitude and longitude values must be specified');
            return None
        elif radius is not None and radius is not '' and radius > '5000':
            logging.error('unable to validate getnearbystops call. illegal radius value of %s' % radius)
            api_utils.recordDeveloperRequest(devStoreKey,type,request.query_string,request.remote_addr,'radius must be less than 5,000');
            return None

    return devStoreKey