Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. /*
  2. The following javascript was created to avoid duplicating code in postman's pre-request scripts
  3. */
  4. var amp = function() {
  5. var api_key = postman.getEnvironmentVariable("api_key"),
  6. api_key_id = postman.getEnvironmentVariable("api_key_id"),
  7. signature_delim = '|',
  8. sign = function(overrides) {
  9. if(typeof overrides !== 'object'){
  10. overrides = {};
  11. }
  12.  
  13. var timestamp = Math.round(new Date() / 1000);
  14.  
  15. if(overrides.timestamp){
  16. timestamp = overrides.timestamp;
  17. }
  18.  
  19. var api_signature = "";
  20. var buffer = '/amp/api/createApp/?key_id=' + api_key_id +
  21. '&timestamp=' + timestamp +
  22. signature_delim + request.data +
  23. signature_delim + api_key;
  24.  
  25. api_signature = md5(buffer);
  26.  
  27. postman.setGlobalVariable("api_timestamp", timestamp);
  28. postman.setGlobalVariable("api_signature", api_signature);
  29. },
  30. cleanup = function(){
  31. postman.clearGlobalVariable("api_timestamp");
  32. postman.clearGlobalVariable("api_signature");
  33. },
  34. md5 = function(value) {
  35. return CryptoJS.MD5(value).toString();
  36. }
  37.  
  38. return {"sign":sign,"cleanup":cleanup };
  39. }();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement