Permalink
Browse files

Cleaning things up, html response bug fix, other smalls things

  • Loading branch information...
1 parent 68d3011 commit ed65259d7c0bc7c833447af1f1fbb2778afcceb2 @arfrank committed Nov 14, 2010
@@ -18,6 +18,4 @@ curl -v -d "FriendlyName=TVSHOW&VoiceUrl=http://www.cnn.com" --user AC4b63ca275b
curl -v -X DELETE --user AC4b63ca275b10e0908abb60f9e6ff6a676079bceba07ea502bfcf9c16b449bdda:0143bc9f3df75ac4431043f24c18295ffa9fbee5fbbac27879d9d184ad62db5f localhost:8094/2010-04-01/Accounts/AC4b63ca275b10e0908abb60f9e6ff6a676079bceba07ea502bfcf9c16b449bdda/IncomingPhoneNumbers/*SID*
#Update a users friendlyname
-
-#RETRIEVE PHONE NUMBER LIST
curl -d "FriendlyName=testusername" --user AC4b63ca275b10e0908abb60f9e6ff6a676079bceba07ea502bfcf9c16b449bdda:0143bc9f3df75ac4431043f24c18295ffa9fbee5fbbac27879d9d184ad62db5f localhost:8094/2010-04-01/Accounts/AC4b63ca275b10e0908abb60f9e6ff6a676079bceba07ea502bfcf9c16b449bdda
@@ -34,6 +34,7 @@ def authorized_method(self, API_VERSION, ACCOUNT_SID, *args, **kwargs):
if Account is not None:
authstring = base64.encodestring(Account.Sid+':'+Account.AuthToken).replace('\n','')
if 'Authorization' in self.request.headers: #hasattr(self.request.headers,'Authorization'):
+ logging.info("basic http authorization")
request_auth = self.request.headers['Authorization'].split(' ')
if request_auth[0] == 'Basic' and request_auth[1]==authstring:
if Account.Status == 'active':
@@ -45,10 +46,14 @@ def authorized_method(self, API_VERSION, ACCOUNT_SID, *args, **kwargs):
logging.info('Basic Authorization Failed')
self.response.out.write(response.format_response(errors.rest_error_response(401,"Unauthorized",format),format))
else:
+ #CURRENTLY DOES NOT ENTIRELY WORK, the url is sometimes sanitized when done in a browser
+ logging.info("url authorization")
#should return a tuple of components, but documentation doesnt explain how to retrieve username & password
parsed_url = urlparse.urlparse(self.request.url)
+ #logging.info(parsed_url)
netloc = parsed_url.netloc
net_split = netloc.rsplit('@',1)
+ #logging.info(net_split)
if len(net_split) == 2:
auth_info = net_split[0]
auth_split = auth_info.split(':')
View
@@ -476,7 +476,6 @@ def get(self):
path = os.path.join(os.path.dirname(__file__), '../templates/caller-ids.html')
self.response.out.write(template.render(path,{'data':self.data}))
-
class CallerId(webapp.RequestHandler):
@webapp_decorator.check_logged_in
def get(self, Sid):
@@ -490,12 +489,13 @@ def get(self):
self.data['host'] = urlparse.urlparse(self.request.url).netloc
path = os.path.join(os.path.dirname(__file__), '../templates/examples.html')
self.response.out.write(template.render(path,{'data':self.data}))
-
+
class Logout(webapp.RequestHandler):
def get(self):
session = get_current_session()
session.terminate()
self.redirect('/')
+
def main():
application = webapp.WSGIApplication([
('/', MainHandler),
View
@@ -1,15 +1,19 @@
+import logging
+
def to_html(dictionary):
+ #logging.info(dictionary)
string = ""
for item in dictionary:
+ #logging.info(item)
if item.lower() == 'twilioresponse' and type(dictionary[item]) is dict:
- string += "<html><head><title>200</title></head>"+"<body class=\"twilioresponse\">"+to_html(dictionary[item])+"</body></html>"
- if type(dictionary[item]) is dict:
- string += "<div class=\""+item.lower()+"\">"+to_html(dictionary[item])+"</div>"
+ string += "<html><head><title>200</title><style>body{ margin:15px; } div{padding:10px;}</style></head>"+"<body class=\"twilioresponse\">"+to_html(dictionary[item])+"</body></html>"
+ elif type(dictionary[item]) is dict:
+ string += "<div class=\""+item.lower()+"\">"+item.lower()+': '+to_html(dictionary[item])+"</div>"
elif type(dictionary[item]) is list:
for element in dictionary[item]:
- string+="<dic class=\""+item+"\">"+to_html(element)+"</div>"
+ string+="<dic class=\""+item+"\">"+item+': '+to_html(element)+"</div>"
else:
- string +='<div class="'+item.lower()+'">'+str(dictionary[item])+"</div>"
+ string +='<div class="'+item.lower()+'">'+item.lower()+': '+str(dictionary[item])+"</div>"
return string
@@ -1,36 +0,0 @@
-from helpers import parameters
-
-def validate(self,arg_name,arg_value):
- validators = {
- 'FriendlyName' : self.request.get('FriendlyName',None),
- 'VoiceCallerIdLookup' : parameters.allowed_boolean(self.request.get('VoiceCallerIdLookup',None)),
- 'VoiceUrl' : parameters.standard_urls(self.request.get('VoiceUrl',None))
- 'VoiceMethod' : parameters.allowed_methods(arg_value,['GET','POST']),
- 'VoiceFallbackUrl' : self.request.get('VoiceFallbackUrl',None),
- 'VoiceFallbackMethod' : parameters.allowed_methods(arg_value,['GET','POST']),
- 'StatusCallback' : self.request.get('StatusCallback',None),
- 'StatusCallbackMethod' : parameters.allowed_methods(arg_value,['GET','POST']),
- 'SmsUrl' : self.request.get('SmsUrl',None),
- 'SmsMethod' : parameters.allowed_methods(arg_value,['GET','POST']),
- 'SmsFallbackUrl' : self.request.get('SmsFallbackUrl',None),
- 'SmsFallbackMethod' : parameters.allowed_methods(arg_value,['GET','POST'])
- }
-
- return True
-
-def sanitize(self,arg_name,arg_value):
- santizers = {
- 'FriendlyName' : self.request.get('FriendlyName',None),
- 'VoiceCallerIdLookup' : self.request.get('VoiceCallerIdLookup',None),
- 'VoiceUrl' : self.request.get('VoiceUrl',None),
- 'VoiceMethod' : parameters.methods(arg_name,self.request,'POST'),
- 'VoiceFallbackUrl' : self.request.get('VoiceFallbackUrl',None),
- 'VoiceFallbackMethod' : parameters.methods(arg_name,self.request,'POST'),
- 'StatusCallback' : self.request.get('StatusCallback',None),
- 'StatusCallbackMethod' : parameters.methods(arg_name,self.request,'POST'),
- 'SmsUrl' : self.request.get('SmsUrl',None),
- 'SmsMethod' : parameters.methods(arg_name,self.request,'POST'),
- 'SmsFallbackUrl' : self.request.get('SmsFallbackUrl',None),
- 'SmsFallbackMethod' : parameters.methods(arg_name,self.request,'POST')
- }
- return arg_value
@@ -1,39 +0,0 @@
-from helpers import parameters
-
-#Phone Number Helper
-
-def validate(self, phone_number, arg_name, arg_value):
- validators = {
- 'FriendlyName' : self.request.get('FriendlyName',None),
- 'VoiceCallerIdLookup' : parameters.allowed_boolean(self.request.get('VoiceCallerIdLookup',None)),
- 'VoiceUrl' : parameters.standard_urls(self.request.get('VoiceUrl',None))
- 'VoiceMethod' : parameters.allowed_methods(arg_value,['GET','POST']),
- 'VoiceFallbackUrl' : self.request.get('VoiceFallbackUrl',None),
- 'VoiceFallbackMethod' : parameters.allowed_methods(arg_value,['GET','POST']),
- 'StatusCallback' : self.request.get('StatusCallback',None),
- 'StatusCallbackMethod' : parameters.allowed_methods(arg_value,['GET','POST']),
- 'SmsUrl' : self.request.get('SmsUrl',None),
- 'SmsMethod' : parameters.allowed_methods(arg_value,['GET','POST']),
- 'SmsFallbackUrl' : self.request.get('SmsFallbackUrl',None),
- 'SmsFallbackMethod' : parameters.allowed_methods(arg_value,['GET','POST'])
- }
-
- return validators[arg_name](arg_value)
-
-def sanitize(self, phone_number, arg_name, arg_value):
- santizers = {
- 'FriendlyName' : self.request.get('FriendlyName',None),
- 'VoiceCallerIdLookup' : self.request.get('VoiceCallerIdLookup',None),
- 'VoiceUrl' : self.request.get('VoiceUrl',None),
- 'VoiceMethod' : parameters.methods(arg_name,self.request,'POST'),
- 'VoiceFallbackUrl' : self.request.get('VoiceFallbackUrl',None),
- 'VoiceFallbackMethod' : parameters.methods(arg_name,self.request,'POST'),
- 'StatusCallback' : self.request.get('StatusCallback',None),
- 'StatusCallbackMethod' : parameters.methods(arg_name,self.request,'POST'),
- 'SmsUrl' : self.request.get('SmsUrl',None),
- 'SmsMethod' : parameters.methods(arg_name,self.request,'POST'),
- 'SmsFallbackUrl' : self.request.get('SmsFallbackUrl',None),
- 'SmsFallbackMethod' : parameters.methods(arg_name,self.request,'POST')
- }
- return sanitizers[arg_name](arg_value)
-
View
@@ -164,9 +164,9 @@ def walk_tree(nodes, parentType, sms = False):
for node in nodes:
if node.nodeType == node.ELEMENT_NODE:
#If its an element, makes
- logging.info(parentType)
- logging.info(node.nodeName.encode('ascii'))
- logging.info(sms)
+ #logging.info(parentType)
+ #logging.info(node.nodeName.encode('ascii'))
+ #logging.info(sms)
if ( ( parentType == 'Response' and ( ( node.nodeName.encode('ascii') in ALLOWED_SMS_ELEMENTS and sms == True) or (node.nodeName.encode('ascii') in ALLOWED_VOICE_ELEMENTS and sms == False) ) ) or ( parentType in ALLOWED_SUBELEMENTS ) ):
if parentType == 'Response' or node.nodeName.encode('ascii') in ALLOWED_SUBELEMENTS[parentType]:
twiml.append( { 'Type' : node.nodeName.encode( 'ascii' ), 'Attr' : retrieve_attr(node, node.nodeName.encode('ascii'), sms),'Children': walk_tree(node.childNodes, node.nodeName.encode('ascii'), sms) } )
@@ -2,10 +2,10 @@
{% block 'content' %}
<h1 id="fake_twilio_api">Fake Twilio API Examples</h1>
<div id="content">
- <h2>Messages</h2>
- <li>Retrieve a list of messages sent
+ <h2>SMS Messages</h2>
+ <li>Retrieve a list of messages (json response)
<p class="wrap">
- curl {{data.Account.Sid}}:{{data.Account.AuthToken}}@{{data.host}}/2010-04-01/Accounts/{{data.Account.Sid}}/SMS/Messages.json
+ curl --user {{data.Account.Sid}}:{{data.Account.AuthToken}} {{data.host}}/2010-04-01/Accounts/{{data.Account.Sid}}/SMS/Messages.json
</p>
</li>
<h2>Incoming Phone Numbers</h2>
@@ -16,21 +16,28 @@ <h1 id="fake_twilio_api">Fake Twilio API Examples</h1>
</li>
<li>Get an incoming phone numbers information
<p class="wrap">
- curl --user {{data.Account.Sid}}:{{data.Account.AuthToken}} {{data.host}}/2010-04-01/Accounts/{{data.Account.Sid}}/IncomingPhoneNumbers/*SID*
+ curl --user {{data.Account.Sid}}:{{data.Account.AuthToken}} {{data.host}}/2010-04-01/Accounts/{{data.Account.Sid}}/IncomingPhoneNumbers/<b>*SID*</b>
</p>
</li>
<li>Update an incoming phone number's VoiceUrl and FriendlyName
<p class="wrap">
- curl -d "FriendlyName=TVSHOW&amp;VoiceUrl=http://www.cnn.com" --user {{data.Account.Sid}}:{{data.Account.AuthToken}} {{data.host}}/2010-04-01/Accounts/{{data.Account.Sid}}/IncomingPhoneNumbers/*SID*
+ curl -d "FriendlyName=TVSHOW&amp;VoiceUrl=http://www.cnn.com" --user {{data.Account.Sid}}:{{data.Account.AuthToken}} {{data.host}}/2010-04-01/Accounts/{{data.Account.Sid}}/IncomingPhoneNumbers/<b>*SID*</b>
</p>
</li>
<li>Delete an incoming phone number
<p class="wrap">
- curl -v -X DELETE --user {{data.Account.Sid}}:{{data.Account.AuthToken}} {{data.host}}/2010-04-01/Accounts/{{data.Account.Sid}}/IncomingPhoneNumbers/*SID*
+ curl -X DELETE --user {{data.Account.Sid}}:{{data.Account.AuthToken}} {{data.host}}/2010-04-01/Accounts/{{data.Account.Sid}}/IncomingPhoneNumbers/<b>*SID*</b>
</p>
</li>
+ <h2>Accounts</h2>
+ <li>
+ Update an accounts information (friendly name)
+ <p class="wrap">
+ curl -d "FriendlyName=NewFriendlyName" --user {{data.Account.Sid}}:{{data.Account.AuthToken}} {{data.host}}/2010-04-01/Accounts/{{data.Account.Sid}}
+ </p>
+ </li>
</div>
{% endblock %}

0 comments on commit ed65259

Please sign in to comment.