As discussed in 13 PR.
The idea is to add a Response class:
I think that storing the response in the Net::FreeIPA is something unnecesary, and the LWP::UserAgent aproach will be better. i.e.: the LWP::UserAgent performs requests that return a HTTP::Response object.
Code example:
my $ua = LWP::UserAgent->new;
my $response = $ua->get('http://search.cpan.org/');
if ($response->is_success) {
print $response->decoded_content; # or whatever
} else {
die $response->status_line;
}
I think that all the api calls would return a Net::FreeIPA::Response object (the get or post method and the HTTP::Response class would be an analogy of this). Net::FreeIPA::Error will be a subclass of Net::FreeIPA::Response.
The client would use the api in the following way:
my $fi = Net::FreeIPA->new("host.example.com");
die("Failed to initialise the rest client") if ! $fi->{rc};
my $response = $fi->api_user_find("");
# If the `Net::FreeIPA::Response overloads the bool operator
if($reponse){
# if it doesnot overload it
# if($response->is_success){ # or if(not($response->is_error){
# More helper methods could be implemented, like $response->result_len or things that
# will make easier for the client to work with the response
print "Found ", scalar @{$response->result}, " users\n";
} else{
print "Error , $response;
}
The Request class is done to provide batch support (#7)
@NickCis this is now implemented, rpc takes request instance and returns response instance. the last rpc response is still store in an attribute, but that is purely for convenience, it's not used anymore.
As discussed in 13 PR. The idea is to add a
Response
class:I think that storing the response in the
Net::FreeIPA
is something unnecesary, and theLWP::UserAgent
aproach will be better. i.e.: theLWP::UserAgent
performs requests that return aHTTP::Response
object.Code example:
I think that all the api calls would return a
Net::FreeIPA::Response
object (theget
orpost
method and theHTTP::Response
class would be an analogy of this).Net::FreeIPA::Error
will be a subclass ofNet::FreeIPA::Response
.The client would use the api in the following way:
The
Request
class is done to provide batch support (#7)