123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- var mktSuite = (function(){
- var actions = {}
- var urlAPIMkt = "http://142.93.247.97:8081"
- var auth = "eyJ1dWlkIjoiNjM2MzJkY2YtNWQzMi00NTJhLTkzMjItYjQ5NGMwNmMwNmQ5NWI4M2Y3NjAyZTZkZiIsImF1dGgiOiI5M2YzZGQzZjBkZmE4NzY5ZjMyNzMxYjFhZmVkMmY5NTZmOWM3Yzg0YzhiODQzYzY5YjE4M2ViZGE2NGQxN2NlIn0="
- var auth2 = "eyJ1dWlkIjoiOWJhZDg3ZDEtMDY3Ny00ZGMxLTllMDAtMDA1ZTZlYTkzYTBiNWI4NTdlNjU1YjE0NyIsImF1dGgiOiJmZDhmODU3NzFhYWRmZmFjZmQ4ZjdiMDI3NWY3YzdjY2RjNDg3MjhiOTM4NGYyNGM1OGViMzE3YzdlM2QwYmNiIn0="
- var account = null
- function call(method, uri, data, success, process) {
- $.ajax({
- xhr: function() {
- var xhr = new window.XMLHttpRequest();
- if(process) {
- xhr.upload.addEventListener("progress", function(evt) {
- if (evt.lengthComputable) {
- var percentComplete = evt.loaded / evt.total;
- percentComplete = parseInt(percentComplete * 100);
- process(percentComplete)
- }
- }, false);
- }
- return xhr;
- },
- url: urlAPIMkt + uri,
- data: data,
- type: method,
- // contentType: false,
- // processData: false,
- crossDomain: true,
- beforeSend: function(xhr){
- xhr.setRequestHeader('Auth', auth)
- xhr.setRequestHeader('account', account)
- },
- success: function(data) {
- success(data)
- }
- });
- }
- var accounts = null
- actions.authentication = function(success) {
- call('GET', '/account', null, function (data) {
- accounts = data.accounts;
- if (accounts != null) {
- actions.validation(accounts[0], success)
- } else {
- alert("Não possui contas")
- }
- })
- }
- actions.validation = function (data, success) {
- var token = data.token
- call('POST', '/account/auth', { account: token }, function (data) {
- account = data.token
- success()
- console.log(account);
- })
- }
- actions.getContactList = function (start, limit) {
- start = start || 0
- limit = limit || 100
- call('GET', '/contactlist?start='+start+'&limit='+limit, null, function (data) {
- console.log(data);
- })
- }
- actions.postContactList = function (name, description) {
- name = name
- description = description || ''
- call('POST', '/contactlist', {name: name, description: description}, function (data) {
- console.log(data);
- })
- }
- actions.getContactListId = function () {
- call('GET', '/contactlist/22', null, function (data) {
- console.log(data);
- })
- }
- actions.putContactListId = function (name, description) {
- name = name || ''
- description = description || ''
- call('PUT', '/contactlist/22', {name: name, description: description}, function (data) {
- console.log(data);
- })
- }
- actions.getContactListFields = function () {
- call('GET', '/contactlist/22/field', null, function (data) {
- console.log(data);
- })
- }
- actions.postContactListFields = function (cli, name, tag) {
- ct = 'string'
- cli = cli
- name = name
- tag = tag || ''
- call('POST', '/field', {columnType: ct, contactListId: cli, name: name, tag: tag}, function (data) {
- console.log(data);
- })
- }
- actions.getContactListContacts = function (start, limit, filter) {
- start = start || 0
- limit = limit || 100
- name = filter || ''
- email = filter || ''
- phone = filter || ''
- call('GET', '/contactlist/22/contact?start='+start+'&limit='+limit+'&name='+filter+'&email='+filter+'&phone='+filter, null, function (data) {
- console.log(data);
- })
- }
- actions.getContact = function () {
- call('GET', '/contact/200', null, function (data) {
- console.log(data);
- })
- }
- actions.postContact = function (cli, name, email, phone) {
- cli = cli
- name = name
- email = email
- phone = phone
- call('POST', '/contact', {contactListId: cli, name: name, email: email, phone: phone}, function (data) {
- console.log(data);
- })
- }
- actions.putContact = function (cli, name, email, phone) {
- cli = cli || ''
- name = name || ''
- email = email || ''
- phone = phone || ''
- call('PUT', '/contact/200', {contactListId: cli, name: name, email: email, phone: phone}, function (data) {
- console.log(data);
- })
- }
- actions.deleteContact = function () {
- call('DELETE', '/contact/205', null, function (data) {
- console.log(data);
- })
- }
- actions.getField = function () {
- call('GET', '/field/74', null, function (data) {
- console.log(data);
- })
- }
- actions.putField = function (name, tag) {
- name = name || ''
- tag = tag || ''
- call('PUT', '/field/32', {name: name, tag: tag}, function (data) {
- console.log(data);
- })
- }
- actions.deleteField = function () {
- call('DELETE', '/field/75', null, function (data) {
- console.log(data);
- })
- }
- actions.getTemplate = function (start, limit) {
- start = start || 0
- limit = limit || 100
- call('GET', '/template?start='+start+'&limit='+limit, null, function (data) {
- console.log(data);
- })
- }
- actions.postTemplate = function (name, content) {
- name = name
- content = content
- call('POST', '/template', {name: name, content: content}, function (data) {
- console.log(data);
- })
- }
- actions.getTemplateId = function () {
- call('GET', '/template/4', null, function (data) {
- console.log(data);
- })
- }
- actions.deleteTemplateId = function () {
- call('DELETE', '/template/5', null, function (data) {
- console.log(data);
- })
- }
- actions.putTemplateId = function (name, content) {
- name = name || ''
- content = content || ''
- call('PUT', '/template/3', {name: name, content: content}, function (data) {
- console.log(data);
- })
- }
- actions.getCampaign = function (start, limit) {
- start = start || 0
- limit = limit || 100
- call('GET', '/campaign?start='+start+'&limit='+limit, null, function (data) {
- console.log(data);
- })
- }
- actions.postCampaign = function (cli, tpi, name, ro) {
- cli = cli
- tpi = tpi
- name = name
- runOn = ro
- call('POST', '/campaign', {contactListId: cli, templateId: tpi, name: name, runOn: ro}, function (data) {
- console.log(data);
- })
- }
- actions.getCampaignId = function () {
- call('GET', '/campaign/4', null, function (data) {
- console.log(data);
- })
- }
- actions.deleteCampaignId = function () {
- call('DELETE', '/campaign/8', null, function (data) {
- console.log(data);
- })
- }
- actions.putCampaignId = function (cli, tpi, name, ro) {
- cli = cli || ''
- tpi = tpi || ''
- name = name || ''
- runOn = ro || ''
- call('PUT', '/campaign/4', null, function (data) {
- console.log(data);
- })
- }
- return actions
- })();
- mktSuite.authentication(function() {
- // mktSuite.getContactList()
- // mktSuite.postContactList('teste')
- // mktSuite.getContactListId()
- // mktSuite.putContactListId()
- // mktSuite.getContactListFields()
- // mktSuite.postContactListFields('22', 'vai saber')
- // mktSuite.getContactListContacts()
- // mktSuite.getContact()
- // mktSuite.deleteContact()
- // mktSuite.postContact('22','nome','email@teste.com','5173626514')
- // mktSuite.putContact()
- // mktSuite.getField()
- // mktSuite.putField()
- // mktSuite.deleteField()
- // mktSuite.getTemplate()
- // mktSuite.postTemplate('template teste','tchau')
- // mktSuite.getTemplateId()
- // mktSuite.putTemplateId()
- // mktSuite.deleteTemplateId()
- // mktSuite.getCampaign()
- // mktSuite.postCampaign('22', '3', 'campanha teste', '2019-04-23T18:25:43.511Z')
- // mktSuite.getCampaignId()
- // mktSuite.putCampaignId()
- // mktSuite.deleteCampaignId()
- })
|