Created
March 2, 2012 02:48
-
-
Save J-O-N/1955171 to your computer and use it in GitHub Desktop.
C2C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var c2c = { | |
realm: 'somerealm.sip.2600hz.com', | |
ext_regex: /^79\d\d$/, | |
init: function() { | |
winkstart.registerResources('voip', { | |
'c2c.create': { | |
url: '{api_url}/accounts/{account_id}/clicktocall', | |
dataType: 'application/json', | |
verb: 'PUT' | |
}, | |
'c2c.list': { | |
url: '{api_url}/accounts/{account_id}/clicktocall', | |
dataType: 'application/json', | |
verb: 'GET' | |
}, | |
'c2c.delete': { | |
url: '{api_url}/accounts/{account_id}/clicktocall/{c2c_id}', | |
dataType: 'application/json', | |
verb: 'DELETE' | |
} | |
}); | |
}, | |
clear_all: function(callback) { | |
var THIS = this; | |
winkstart.request('c2c.list', { | |
api_url: winkstart.apps['voip'].api_url, | |
account_id: winkstart.apps['voip'].account_id | |
}, | |
function(data, status) { | |
THIS.clear_all1(data.data, callback); | |
} | |
); | |
}, | |
clear_all1: function(list, callback) { | |
var THIS = this; | |
if(!list.length) { | |
callback(); | |
} | |
else { | |
winkstart.request('c2c.delete', { | |
api_url: winkstart.apps['voip'].api_url, | |
account_id: winkstart.apps['voip'].account_id, | |
c2c_id: list[0].id | |
}, | |
function(data, status) { | |
THIS.clear_all1(list.slice(1), callback); | |
} | |
); | |
} | |
}, | |
list_callflow_exts: function(callback) { | |
var THIS = this; | |
winkstart.request('callflow.list', { | |
api_url: winkstart.apps['voip'].api_url, | |
account_id: winkstart.apps['voip'].account_id | |
}, | |
function(data, status) { | |
var extensions = []; | |
$.each(data.data, function(index, callflow_data) { | |
$.each(callflow_data.numbers || [], function(index, number) { | |
if(number.match(THIS.ext_regex)) { | |
extensions.push(number); | |
} | |
}); | |
}); | |
callback(extensions); | |
} | |
); | |
}, | |
create_c2c_docs: function(ext_list, callback) { | |
var THIS = this; | |
THIS.create_c2c_docs1(ext_list, [], callback); | |
}, | |
create_c2c_docs1: function(ext_list, acc_list, callback) { | |
var THIS = this; | |
if(!ext_list.length) { | |
callback(acc_list); | |
} | |
else { | |
winkstart.request('c2c.create', { | |
api_url: winkstart.apps['voip'].api_url, | |
account_id: winkstart.apps['voip'].account_id, | |
data: { | |
name: ext_list[0], | |
realm: THIS.realm, | |
extension: ext_list[0], | |
auth_required: false | |
} | |
}, | |
function(data, status) { | |
acc_list.push({ | |
extension: ext_list[0], | |
c2c_id: data.data.id | |
}); | |
THIS.create_c2c_docs1(ext_list.slice(1), acc_list, callback); | |
} | |
); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment