12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #!/usr/bin/perl
- # @file journal.pl
- # @author nas
- # @date 31/01/2022
- # @brief Remote call to the API in order to test
-
- use Config::Std;
- use LWP::UserAgent ();
-
- read_config 'test.cfg' => my %config;
- print "Username : $config{Authentification}{Username}\n";
- print "Host : $config{Authentification}{Host}\n";
- print "Host : $config{Authentification}{Path}\n";
- print "Protocol : $config{Authentification}{Protocol}\n";
-
- local $url = "$config{Authentification}{Protocol}$config{Authentification}{Host}$config{Authentification}{Path}";
- local $ua = LWP::UserAgent->new(timeout => 10);
- $ua->env_proxy;
-
- sub get_code {
- my $path = (exists $_[0])? $_[0] : "";
- my $response = $ua->get( "$url$path" );
- print "rq $url$path\n";
- if ($response->is_success) {
- print $response->decoded_content;
- print "\n";
- }
- else {
- print $response->status_line;
- print "\n";
- }
- }
-
- get_code();
- get_code( "tokens" );
-
- sub rq {
- my $path = (exists $_[0])? $_[0] : "";
- my $method = (exists $_[1])? $_[1] : "";
- my $content = (exists $_[2])? $_[2] : "";
-
- my $req = HTTP::Request->new(POST => "$url$path");
- $req->content_type('application/json');
- $req->content("$content");
- my $res = $ua->request($req);
- print $res->as_string;
- }
-
- rq( "tokens", "GET", "{\"user\" : {\"email\" : \"$config{Authentification}{Email}\", \"password\" : \"$config{Authentification}{Password}\"}}" );
|