<s> import datetime <EOL> import logging <EOL> import twilio <EOL> from twilio import TwilioException <EOL> from twilio import TwilioRestException <EOL> from urllib import urlencode <EOL> from urlparse import urlparse <EOL> try : <EOL> import simplejson as json <EOL> except ImportError : <EOL> try : <EOL> import json <EOL> except ImportError : <EOL> from django . utils import simplejson as json <EOL> try : <EOL> import httplib2 <EOL> except ImportError : <EOL> from twilio . contrib import httplib2 <EOL> def transform_params ( p ) : <EOL> """<STR_LIT>""" <EOL> p = [ ( d , convert_boolean ( p [ d ] ) ) for d in p if p [ d ] is not None ] <EOL> return dict ( p ) <EOL> def parse_date ( d ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( d , datetime . datetime ) : <EOL> return str ( d . date ( ) ) <EOL> elif isinstance ( d , datetime . date ) : <EOL> return str ( d ) <EOL> elif isinstance ( d , str ) : <EOL> return d <EOL> def convert_boolean ( bool ) : <EOL> if bool == True : <EOL> return "<STR_LIT:true>" <EOL> elif bool == False : <EOL> return "<STR_LIT:false>" <EOL> else : <EOL> return bool <EOL> def convert_case ( s ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' . join ( [ a . title ( ) for a in s . split ( "<STR_LIT:_>" ) if a ] ) <EOL> def convert_keys ( d ) : <EOL> """<STR_LIT>""" <EOL> special = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> result = { } <EOL> for k , v in d . iteritems ( ) : <EOL> if k in special : <EOL> result [ special [ k ] ] = v <EOL> else : <EOL> result [ convert_case ( k ) ] = v <EOL> return result <EOL> def normalize_dates ( myfunc ) : <EOL> def inner_func ( * args , ** kwargs ) : <EOL> for k , v in kwargs . iteritems ( ) : <EOL> res = [ True for s in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] if s in k ] <EOL> if len ( res ) : <EOL> kwargs [ k ] = parse_date ( v ) <EOL> return myfunc ( * args , ** kwargs ) <EOL> return inner_func <EOL> class Response ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , httplib_resp , content , url ) : <EOL> self . content = content <EOL> self . cached = False <EOL> self . status_code = int ( httplib_resp . status ) <EOL> self . ok = self . status_code < <NUM_LIT> <EOL> self . url = url <EOL> def make_request ( method , url , <EOL> params = None , data = None , headers = None , cookies = None , files = None , <EOL> auth = None , timeout = None , allow_redirects = False , proxies = None ) : <EOL> """<STR_LIT>""" <EOL> http = httplib2 . Http ( timeout = timeout ) <EOL> http . follow_redirects = allow_redirects <EOL> if auth is not None : <EOL> http . add_credentials ( auth [ <NUM_LIT:0> ] , auth [ <NUM_LIT:1> ] ) <EOL> if data is not None : <EOL> data = urlencode ( data ) <EOL> if params is not None : <EOL> enc_params = urlencode ( params , doseq = True ) <EOL> if urlparse ( url ) . query : <EOL> url = '<STR_LIT>' % ( url , enc_params ) <EOL> else : <EOL> url = '<STR_LIT>' % ( url , enc_params ) <EOL> resp , content = http . request ( url , method , headers = headers , body = data ) <EOL> return Response ( resp , content , url ) <EOL> def make_twilio_request ( method , uri , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> headers = kwargs . get ( "<STR_LIT>" , { } ) <EOL> headers [ "<STR_LIT>" ] = "<STR_LIT>" % twilio . __version__ <EOL> if method == "<STR_LIT:POST>" and "<STR_LIT:Content-Type>" not in headers : <EOL> headers [ "<STR_LIT:Content-Type>" ] = "<STR_LIT>" <EOL> kwargs [ "<STR_LIT>" ] = headers <EOL> if "<STR_LIT>" not in headers : <EOL> headers [ "<STR_LIT>" ] = "<STR_LIT:application/json>" <EOL> uri = uri + "<STR_LIT>" <EOL> resp = make_request ( method , uri , ** kwargs ) <EOL> if not resp . ok : <EOL> try : <EOL> error = json . loads ( resp . content ) <EOL> message = "<STR_LIT>" % ( error [ "<STR_LIT:code>" ] , error [ "<STR_LIT:message>" ] ) <EOL> except : <EOL> message = resp . content <EOL> raise TwilioRestException ( resp . status_code , resp . url , message ) <EOL> return resp <EOL> class Resource ( object ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> def __init__ ( self , base_uri , auth ) : <EOL> self . base_uri = base_uri <EOL> self . auth = auth <EOL> def __eq__ ( self , other ) : <EOL> return ( isinstance ( other , self . __class__ ) <EOL> and self . __dict__ == other . __dict__ ) <EOL> def __ne__ ( self , other ) : <EOL> return not self . __eq__ ( other ) <EOL> def request ( self , method , uri , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> resp = make_twilio_request ( method , uri , auth = self . auth , ** kwargs ) <EOL> logging . debug ( resp . content ) <EOL> if method == "<STR_LIT>" : <EOL> return resp , { } <EOL> else : <EOL> return resp , json . loads ( resp . content ) <EOL> @ property <EOL> def uri ( self ) : <EOL> format = ( self . base_uri , self . name ) <EOL> return "<STR_LIT>" % format <EOL> class InstanceResource ( Resource ) : <EOL> subresources = [ ] <EOL> def __init__ ( self , parent , sid ) : <EOL> self . parent = parent <EOL> self . name = sid <EOL> super ( InstanceResource , self ) . __init__ ( parent . uri , <EOL> parent . auth ) <EOL> def load ( self , entries ) : <EOL> if "<STR_LIT>" in entries . keys ( ) : <EOL> entries [ "<STR_LIT>" ] = entries [ "<STR_LIT>" ] <EOL> del entries [ "<STR_LIT>" ] <EOL> if "<STR_LIT>" in entries . keys ( ) : <EOL> del entries [ "<STR_LIT>" ] <EOL> self . __dict__ . update ( entries ) <EOL> def load_subresources ( self ) : <EOL> """<STR_LIT>""" <EOL> for resource in self . subresources : <EOL> list_resource = resource ( self . uri , self . parent . auth ) <EOL> self . __dict__ [ list_resource . key ] = list_resource <EOL> def update_instance ( self , ** kwargs ) : <EOL> a = self . parent . update ( self . name , ** kwargs ) <EOL> self . load ( a . __dict__ ) <EOL> def delete_instance ( self ) : <EOL> return self . parent . delete ( self . name ) <EOL> class ListResource ( Resource ) : <EOL> name = "<STR_LIT>" <EOL> instance = InstanceResource <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ListResource , self ) . __init__ ( * args , ** kwargs ) <EOL> try : <EOL> self . key <EOL> except AttributeError : <EOL> self . key = self . name . lower ( ) <EOL> def get ( self , sid ) : <EOL> """<STR_LIT>""" <EOL> return self . get_instance ( sid ) <EOL> def get_instance ( self , sid ) : <EOL> """<STR_LIT>""" <EOL> uri = "<STR_LIT>" % ( self . uri , sid ) <EOL> resp , item = self . request ( "<STR_LIT:GET>" , uri ) <EOL> return self . load_instance ( item ) <EOL> def get_instances ( self , params = None , page = None , page_size = None ) : <EOL> """<STR_LIT>""" <EOL> params = params or { } <EOL> if page is not None : <EOL> params [ "<STR_LIT>" ] = page <EOL> if page_size is not None : <EOL> params [ "<STR_LIT>" ] = page_size <EOL> resp , page = self . request ( "<STR_LIT:GET>" , self . uri , params = params ) <EOL> if self . key not in page : <EOL> raise TwilioException ( "<STR_LIT>" % self . key ) <EOL> return [ self . load_instance ( ir ) for ir in page [ self . key ] ] <EOL> def create_instance ( self , body ) : <EOL> """<STR_LIT>""" <EOL> resp , instance = self . request ( "<STR_LIT:POST>" , self . uri , data = body ) <EOL> if resp . status_code != <NUM_LIT> : <EOL> raise TwilioRestException ( resp . status , <EOL> self . uri , "<STR_LIT>" ) <EOL> return self . load_instance ( instance ) <EOL> def delete_instance ( self , sid ) : <EOL> """<STR_LIT>""" <EOL> uri = "<STR_LIT>" % ( self . uri , sid ) <EOL> resp , instance = self . request ( "<STR_LIT>" , uri ) <EOL> return resp . status_code == <NUM_LIT> <EOL> def update_instance ( self , sid , body ) : <EOL> """<STR_LIT>""" <EOL> uri = "<STR_LIT>" % ( self . uri , sid ) <EOL> resp , entry = self . request ( "<STR_LIT:POST>" , uri , data = body ) <EOL> return self . load_instance ( entry ) <EOL> def count ( self ) : <EOL> """<STR_LIT>""" <EOL> resp , page = self . request ( "<STR_LIT:GET>" , self . uri ) <EOL> return page [ "<STR_LIT>" ] <EOL> def iter ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> p = <NUM_LIT:0> <EOL> try : <EOL> while True : <EOL> for r in self . list ( page = p , ** kwargs ) : <EOL> yield r <EOL> p += <NUM_LIT:1> <EOL> except TwilioRestException : <EOL> pass <EOL> def load_instance ( self , data ) : <EOL> instance = self . instance ( self , data [ "<STR_LIT>" ] ) <EOL> instance . load ( data ) <EOL> instance . load_subresources ( ) <EOL> return instance <EOL> class AvailablePhoneNumber ( InstanceResource ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent ) : <EOL> super ( AvailablePhoneNumber , self ) . __init__ ( parent , "<STR_LIT>" ) <EOL> self . name = "<STR_LIT>" <EOL> def purchase ( self , ** kwargs ) : <EOL> return self . parent . purchase ( phone_number = self . phone_number , <EOL> ** kwargs ) <EOL> class AvailablePhoneNumbers ( ListResource ) : <EOL> name = "<STR_LIT>" <EOL> key = "<STR_LIT>" <EOL> instance = AvailablePhoneNumber <EOL> types = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> def __init__ ( self , base_uri , auth , phone_numbers ) : <EOL> super ( AvailablePhoneNumbers , self ) . __init__ ( base_uri , auth ) <EOL> self . phone_numbers = phone_numbers <EOL> def get ( self , sid ) : <EOL> raise TwilioException ( "<STR_LIT>" ) <EOL> def list ( self , type = "<STR_LIT>" , country = "<STR_LIT>" , region = None , area_code = None , <EOL> postal_code = None , near_number = None , near_lat_long = None , lata = None , <EOL> rate_center = None , distance = None , contains = None ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : region , <EOL> "<STR_LIT>" : postal_code , <EOL> "<STR_LIT>" : contains , <EOL> "<STR_LIT>" : area_code , <EOL> "<STR_LIT>" : lata , <EOL> "<STR_LIT>" : rate_center , <EOL> "<STR_LIT>" : distance , <EOL> "<STR_LIT>" : near_number , <EOL> "<STR_LIT>" : near_lat_long , <EOL> } ) <EOL> uri = "<STR_LIT>" % ( self . uri , country , self . types [ type ] ) <EOL> resp , page = self . request ( "<STR_LIT:GET>" , uri , params = params ) <EOL> return [ self . load_instance ( i ) for i in page [ self . key ] ] <EOL> def load_instance ( self , data ) : <EOL> instance = self . instance ( self . phone_numbers ) <EOL> instance . load ( data ) <EOL> instance . load_subresources ( ) <EOL> return instance <EOL> class Transcription ( InstanceResource ) : <EOL> pass <EOL> class Transcriptions ( ListResource ) : <EOL> name = "<STR_LIT>" <EOL> instance = Transcription <EOL> def list ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . get_instances ( ** kwargs ) <EOL> class Recording ( InstanceResource ) : <EOL> subresources = [ <EOL> Transcriptions , <EOL> ] <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( Recording , self ) . __init__ ( * args , ** kwargs ) <EOL> self . formats = { <EOL> "<STR_LIT>" : self . uri + "<STR_LIT>" , <EOL> "<STR_LIT>" : self . uri + "<STR_LIT>" , <EOL> } <EOL> def delete ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . delete_instance ( ) <EOL> class Recordings ( ListResource ) : <EOL> name = "<STR_LIT>" <EOL> instance = Recording <EOL> @ normalize_dates <EOL> def list ( self , call_sid = None , before = None , after = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : call_sid , <EOL> "<STR_LIT>" : before , <EOL> "<STR_LIT>" : after , <EOL> } ) <EOL> return self . get_instances ( params = params ) <EOL> def delete ( self , sid ) : <EOL> """<STR_LIT>""" <EOL> return self . delete_instance ( sid ) <EOL> class Notification ( InstanceResource ) : <EOL> def delete ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . delete_instance ( ) <EOL> class Notifications ( ListResource ) : <EOL> name = "<STR_LIT>" <EOL> instance = Notification <EOL> @ normalize_dates <EOL> def list ( self , before = None , after = None , log_level = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : before , <EOL> "<STR_LIT>" : after , <EOL> "<STR_LIT>" : log_level , <EOL> } ) <EOL> return self . get_instances ( params = params , ** kwargs ) <EOL> def delete ( self , sid ) : <EOL> """<STR_LIT>""" <EOL> return self . delete_instance ( sid ) <EOL> class Call ( InstanceResource ) : <EOL> """<STR_LIT>""" <EOL> BUSY = "<STR_LIT>" <EOL> CANCELED = "<STR_LIT>" <EOL> COMPLETED = "<STR_LIT>" <EOL> FAILED = "<STR_LIT>" <EOL> IN_PROGRESS = "<STR_LIT>" <EOL> NO_ANSWER = "<STR_LIT>" <EOL> QUEUED = "<STR_LIT>" <EOL> RINGING = "<STR_LIT>" <EOL> subresources = [ <EOL> Notifications , <EOL> Recordings , <EOL> ] <EOL> def hangup ( self ) : <EOL> """<STR_LIT>""" <EOL> a = self . parent . hangup ( self . name ) <EOL> self . load ( a . __dict__ ) <EOL> def cancel ( self ) : <EOL> """<STR_LIT>""" <EOL> a = self . parent . cancel ( self . name ) <EOL> self . load ( a . __dict__ ) <EOL> def route ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> a = self . parent . route ( self . name , ** kwargs ) <EOL> self . load ( a . __dict__ ) <EOL> class Calls ( ListResource ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> instance = Call <EOL> @ normalize_dates <EOL> def list ( self , to = None , from_ = None , status = None , ended_after = None , <EOL> ended_before = None , ended = None , started_before = None , <EOL> started_after = None , started = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : to , <EOL> "<STR_LIT>" : from_ , <EOL> "<STR_LIT>" : status , <EOL> "<STR_LIT>" : started_before , <EOL> "<STR_LIT>" : started_after , <EOL> "<STR_LIT>" : parse_date ( started ) , <EOL> "<STR_LIT>" : ended_before , <EOL> "<STR_LIT>" : ended_after , <EOL> "<STR_LIT>" : parse_date ( ended ) , <EOL> } ) <EOL> return self . get_instances ( params = params , ** kwargs ) <EOL> def create ( self , to , from_ , url , method = None , fallback_url = None , <EOL> fallback_method = None , status_callback = None , status_method = None , <EOL> if_machine = None , send_digits = None , timeout = None , <EOL> application_sid = None ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : to , <EOL> "<STR_LIT>" : from_ , <EOL> "<STR_LIT>" : url , <EOL> "<STR_LIT>" : method , <EOL> "<STR_LIT>" : fallback_url , <EOL> "<STR_LIT>" : fallback_method , <EOL> "<STR_LIT>" : status_callback , <EOL> "<STR_LIT>" : status_method , <EOL> "<STR_LIT>" : send_digits , <EOL> "<STR_LIT>" : timeout , <EOL> "<STR_LIT>" : if_machine , <EOL> "<STR_LIT>" : application_sid , <EOL> } ) <EOL> return self . create_instance ( params ) <EOL> def update ( self , sid , status = None , method = None , url = None ) : <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : status , <EOL> "<STR_LIT>" : url , <EOL> "<STR_LIT>" : method , <EOL> } ) <EOL> return self . update_instance ( sid , params ) <EOL> def cancel ( self , sid ) : <EOL> """<STR_LIT>""" <EOL> return self . update ( sid , status = Call . CANCELED ) <EOL> def hangup ( self , sid ) : <EOL> """<STR_LIT>""" <EOL> return self . update ( sid , status = Call . COMPLETED ) <EOL> def route ( self , sid , url , method = "<STR_LIT:POST>" ) : <EOL> """<STR_LIT>""" <EOL> return self . update ( sid , url = url , method = method ) <EOL> class CallerId ( InstanceResource ) : <EOL> def delete ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . delete_instance ( ) <EOL> def update ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . update_instance ( ** kwargs ) <EOL> class CallerIds ( ListResource ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> key = "<STR_LIT>" <EOL> instance = CallerId <EOL> def delete ( self , sid ) : <EOL> """<STR_LIT>""" <EOL> self . delete_instance ( sid ) <EOL> def list ( self , phone_number = None , friendly_name = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : phone_number , <EOL> "<STR_LIT>" : friendly_name , <EOL> } ) <EOL> return self . get_instances ( params = params , ** kwargs ) <EOL> def update ( self , sid , friendly_name = None ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : friendly_name , <EOL> } ) <EOL> return self . update_instance ( sid , params ) <EOL> def validate ( self , phone_number , friendly_name = None , call_delay = None , <EOL> extension = None ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : phone_number , <EOL> "<STR_LIT>" : friendly_name , <EOL> "<STR_LIT>" : call_delay , <EOL> "<STR_LIT>" : extension , <EOL> } ) <EOL> resp , validation = self . request ( "<STR_LIT:POST>" , self . uri , data = params ) <EOL> return validation <EOL> class PhoneNumber ( InstanceResource ) : <EOL> def trasfer ( self , account_sid ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def update ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> a = self . parent . update ( self . name , ** kwargs ) <EOL> self . load ( a . __dict__ ) <EOL> def delete ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . parent . delete ( self . name ) <EOL> class PhoneNumbers ( ListResource ) : <EOL> name = "<STR_LIT>" <EOL> key = "<STR_LIT>" <EOL> instance = PhoneNumber <EOL> def __init__ ( self , base_uri , auth ) : <EOL> super ( PhoneNumbers , self ) . __init__ ( base_uri , auth ) <EOL> self . available_phone_numbers = AvailablePhoneNumbers ( base_uri , auth , self ) <EOL> def delete ( self , sid ) : <EOL> """<STR_LIT>""" <EOL> return self . delete_instance ( sid ) <EOL> def list ( self , phone_number = None , friendly_name = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : phone_number , <EOL> "<STR_LIT>" : friendly_name , <EOL> } ) <EOL> return self . get_instances ( params = params , ** kwargs ) <EOL> def purchase ( self , phone_number = None , area_code = None , voice_url = None , <EOL> voice_method = None , voice_fallback_url = None , <EOL> voice_fallback_method = None , <EOL> status_callback_url = None , status_callback_method = None , <EOL> sms_url = None , sms_method = None , sms_fallback_url = None , <EOL> sms_fallback_method = None , voice_caller_id_lookup = None , <EOL> account_sid = None , application_sid = None ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : voice_url , <EOL> "<STR_LIT>" : voice_method , <EOL> "<STR_LIT>" : voice_fallback_url , <EOL> "<STR_LIT>" : voice_fallback_method , <EOL> "<STR_LIT>" : sms_url , <EOL> "<STR_LIT>" : sms_method , <EOL> "<STR_LIT>" : sms_fallback_url , <EOL> "<STR_LIT>" : sms_fallback_method , <EOL> "<STR_LIT>" : status_callback_url , <EOL> "<STR_LIT>" : status_callback_method , <EOL> "<STR_LIT>" : voice_caller_id_lookup , <EOL> "<STR_LIT>" : account_sid , <EOL> "<STR_LIT>" : application_sid , <EOL> } ) <EOL> if phone_number : <EOL> params [ "<STR_LIT>" ] = phone_number <EOL> elif area_code : <EOL> params [ "<STR_LIT>" ] = area_code <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> return self . create_instance ( params ) <EOL> def search ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . available_phone_numbers . list ( ** kwargs ) <EOL> def trasfer ( self , sid , account_sid ) : <EOL> """<STR_LIT>""" <EOL> return self . update_instance ( sid , { "<STR_LIT>" : url , "<STR_LIT>" : method } ) <EOL> def update ( self , sid , api_version = None , voice_url = None , voice_method = None , <EOL> voice_fallback_url = None , voice_fallback_method = None , <EOL> status_callback_method = None , sms_url = None , sms_method = None , <EOL> sms_fallback_url = None , sms_fallback_method = None , <EOL> voice_caller_id_lookup = None , account_sid = None , <EOL> application_sid = None ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : api_version , <EOL> "<STR_LIT>" : voice_url , <EOL> "<STR_LIT>" : voice_method , <EOL> "<STR_LIT>" : voice_fallback_url , <EOL> "<STR_LIT>" : voice_fallback_method , <EOL> "<STR_LIT>" : status_callback_method , <EOL> "<STR_LIT>" : sms_url , <EOL> "<STR_LIT>" : sms_method , <EOL> "<STR_LIT>" : sms_fallback_url , <EOL> "<STR_LIT>" : sms_fallback_method , <EOL> "<STR_LIT>" : voice_caller_id_lookup , <EOL> "<STR_LIT>" : account_sid , <EOL> "<STR_LIT>" : application_sid , <EOL> } ) <EOL> return self . update_instance ( sid , params ) <EOL> class Sandbox ( InstanceResource ) : <EOL> id_key = "<STR_LIT>" <EOL> def update ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> a = self . parent . update ( ** kwargs ) <EOL> self . load ( a . __dict__ ) <EOL> class Sandboxes ( ListResource ) : <EOL> name = "<STR_LIT>" <EOL> instance = Sandbox <EOL> def get ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get_instance ( self . uri ) <EOL> def update ( self , voice_url = None , voice_method = None , sms_url = None , <EOL> sms_method = None ) : <EOL> """<STR_LIT>""" <EOL> data = transform_params ( { <EOL> "<STR_LIT>" : voice_url , <EOL> "<STR_LIT>" : voice_method , <EOL> "<STR_LIT>" : sms_url , <EOL> "<STR_LIT>" : sms_method , <EOL> } ) <EOL> resp , entry = self . request ( "<STR_LIT:POST>" , self . uri , body = body ) <EOL> return self . create_instance ( entry ) <EOL> class Sms ( object ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> key = "<STR_LIT>" <EOL> def __init__ ( self , base_uri , auth ) : <EOL> self . uri = "<STR_LIT>" % base_uri <EOL> self . messages = SmsMessages ( self . uri , auth ) <EOL> self . short_codes = ShortCodes ( self . uri , auth ) <EOL> class SmsMessage ( InstanceResource ) : <EOL> pass <EOL> class SmsMessages ( ListResource ) : <EOL> name = "<STR_LIT>" <EOL> key = "<STR_LIT>" <EOL> instance = SmsMessage <EOL> def create ( self , to = None , from_ = None , body = None , status_callback = None , <EOL> application_sid = None ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : to , <EOL> "<STR_LIT>" : from_ , <EOL> "<STR_LIT>" : body , <EOL> "<STR_LIT>" : status_callback , <EOL> "<STR_LIT>" : application_sid , <EOL> } ) <EOL> return self . create_instance ( params ) <EOL> def list ( self , to = None , from_ = None , before = None , after = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : to , <EOL> "<STR_LIT>" : from_ , <EOL> "<STR_LIT>" : before , <EOL> "<STR_LIT>" : after , <EOL> } ) <EOL> return self . get_instances ( params = params , ** kwargs ) <EOL> class ShortCode ( InstanceResource ) : <EOL> def update ( self , ** kwargs ) : <EOL> return self . parent . update ( self . name , ** kwargs ) <EOL> class ShortCodes ( ListResource ) : <EOL> name = "<STR_LIT>" <EOL> key = "<STR_LIT>" <EOL> instance = ShortCode <EOL> def list ( self , short_code = None , friendly_name = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : short_code , <EOL> "<STR_LIT>" : friendly_name , <EOL> } ) <EOL> return self . get_instances ( params = params , ** kwargs ) <EOL> def update ( self , sid , friendly_name = None , api_version = None , url = None , <EOL> method = None , fallback_url = None , fallback_method = None ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : friendly_name , <EOL> "<STR_LIT>" : api_version , <EOL> "<STR_LIT>" : url , <EOL> "<STR_LIT>" : method , <EOL> "<STR_LIT>" : fallback_url , <EOL> "<STR_LIT>" : fallback_method , <EOL> } ) <EOL> return self . update_instance ( sid , params ) <EOL> class Participant ( InstanceResource ) : <EOL> id_key = "<STR_LIT>" <EOL> def mute ( self ) : <EOL> """<STR_LIT>""" <EOL> self . update_instance ( muted = "<STR_LIT:true>" ) <EOL> def unmute ( self ) : <EOL> """<STR_LIT>""" <EOL> self . update_instance ( muted = "<STR_LIT:false>" ) <EOL> def kick ( self ) : <EOL> """<STR_LIT>""" <EOL> self . delete_instance ( ) <EOL> class Participants ( ListResource ) : <EOL> name = "<STR_LIT>" <EOL> instance = Participant <EOL> def list ( self , muted = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : muted , <EOL> } ) <EOL> return self . get_instances ( params = params , ** kwargs ) <EOL> def mute ( self , call_sid ) : <EOL> """<STR_LIT>""" <EOL> return self . update ( call_sid , muted = True ) <EOL> def unmute ( self , call_sid ) : <EOL> """<STR_LIT>""" <EOL> return self . update ( call_sid , muted = False ) <EOL> def kick ( self , call_sid ) : <EOL> """<STR_LIT>""" <EOL> return self . delete ( call_sid ) <EOL> def delete ( self , call_sid ) : <EOL> """<STR_LIT>""" <EOL> return self . _delete ( call_sid ) <EOL> def update ( self , sid , muted = None ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : muted <EOL> } ) <EOL> return self . update_instance ( sid , params ) <EOL> class Conference ( InstanceResource ) : <EOL> subresources = [ <EOL> Participants <EOL> ] <EOL> class Conferences ( ListResource ) : <EOL> name = "<STR_LIT>" <EOL> instance = Conference <EOL> def list ( self , status = None , friendly_name = None , updated_before = None , <EOL> updated_after = None , created_after = None , created_before = None , <EOL> updated = None , created = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : status , <EOL> "<STR_LIT>" : friendly_name , <EOL> "<STR_LIT>" : updated_before , <EOL> "<STR_LIT>" : updated_after , <EOL> "<STR_LIT>" : updated , <EOL> "<STR_LIT>" : created_before , <EOL> "<STR_LIT>" : created_after , <EOL> "<STR_LIT>" : created , <EOL> } ) <EOL> return self . get_instance ( params = params , ** kwargs ) <EOL> class Application ( InstanceResource ) : <EOL> """<STR_LIT>""" <EOL> def update ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . parent . update ( self . sid , ** kwargs ) <EOL> def delete ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . parent . delete ( self . sid ) <EOL> class Applications ( ListResource ) : <EOL> name = "<STR_LIT>" <EOL> instance = Application <EOL> def list ( self , friendly_name = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : friendly_name , <EOL> } ) <EOL> return self . get_instances ( params = params , ** kwargs ) <EOL> def create ( self , friendly_name = None , api_version = None , voice_url = None , <EOL> voice_method = None , voice_fallback_url = None , <EOL> voice_fallback_method = None , status_callback = None , <EOL> status_callback_method = None , voice_caller_id_lookup = None , <EOL> sms_url = None , sms_method = None , sms_fallback_url = None , <EOL> sms_fallback_method = None , sms_status_callback = None ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : friendly_name , <EOL> "<STR_LIT>" : api_version , <EOL> "<STR_LIT>" : voice_url , <EOL> "<STR_LIT>" : voice_method , <EOL> "<STR_LIT>" : voice_fallback_url , <EOL> "<STR_LIT>" : voice_fallback_method , <EOL> "<STR_LIT>" : status_callback , <EOL> "<STR_LIT>" : status_callback_method , <EOL> "<STR_LIT>" : voice_caller_id_lookup , <EOL> "<STR_LIT>" : sms_fallback_url , <EOL> "<STR_LIT>" : sms_fallback_method , <EOL> "<STR_LIT>" : sms_status_callback , <EOL> } ) <EOL> return self . create_instance ( params ) <EOL> def update ( self , sid , friendly_name = None , api_version = None , voice_url = None , <EOL> voice_method = None , voice_fallback_url = None , <EOL> voice_fallback_method = None , status_callback = None , <EOL> status_callback_method = None , voice_caller_id_lookup = None , <EOL> sms_url = None , sms_method = None , sms_fallback_url = None , <EOL> sms_fallback_method = None , sms_status_callback = None ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : friendly_name , <EOL> "<STR_LIT>" : api_version , <EOL> "<STR_LIT>" : voice_url , <EOL> "<STR_LIT>" : voice_method , <EOL> "<STR_LIT>" : voice_fallback_url , <EOL> "<STR_LIT>" : voice_fallback_method , <EOL> "<STR_LIT>" : status_callback , <EOL> "<STR_LIT>" : status_callback_method , <EOL> "<STR_LIT>" : voice_caller_id_lookup , <EOL> "<STR_LIT>" : sms_fallback_url , <EOL> "<STR_LIT>" : sms_fallback_method , <EOL> "<STR_LIT>" : sms_status_callback , <EOL> } ) <EOL> return self . update_instance ( sid , params ) <EOL> def delete ( self , sid ) : <EOL> """<STR_LIT>""" <EOL> return self . delete_instance ( sid ) <EOL> class Account ( InstanceResource ) : <EOL> """<STR_LIT>""" <EOL> ACTIVE = "<STR_LIT>" <EOL> SUSPENDED = "<STR_LIT>" <EOL> CLOSED = "<STR_LIT>" <EOL> subresources = [ <EOL> Applications , <EOL> Notifications , <EOL> Transcriptions , <EOL> Recordings , <EOL> Calls , <EOL> Sms , <EOL> CallerIds , <EOL> PhoneNumbers , <EOL> Conferences , <EOL> ] <EOL> def update ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . update_instance ( ** kwargs ) <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . update_instance ( status = Account . CLOSED ) <EOL> def suspend ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . update_instance ( status = Account . SUSPENDED ) <EOL> def activate ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . update_instance ( status = Account . ACTIVE ) <EOL> class Accounts ( ListResource ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> instance = Account <EOL> def list ( self , friendly_name = None , status = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : friendly_name , <EOL> "<STR_LIT>" : status , <EOL> } ) <EOL> return self . get_instances ( params = params , ** kwargs ) <EOL> def update ( self , sid , friendly_name = None , status = None ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : friendly_name , <EOL> "<STR_LIT>" : status <EOL> } ) <EOL> return self . update_instance ( sid , params ) <EOL> def close ( self , sid ) : <EOL> """<STR_LIT>""" <EOL> return self . update ( sid , status = Account . CLOSED ) <EOL> def suspend ( self , sid ) : <EOL> """<STR_LIT>""" <EOL> return self . update ( sid , status = Account . SUSPENDED ) <EOL> def activate ( self , sid ) : <EOL> """<STR_LIT>""" <EOL> return self . update ( sid , status = Account . ACTIVE ) <EOL> def create ( self , friendly_name = None ) : <EOL> """<STR_LIT>""" <EOL> params = transform_params ( { <EOL> "<STR_LIT>" : friendly_name , <EOL> } ) <EOL> return self . create_instance ( params ) </s>
