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