API de comptabilité horaire.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.pl 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/perl
  2. # @file journal.pl
  3. # @author nas
  4. # @date 31/01/2022
  5. # @brief Remote call to the API in order to test
  6. use Config::Std;
  7. use LWP::UserAgent ();
  8. read_config 'test.cfg' => my %config;
  9. print "Username : $config{Authentification}{Username}\n";
  10. print "Host : $config{Authentification}{Host}\n";
  11. print "Host : $config{Authentification}{Path}\n";
  12. print "Protocol : $config{Authentification}{Protocol}\n";
  13. local $url = "$config{Authentification}{Protocol}$config{Authentification}{Host}$config{Authentification}{Path}";
  14. local $ua = LWP::UserAgent->new(timeout => 10);
  15. $ua->env_proxy;
  16. sub get_code {
  17. my $path = (exists $_[0])? $_[0] : "";
  18. my $response = $ua->get( "$url$path" );
  19. print "rq $url$path\n";
  20. if ($response->is_success) {
  21. print $response->decoded_content;
  22. print "\n";
  23. }
  24. else {
  25. print $response->status_line;
  26. print "\n";
  27. }
  28. }
  29. get_code();
  30. get_code( "tokens" );
  31. sub rq {
  32. my $path = (exists $_[0])? $_[0] : "";
  33. my $method = (exists $_[1])? $_[1] : "";
  34. my $content = (exists $_[2])? $_[2] : "";
  35. my $req = HTTP::Request->new(POST => "$url$path");
  36. $req->content_type('application/json');
  37. $req->content("$content");
  38. my $res = $ua->request($req);
  39. print $res->as_string;
  40. }
  41. rq( "tokens", "GET", "{\"user\" : {\"email\" : \"$config{Authentification}{Email}\", \"password\" : \"$config{Authentification}{Password}\"}}" );