# Path: apps/api_bridge.py
# def getarrivals(request, result_count=3):
# def getparking():
# 
# Path: apps/meta.py
# def getStats(phone):


import logging
import webapp2
import twilio
import config
import paywall
from google.appengine.api.taskqueue import Task
from apps import api_bridge
from apps import meta

      # validate it is in fact coming from twilio
      if config.ACCOUNT_SID != self.request.get('AccountSid'):
        logging.error("Inbound request was NOT VALID.  It might have been spoofed!")
        self.response.out.write(errorResponse("Illegal caller"))
        return

      # who called? and what did they ask for?
      phone = self.request.get("From")
      msg = self.request.get("Body")
      logging.info("New inbound request from %s with message, %s" % (self.request.get('From'),msg))

      if paywall.isUserValid(phone) is False:
          if paywall.isUserVirgin(phone) is True:
              logging.info('Brand new caller - welcome them')
              paywall.welcomeSolicitor(phone)
          else:
              # ignore caller
              logging.info('We have seen this number before. Ignore this request')
              return

      # interrogate the message body to determine what to do
      if msg.lower().find('parking') > -1:
          response = api_bridge.getparking()
      elif msg.lower().find('help') > -1:
          response = "Bus arrival requests are either, stopID -or- routeID stopID  Send 'parking' to find parking details"
      elif msg.lower().find('stats') > -1:
          response = meta.getStats(phone)
      else:
          ## magic ##

# Path: apps/api_bridge.py
# def getarrivals(request, result_count=3):
# def getparking():
# 
# Path: apps/meta.py
# def getStats(phone):


# Path: apps/sms.py
import logging
import webapp2
import twilio
import config
import paywall
from google.appengine.api.taskqueue import Task
from apps import api_bridge
from apps import meta


      # validate it is in fact coming from twilio
      if config.ACCOUNT_SID != self.request.get('AccountSid'):
        logging.error("Inbound request was NOT VALID.  It might have been spoofed!")
        self.response.out.write(errorResponse("Illegal caller"))
        return

      # who called? and what did they ask for?
      phone = self.request.get("From")
      msg = self.request.get("Body")
      logging.info("New inbound request from %s with message, %s" % (self.request.get('From'),msg))

      if paywall.isUserValid(phone) is False:
          if paywall.isUserVirgin(phone) is True:
              logging.info('Brand new caller - welcome them')
              paywall.welcomeSolicitor(phone)
          else:
              # ignore caller
              logging.info('We have seen this number before. Ignore this request')
              return

      # interrogate the message body to determine what to do
      if msg.lower().find('parking') > -1:
          response = api_bridge.getparking()
      elif msg.lower().find('help') > -1:
          response = "Bus arrival requests are either, stopID -or- routeID stopID  Send 'parking' to find parking details"
      elif msg.lower().find('stats') > -1:
          response = meta.getStats(phone)
      else:
          ## magic ##

          response = api_bridge.getarrivals(msg,4)