Нема описа

functions.js 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. var mktSuite = (function(){
  2. var actions = {}
  3. var urlAPIMkt = "http://142.93.247.97:8081"
  4. var auth = "eyJ1dWlkIjoiNjM2MzJkY2YtNWQzMi00NTJhLTkzMjItYjQ5NGMwNmMwNmQ5NWI4M2Y3NjAyZTZkZiIsImF1dGgiOiI5M2YzZGQzZjBkZmE4NzY5ZjMyNzMxYjFhZmVkMmY5NTZmOWM3Yzg0YzhiODQzYzY5YjE4M2ViZGE2NGQxN2NlIn0="
  5. var auth2 = "eyJ1dWlkIjoiOWJhZDg3ZDEtMDY3Ny00ZGMxLTllMDAtMDA1ZTZlYTkzYTBiNWI4NTdlNjU1YjE0NyIsImF1dGgiOiJmZDhmODU3NzFhYWRmZmFjZmQ4ZjdiMDI3NWY3YzdjY2RjNDg3MjhiOTM4NGYyNGM1OGViMzE3YzdlM2QwYmNiIn0="
  6. var account = null
  7. function call(method, uri, data, success, process) {
  8. $.ajax({
  9. xhr: function() {
  10. var xhr = new window.XMLHttpRequest();
  11. if(process) {
  12. xhr.upload.addEventListener("progress", function(evt) {
  13. if (evt.lengthComputable) {
  14. var percentComplete = evt.loaded / evt.total;
  15. percentComplete = parseInt(percentComplete * 100);
  16. process(percentComplete)
  17. }
  18. }, false);
  19. }
  20. return xhr;
  21. },
  22. url: urlAPIMkt + uri,
  23. data: data,
  24. type: method,
  25. // contentType: false,
  26. // processData: false,
  27. crossDomain: true,
  28. beforeSend: function(xhr){
  29. xhr.setRequestHeader('Auth', auth)
  30. xhr.setRequestHeader('account', account)
  31. },
  32. success: function(data) {
  33. success(data)
  34. }
  35. });
  36. }
  37. var accounts = null
  38. actions.authentication = function(success) {
  39. call('GET', '/account', null, function (data) {
  40. accounts = data.accounts;
  41. if (accounts != null) {
  42. actions.validation(accounts[0], success)
  43. } else {
  44. alert("Não possui contas")
  45. }
  46. })
  47. }
  48. actions.validation = function (data, success) {
  49. var token = data.token
  50. call('POST', '/account/auth', { account: token }, function (data) {
  51. account = data.token
  52. success()
  53. console.log(account);
  54. })
  55. }
  56. actions.getContactList = function (start, limit) {
  57. start = start || 0
  58. limit = limit || 100
  59. call('GET', '/contactlist?start='+start+'&limit='+limit, null, function (data) {
  60. console.log(data);
  61. })
  62. }
  63. actions.postContactList = function (name, description) {
  64. name = name
  65. description = description || ''
  66. call('POST', '/contactlist', {name: name, description: description}, function (data) {
  67. console.log(data);
  68. })
  69. }
  70. actions.getContactListId = function () {
  71. call('GET', '/contactlist/22', null, function (data) {
  72. console.log(data);
  73. })
  74. }
  75. actions.putContactListId = function (name, description) {
  76. name = name || ''
  77. description = description || ''
  78. call('PUT', '/contactlist/22', {name: name, description: description}, function (data) {
  79. console.log(data);
  80. })
  81. }
  82. actions.getContactListFields = function () {
  83. call('GET', '/contactlist/22/field', null, function (data) {
  84. console.log(data);
  85. })
  86. }
  87. actions.postContactListFields = function (cli, name, tag) {
  88. ct = 'string'
  89. cli = cli
  90. name = name
  91. tag = tag || ''
  92. call('POST', '/field', {columnType: ct, contactListId: cli, name: name, tag: tag}, function (data) {
  93. console.log(data);
  94. })
  95. }
  96. actions.getContactListContacts = function (start, limit, filter) {
  97. start = start || 0
  98. limit = limit || 100
  99. name = filter || ''
  100. email = filter || ''
  101. phone = filter || ''
  102. call('GET', '/contactlist/22/contact?start='+start+'&limit='+limit+'&name='+filter+'&email='+filter+'&phone='+filter, null, function (data) {
  103. console.log(data);
  104. })
  105. }
  106. actions.getContact = function () {
  107. call('GET', '/contact/200', null, function (data) {
  108. console.log(data);
  109. })
  110. }
  111. actions.postContact = function (cli, name, email, phone) {
  112. cli = cli
  113. name = name
  114. email = email
  115. phone = phone
  116. call('POST', '/contact', {contactListId: cli, name: name, email: email, phone: phone}, function (data) {
  117. console.log(data);
  118. })
  119. }
  120. actions.putContact = function (cli, name, email, phone) {
  121. cli = cli || ''
  122. name = name || ''
  123. email = email || ''
  124. phone = phone || ''
  125. call('PUT', '/contact/200', {contactListId: cli, name: name, email: email, phone: phone}, function (data) {
  126. console.log(data);
  127. })
  128. }
  129. actions.deleteContact = function () {
  130. call('DELETE', '/contact/205', null, function (data) {
  131. console.log(data);
  132. })
  133. }
  134. actions.getField = function () {
  135. call('GET', '/field/74', null, function (data) {
  136. console.log(data);
  137. })
  138. }
  139. actions.putField = function (name, tag) {
  140. name = name || ''
  141. tag = tag || ''
  142. call('PUT', '/field/32', {name: name, tag: tag}, function (data) {
  143. console.log(data);
  144. })
  145. }
  146. actions.deleteField = function () {
  147. call('DELETE', '/field/75', null, function (data) {
  148. console.log(data);
  149. })
  150. }
  151. actions.getTemplate = function (start, limit) {
  152. start = start || 0
  153. limit = limit || 100
  154. call('GET', '/template?start='+start+'&limit='+limit, null, function (data) {
  155. console.log(data);
  156. })
  157. }
  158. actions.postTemplate = function (name, content) {
  159. name = name
  160. content = content
  161. call('POST', '/template', {name: name, content: content}, function (data) {
  162. console.log(data);
  163. })
  164. }
  165. actions.getTemplateId = function () {
  166. call('GET', '/template/4', null, function (data) {
  167. console.log(data);
  168. })
  169. }
  170. actions.deleteTemplateId = function () {
  171. call('DELETE', '/template/5', null, function (data) {
  172. console.log(data);
  173. })
  174. }
  175. actions.putTemplateId = function (name, content) {
  176. name = name || ''
  177. content = content || ''
  178. call('PUT', '/template/3', {name: name, content: content}, function (data) {
  179. console.log(data);
  180. })
  181. }
  182. actions.getCampaign = function (start, limit) {
  183. start = start || 0
  184. limit = limit || 100
  185. call('GET', '/campaign?start='+start+'&limit='+limit, null, function (data) {
  186. console.log(data);
  187. })
  188. }
  189. actions.postCampaign = function (cli, tpi, name, ro) {
  190. cli = cli
  191. tpi = tpi
  192. name = name
  193. runOn = ro
  194. call('POST', '/campaign', {contactListId: cli, templateId: tpi, name: name, runOn: ro}, function (data) {
  195. console.log(data);
  196. })
  197. }
  198. actions.getCampaignId = function () {
  199. call('GET', '/campaign/4', null, function (data) {
  200. console.log(data);
  201. })
  202. }
  203. actions.deleteCampaignId = function () {
  204. call('DELETE', '/campaign/8', null, function (data) {
  205. console.log(data);
  206. })
  207. }
  208. actions.putCampaignId = function (cli, tpi, name, ro) {
  209. cli = cli || ''
  210. tpi = tpi || ''
  211. name = name || ''
  212. runOn = ro || ''
  213. call('PUT', '/campaign/4', null, function (data) {
  214. console.log(data);
  215. })
  216. }
  217. return actions
  218. })();
  219. mktSuite.authentication(function() {
  220. // mktSuite.getContactList()
  221. // mktSuite.postContactList('teste')
  222. // mktSuite.getContactListId()
  223. // mktSuite.putContactListId()
  224. // mktSuite.getContactListFields()
  225. // mktSuite.postContactListFields('22', 'vai saber')
  226. // mktSuite.getContactListContacts()
  227. // mktSuite.getContact()
  228. // mktSuite.deleteContact()
  229. // mktSuite.postContact('22','nome','email@teste.com','5173626514')
  230. // mktSuite.putContact()
  231. // mktSuite.getField()
  232. // mktSuite.putField()
  233. // mktSuite.deleteField()
  234. // mktSuite.getTemplate()
  235. // mktSuite.postTemplate('template teste','tchau')
  236. // mktSuite.getTemplateId()
  237. // mktSuite.putTemplateId()
  238. // mktSuite.deleteTemplateId()
  239. // mktSuite.getCampaign()
  240. // mktSuite.postCampaign('22', '3', 'campanha teste', '2019-04-23T18:25:43.511Z')
  241. // mktSuite.getCampaignId()
  242. // mktSuite.putCampaignId()
  243. // mktSuite.deleteCampaignId()
  244. })