AnyEvent-JSONRPC

 view release on metacpan or  search on metacpan

lib/AnyEvent/JSONRPC/HTTP/Client.pm  view on Meta::CPAN

    isa     => enum( [qw( 1.0 1.1 2.0 )] ),
    default => "2.0",
);

has username => (
    is => "rw",
    isa => 'Str',
    predicate => "has_username"
);

has password => (
    is => "rw",
    isa => "Str"
);

has _request_pool => (
    is      => 'ro',
    isa     => 'HashRef',
    lazy    => 1,
    default => sub { {} },
);

lib/AnyEvent/JSONRPC/HTTP/Client.pm  view on Meta::CPAN

    $self->_request_pool->{ $request->id } = [ $guard, $cv ];

    return $cv;
}

sub _authorization_header {
    my $self = shift;

    return unless $self->has_username;

    return Authorization => "Basic " . encode_base64( $self->username . ":" . $self->password );
}

sub _handle_response {
    my ($self, $json, $header) = @_;

    unless ( $header->{Status} =~ /^2/) {
        warn qq/Invalid response from server: $header->{Status} $header->{Reason}/;
        return;
    }

lib/AnyEvent/JSONRPC/HTTP/Client.pm  view on Meta::CPAN


AnyEvent::JSONRPC::HTTP::Client - Simple HTTP-based JSONRPC client

=head1 SYNOPSIS

    use AnyEvent::JSONRPC::HTTP::Client;
    
    my $client = AnyEvent::JSONRPC::HTTP::Client->new(
        url      => 'http://rpc.example.net/issues',
        username => "pmakholm",
        password => "secret",
    );
    
    # blocking interface
    my $res = $client->call( echo => 'foo bar' )->recv; # => 'foo bar';
    
    # non-blocking interface
    $client->call( echo => 'foo bar' )->cb(sub {
        my $res = $_[0]->recv;  # => 'foo bar';
    });

lib/AnyEvent/JSONRPC/HTTP/Client.pm  view on Meta::CPAN


URL to json-RPC endpoint to connect. (Required)

=item username => 'Str'

Username to use for authorization (Optional).

If this is set an Authorization header containing basic auth credential is
always sent with request.

=item password => 'Str'

Password used for authorization (optional)

=back

=head2 call ($method, @params)

Call remote method named C<$method> with parameters C<@params>. And return condvar object for response.

    my $cv = $client->call( echo => 'Hello!' );



( run in 0.476 second using v1.01-cache-2.11-cpan-49f99fa48dc )