# Path: data_model.py
# class PhoneLog(db.Model):
#   phone       = db.StringProperty()
#   to          = db.StringProperty(multiline=True)
#   date        = db.DateTimeProperty(auto_now_add=True)
#   body        = db.StringProperty(multiline=True,indexed=False)
#   smsID       = db.StringProperty(indexed=False)
#   outboundSMS = db.StringProperty(multiline=True,indexed=False)


import logging
import urllib
import webapp2
import config
from google.appengine.api import memcache
from data_model import PhoneLog
      log.body  = self.request.get('inboundBody')
      log.smsID = self.request.get('sid')
      log.outboundSMS = self.request.get('outboundBody')
      log.put()

## end EventLoggingHandler


class ResetQuotaHandler(webapp2.RequestHandler):
    def get(self):
        logging.info("deleting the memcached quotas for the day...")
        memcache.delete_multi(config.ABUSERS)
        self.response.set_status(200)
        return
## end

# re-direct for old API documentation path
class APIDocs(webapp2.RequestHandler):
    def get(self):
        self.redirect(config.API_URL_BASE)
## end

class APIRedirectHandler(webapp2.RequestHandler):
    def get(self,endpoint=None):
        api_uri = '%sv1/%s?' % (config.API_URL_BASE,endpoint) + urllib.urlencode(self.request.params)
        #logging.info("re-direct %s" % api_uri);
        self.redirect(api_uri);
## end

application = webapp2.WSGIApplication([('/', MainHandler),

# Path: data_model.py
# class PhoneLog(db.Model):
#   phone       = db.StringProperty()
#   to          = db.StringProperty(multiline=True)
#   date        = db.DateTimeProperty(auto_now_add=True)
#   body        = db.StringProperty(multiline=True,indexed=False)
#   smsID       = db.StringProperty(indexed=False)
#   outboundSMS = db.StringProperty(multiline=True,indexed=False)


# Path: main.py
import logging
import urllib
import webapp2
import config
from google.appengine.api import memcache
from data_model import PhoneLog

      log.body  = self.request.get('inboundBody')
      log.smsID = self.request.get('sid')
      log.outboundSMS = self.request.get('outboundBody')
      log.put()

## end EventLoggingHandler


class ResetQuotaHandler(webapp2.RequestHandler):
    def get(self):
        logging.info("deleting the memcached quotas for the day...")
        memcache.delete_multi(config.ABUSERS)
        self.response.set_status(200)
        return
## end

# re-direct for old API documentation path
class APIDocs(webapp2.RequestHandler):
    def get(self):
        self.redirect(config.API_URL_BASE)
## end

class APIRedirectHandler(webapp2.RequestHandler):
    def get(self,endpoint=None):
        api_uri = '%sv1/%s?' % (config.API_URL_BASE,endpoint) + urllib.urlencode(self.request.params)
        #logging.info("re-direct %s" % api_uri);
        self.redirect(api_uri);
## end

application = webapp2.WSGIApplication([('/', MainHandler),

                                      ('/loggingtask', EventLoggingHandler),