GitLab-API-v3

 view release on metacpan or  search on metacpan

lib/GitLab/API/v3.pm  view on Meta::CPAN

as a strict representation of GitLab's own documentation which
is often inconsistent.

If you find a method that should provide a return value, but
doesn't currently, please verify that GitLab actually does
return a value and then submit a pull request or open an issue.
See L</CONTRIBUTING> for more info.

=cut

use GitLab::API::v3::RESTClient;
use GitLab::API::v3::Paginator;

use Types::Standard -types;
use Types::Common::String -types;
use URI::Escape;
use Carp qw( croak );
use Log::Any qw( $log );

use Moo;
use strictures 1;
use namespace::clean;

around BUILDARGS => sub{
    my $orig = shift;
    my $class = shift;

    my $args = $class->$orig( @_ );

    my $session_args = {};
    foreach my $key (qw( login email password )) {
        next if !exists $args->{$key};
        $session_args->{$key} = delete $args->{$key};
    }

    if (%$session_args) {
        my $api = $class->new( $args );
        my $session = $api->session( $session_args );
        $args->{token} = $session->{private_token};
    }

    return $args;
};

sub BUILD {
    my ($self) = @_;

    $log->debugf( "An instance of %s has been created.", ref($self) );

    $self->rest_client->set_persistent_header(
        'PRIVATE-TOKEN' => $self->token(),
    ) if $self->has_token();

    return;
}

=head1 REQUIRED ARGUMENTS

=head2 url

The URL to your v3 API endpoint.  Typically this will be something
like C<http://git.example.com/api/v3>.

=cut

has url => (
    is       => 'ro',
    isa      => NonEmptySimpleStr,
    required => 1,
);

=head1 OPTIONAL ARGUMENTS

=head2 token

A GitLab API token.
If set then neither L</login> or L</email> may be set.
Read more in L</CREDENTIALS>.

=cut

has token => (
    is        => 'ro',
    isa       => NonEmptySimpleStr,
    predicate => 'has_token',
);

=head2 login

A GitLab user login name.
If set then L</password> must be set.
Read more in L</CREDENTIALS>.

=head2 email

A GitLab user email.
If set then L</password> must be set.
Read more in L</CREDENTIALS>.

=head2 password

A GitLab user password.
This must be set if either L</login> or L</email> are set.
Read more in L</CREDENTIALS>.

=cut

# The above three args are virtual and get stripped out in BUILDARGS.

=head2 rest_client

An instance of L<GitLab::API::v3::RESTClient>.  Typically you will not
be setting this as it defaults to a new instance and customization
should not be necessary.

=cut

has rest_client => (
    is      => 'lazy',
    isa     => InstanceOf[ 'GitLab::API::v3::RESTClient' ],
    handles => [qw( post get head put delete options )],



( run in 1.812 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )