thorpedosg

xK38x2Kk

Aug 6th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. import mercadoenvios.*
  2.  
  3. def users= [342351050]
  4.  
  5. def getPreferencesLegacy(userId) {
  6. def uri = "/users/${userId}/shipping_preferences?caller.scopes=admin".toString()
  7. def data
  8. try {
  9. ctx.restClient.get(
  10. uri:uri,
  11. headers:["x-source-data-legacy": "true"],
  12. success: {
  13. data = it.data
  14. },
  15. failure: {
  16. data = null
  17. }
  18. )
  19. }
  20.  
  21. catch(Exception e) {
  22. println "Error actualizando preferences de user ${user}"
  23. }
  24. return data
  25. }
  26.  
  27. def putPreferencesFury(userId, data){
  28. ctx.restClient.put(
  29. uri : "/migration/users/${userId}/shipping_preferences?caller.scopes=admin".toString(),
  30. data: data,
  31. headers:["x-source-data-legacy": "false"],
  32. success : {
  33. if(it.status.getStatusCode() != 200) {
  34. println it.status.getStatusCode()
  35. }
  36. },
  37. failure : {
  38. println "Error ${it.dump()}"
  39. if(it.exception) {
  40. throw it.exception
  41. }
  42. }
  43. )
  44. }
  45.  
  46.  
  47. users.each {userId ->
  48. try {
  49. def data = getPreferencesLegacy(userId)
  50. def mandatory_settings = data.mandatory_settings.findAll{k, v -> v != ""}
  51.  
  52. def newApiData = [
  53. local_pick_up: data.local_pick_up,
  54. modes: data.modes,
  55. free_configurations: data.free_configurations,
  56. trusted_user: data.trusted_user,
  57. mandatory_settings: mandatory_settings,
  58. custom_calculator: data.custom_calculator,
  59. picking_type: data.picking_type,
  60. thermal_printer: data.thermal_printer,
  61. content_declaration_disabled: data.content_declaration_disabled,
  62. mandatory_invoice_data: data.mandatory_invoice_data,
  63. option: data.option,
  64. site_id: data.site_id,
  65. tags: data.tags,
  66. carrier_pickup: data.carrier_pickup,
  67. history: data.history,
  68. items_combination: data.items_combination,
  69. logistics: data.logistics,
  70. services: data.services,
  71. conciliation: data.conciliation
  72. ]
  73. //println mandatory_settings
  74. putPreferencesFury(userId, newApiData)
  75. } catch (Exception e) {
  76. println "Error actualizando preferencias de usuario ${userId}"
  77. }
  78. }
Add Comment
Please, Sign In to add comment