def GET(requestparams):
    # TODO: validate parameters
    yahooOAuthTimeZone = YahooOAuthTimeZone()

    try:
        load_result = yahooOAuthTimeZone.loadData(requestparams["zip_code"])
    except ServiceException as e:
        error_view = Error(e.errorCode)
        return error_view.render()

    if load_result is False:
        raise Exception("invalid zip code given")

    try:
        yahooResponse = json.loads(yahooOAuthTimeZone.response)
        if yahooResponse["bossresponse"]["responsecode"] != "200":
            raise ServiceException(
                Exception("Invalid yahoo OAuth response %s." % yahooResponse["bossresponse"]["responsecode"]),
                "ZipCode doesn't exist",
                10001,
            )
    except (ValueError, KeyError, TypeError):
        print "JSON format error"

    yahoo_timezone_view = ReadYahooTimeZone(yahooResponse)

    return yahoo_timezone_view.render()
def GET(requestparams):
    # TODO: validate parameters
    yahooOAuthTimeZone = YahooOAuthTimeZone()

    try:
        load_result = yahooOAuthTimeZone.loadData(requestparams['zip_code'])
    except ServiceException as e:
        error_view = Error(e.errorCode)
        return error_view.render()

    if load_result is False:
        raise Exception("invalid zip code given")

    try:
        yahooResponse = json.loads(yahooOAuthTimeZone.response)
        if yahooResponse['bossresponse']['responsecode'] != '200':
            raise ServiceException(
                Exception("Invalid yahoo OAuth response %s." %
                          yahooResponse['bossresponse']['responsecode']),
                "ZipCode doesn't exist", 10001)
    except (ValueError, KeyError, TypeError):
        print "JSON format error"

    yahoo_timezone_view = ReadYahooTimeZone(yahooResponse)

    return yahoo_timezone_view.render()
def PUT(requestparams, contextparams):
    thermostat = Thermostat()
    try:
        logger.info("Calling update thermostat Model")
        update_result = thermostat.updateThermostatData(
            requestparams['thermostat_id'], requestparams['name'])
    except ServiceException as e:
        error_view = Error(e.errorCode)
        return error_view.render()
    if (update_result) is False:
        raise Exception("Thermsotat data could not be updated")
# need to format the success response to send 200 OK success
    return None
def PUT(requestparams,contextparams):
    thermostat = Thermostat()
    try:
        logger.info("Calling update thermostat Model")
        update_result = thermostat.updateThermostatData(requestparams['thermostat_id'],requestparams['name'])
    except ServiceException as e:
        error_view = Error(e.errorCode)
        return error_view.render()
    if(update_result) is False:
        raise Exception("Thermsotat data could not be updated")
# need to format the success response to send 200 OK success
    return None
    
Esempio n. 5
0
def updateThermostat(thermostat_id=None,guid=None):
    requestparams={'thermostat_id':thermostat_id}
    requestparams.update(request.json)
    contextparams={'guid' : requestparams.pop('guid', 0)}
    if request.json is None:
        return Error(10004).render()
#     result = validate_update_thermostat(requestparams)
#     if result is not None:
#         return result
    result =invoke( 'PUT', 'thermostat',requestparams,contextparams)
    return result
Esempio n. 6
0
def POST(request_params, context_params):
    logger.info("Start of user onboarding")
    location_params = {}
    location_params['locations'] = request_params.pop('locations')
    user_params = request_params

    try:
        user_response = invoke('POST', 'user', user_params, context_params)
        location_params['user_id'] = user_response['user_id']
        location_response = invoke('PUT', 'location', location_params,
                                   context_params)
    except ServiceException as ex:
        logger.error("Onboarding failed for user %s %s" %
                     (user_params, location_params))
        return Error(ex.errorCode)

    response = {}
    response.update(location_response)
    response.update(user_response)
    logger.info("User onboarding succesful")

    return response