API::Base can respond
This commit is contained in:
parent
d0420fe9f3
commit
65f11b676b
@ -1,6 +1,6 @@
|
|||||||
#! /usr/bin/env perl
|
#! /usr/bin/env perl
|
||||||
|
|
||||||
package Base;
|
package API::Base;
|
||||||
|
|
||||||
use v5.10.1;
|
use v5.10.1;
|
||||||
use strict;
|
use strict;
|
||||||
@ -10,6 +10,23 @@ use LWP::UserAgent;
|
|||||||
use XML::LibXML;
|
use XML::LibXML;
|
||||||
use XML::SAX::ParserFactory;
|
use XML::SAX::ParserFactory;
|
||||||
|
|
||||||
|
sub make_response($$)
|
||||||
|
{
|
||||||
|
my $doc = XML::LibXML::Document->new('1.0');
|
||||||
|
my $root = $doc->createElement("response");
|
||||||
|
|
||||||
|
my $result = $doc->createElement("result");
|
||||||
|
$result->appendText(shift);
|
||||||
|
$root->appendChild($result);
|
||||||
|
|
||||||
|
my $message = $doc->createElement("message");
|
||||||
|
$message->appendText(shift);
|
||||||
|
$root->appendChild($message);
|
||||||
|
|
||||||
|
$doc->setDocumentElement( $root );
|
||||||
|
return $doc->toString();
|
||||||
|
}
|
||||||
|
|
||||||
sub parse($$)
|
sub parse($$)
|
||||||
{
|
{
|
||||||
my $mod = shift;
|
my $mod = shift;
|
||||||
@ -20,7 +37,10 @@ sub parse($$)
|
|||||||
|
|
||||||
my $parser = XML::SAX::ParserFactory->parser( Handler => $sax_handler );
|
my $parser = XML::SAX::ParserFactory->parser( Handler => $sax_handler );
|
||||||
|
|
||||||
$parser->parse_string(shift);
|
my $str = shift;
|
||||||
|
|
||||||
|
print $str;
|
||||||
|
$parser->parse_string($str);
|
||||||
|
|
||||||
return $parsed;
|
return $parsed;
|
||||||
}
|
}
|
||||||
@ -32,7 +52,7 @@ sub get($$)
|
|||||||
my $ua = LWP::UserAgent->new;
|
my $ua = LWP::UserAgent->new;
|
||||||
my $req = GET 'https://lerdorf.acu.epita.fr/intra/api/' . $url;
|
my $req = GET 'https://lerdorf.acu.epita.fr/intra/api/' . $url;
|
||||||
|
|
||||||
return parse($next, $ua->request($req)->as_string);
|
return parse($next, $ua->request($req)->content);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub send($$@)
|
sub send($$@)
|
||||||
@ -42,7 +62,7 @@ sub send($$@)
|
|||||||
my $ua = LWP::UserAgent->new;
|
my $ua = LWP::UserAgent->new;
|
||||||
my $req = POST 'https://lerdorf.acu.epita.fr/intra/api/' . $url, @_;
|
my $req = POST 'https://lerdorf.acu.epita.fr/intra/api/' . $url, @_;
|
||||||
|
|
||||||
return parse($next, $ua->request($req)->as_string);
|
return parse($next, $ua->request($req)->content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user