Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2017
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # 20170328 - mflores - Prueba de subir fichero Haberes.xls.
  4.  
  5. use strict;
  6. use warnings;
  7.  
  8. # Global Vars.
  9. my $debug = 0;
  10.  
  11. # OAuth Vars.
  12. my $client_id = 2;
  13. my $client_secret = "zvzY7SugOyUpUq61oug7AZTHmIKekuGikaQ62ss5";
  14.  
  15. # User Vars.
  16. my $username = 'socio@example.com';
  17. my $password = "secret";
  18. my $auth_uri = "https://api.test.sistema.unionportuaria.cl/oauth/token";
  19.  
  20. # Import Vars.
  21. my $file = "/tmp/Haberes.xls";
  22. my $import_uri = "https://api.test.sistema.unionportuaria.cl/api/plantilla/testImport";
  23.  
  24. my $resp1 = `curl -s 1 -F "grant_type=password" -F "client_id=$client_id" -F "client_secret=$client_secret" -F "username=$username" -F "password=$password" $auth_uri`;
  25. print "DEBUG: $resp1 \n" if $debug;
  26.  
  27. my ($token_type, $expires_in, $access_token) = split ",", $resp1;
  28. print "DEBUG: $access_token \n" if $debug;
  29.  
  30. my ($name, $string) = split ":", $access_token;
  31. print "DEBUG: $string \n" if $debug;
  32.  
  33. my $token = substr( $string, 1, (length($string) - 2) );
  34. print "DEBUG: $token \n" if $debug;
  35.  
  36.  
  37. system("curl -H \"Authorization: Bearer $token\" -F archivo=@\"$file\" $import_uri");
  38. # print ("curl -H \"Authorization: Bearer $token\" -F archivo=@\"$file\" $import_uri");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement