Gustavo Leite de Mendonça Chaves > Gerrit-REST-0.007 > Gerrit::REST

Download:
Gerrit-REST-0.007.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.007   Source   Latest Release: Gerrit-REST-0.011

NAME ^

Gerrit::REST - A thin wrapper around Gerrit's REST API

VERSION ^

version 0.007

SYNOPSIS ^

    use Gerrit::REST;

    my $gerrit = Gerrit::REST->new('https://review.example.net', 'myuser', 'mypass');

    # Get a specific project description
    my $project = $gerrit->GET('/projects/myproject');
    print "Name: $project->{name}\n";
    print "Description: $project->{description}\n";

    # Create a new group belonging to the Administrators group
    my $admin_group = $gerrit->GET('/groups/Administrators');
    my $newgroup = $gerrit->PUT('/groups/newgroup', {
        description    => 'New group description.',
        visible_to_all => 'true',
        owner          => $admin_group->{name},
        owner_id       => $admin_group->{group_id},
    });

    # Add an account to the new group
    my $account = $gerrit->GET('/accounts/someuser');
    $gerrit->PUT("/groups/$newgroup->{id}/members/$account->{name}");

    # Review change-id #100, patch-set 3
    $gerrit->POST("/changes/100/revisions/3/review", {
        message => 'Some nits need to be fixed.',
        labels  => {'Code-Review' => -1},
    });

DESCRIPTION ^

"Gerrit is a web based code review system, facilitating online code reviews for projects using the Git version control system."

This module is a thin wrapper around Gerrit's REST API, which is superseding it's old SSH API, for which there is another Perl module called Gerrit::Client.

CONSTRUCTOR ^

new URL, USERNAME, PASSWORD [, REST_CLIENT_CONFIG]

The constructor needs up to four arguments:

METHODS ^

Gerrit's REST API documentation lists dozens of "endpoints" which can be operated via the standard HTTP requests: GET, DELETE, PUT, and POST. Gerrit::REST objects implement four methods called GET, DELETE, PUT, and POST to make it easier to invoke and get results from Gerrit's REST endpoints.

All four methods need a RESOURCE argument which is simply a string denoting the endpoint URL's path, as indicated in the documentation.

PUT and POST need a second argument which is the VALUE that's a Perl data structure (usually a hash-ref, but sometimes a simple string) which is encoded using the encode method of a JSON object and passed as contents of the underlying associated HTTP method.

All four methods return the value returned by the associated endpoint's method, as specified in the documentation, decoded according to its content type as follows:

Some endpoints don't return anything. In those cases, the methods return undef. The methods croak if they get any other type of values in return.

In case of errors (i.e., if the underlying HTTP method return an error code different from 2xx) the methods croak with a multi-line string like this:

    Code: <CODE>
    Content-Type: <CONTENT-TYPE>

    <CONTENT>

So, in order to treat errors you must invoke the methods in an eval block or use any of the exception handling Perl modules, such as Try::Tiny and Try::Catch.

GET RESOURCE

Returns the RESOURCE as a Perl data structure.

DELETE RESOURCE

Deletes the RESOURCE.

PUT RESOURCE, VALUE

Creates RESOURCE based on VALUE.

POST RESOURCE, VALUE

Updates RESOURCE based on VALUE.

SEE ALSO ^

AUTHOR ^

Gustavo L. de M. Chaves <gnustavo@cpan.org>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2013 by CPqD <www.cpqd.com.br>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: