Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Request / Response types #18

Open
NickCis opened this issue Apr 8, 2016 · 1 comment
Open

Add Request / Response types #18

NickCis opened this issue Apr 8, 2016 · 1 comment

Comments

@NickCis
Copy link
Collaborator

NickCis commented Apr 8, 2016

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 added a commit that referenced this issue Apr 8, 2016
@stdweird
Copy link
Owner

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants