暫無描述

functions.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.contactListFields = function () {
  83. call('GET', '/contactlist/22/field', null, function (data) {
  84. console.log(data);
  85. })
  86. }
  87. actions.contactListContacts = function () {
  88. call('GET', '/contactlist/22/contact', null, function (data) {
  89. console.log(data);
  90. })
  91. }
  92. actions.contact = function () {
  93. call('GET', '/contact/200', null, function (data) {
  94. console.log(data);
  95. })
  96. }
  97. actions.field = function () {
  98. call('GET', '/field/30', null, function (data) {
  99. console.log(data);
  100. })
  101. }
  102. actions.template = function () {
  103. call('GET', '/template', null, function (data) {
  104. console.log(data);
  105. })
  106. }
  107. actions.templateId = function () {
  108. call('GET', '/template/3', null, function (data) {
  109. console.log(data);
  110. })
  111. }
  112. actions.campaign = function () {
  113. call('GET', '/campaign', null, function (data) {
  114. console.log(data);
  115. })
  116. }
  117. actions.campaignId = function () {
  118. call('GET', '/campaign/4', null, function (data) {
  119. console.log(data);
  120. })
  121. }
  122. return actions
  123. })();
  124. mktSuite.authentication(function() {
  125. mktSuite.getContactList()
  126. mktSuite.postContactList('teste')
  127. mktSuite.getContactListId('trocado')
  128. mktSuite.putContactListId()
  129. mktSuite.contactListFields()
  130. mktSuite.contactListContacts()
  131. mktSuite.contact()
  132. mktSuite.field()
  133. mktSuite.template()
  134. mktSuite.templateId()
  135. mktSuite.campaign()
  136. mktSuite.campaignId()
  137. })