The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Pithub::Base

VERSION

version 0.01000

All "MODULES" in Pithub inherit from Pithub::Base, even Pithub itself. So all attributes listed here can either be set in the constructor or via the setter on the objects.

ATTRIBUTES

api_uri

Defaults to https://api.github.com.

Examples:

    $users = Pithub::Users->new( api_uri => 'https://api-foo.github.com' );

    $users = Pithub::Users->new;
    $users->api_uri('https://api-foo.github.com');

repo

This can be set as a default repo to use for API calls that require the repo parameter to be set.

Examples:

    $c = Pithub::Repos::Collaborators->new( repo => 'Pithub' );
    $result = $c->list( user => 'plu' );

There are two helper methods:

  • clear_repo: reset the repo attribute

  • has_repo: check if the repo attribute is set

skip_request

Mainly used by tests. But it might be useful to build another library on top of Pithub.

Examples:

    $c = Pithub::Repos::Collaborators->new( skip_request => 1 );

    # This will not make any request at all!
    $result = $c->list( user => 'plu' );

    # This will return the HTTP::Request object that has been created
    # for this particular API call
    $http_request = $c->request->http_request;

token

If the OAuth token is set, Pithub will sent it via an HTTP header on each API request. Currently the basic authentication method is not supported.

See also: http://developer.github.com/v3/oauth/

ua

By default a LWP::UserAgent object, but it can be anything that implements the same interface.

user

This can be set as a default user to use for API calls that require the user parameter to be set.

Examples:

    $c = Pithub::Repos::Collaborators->new( user => 'plu' );
    $result = $c->list( repo => 'Pithub' );

There are two helper methods:

  • clear_user: reset the user attribute

  • has_user: check if the user attribute is set

It might makes sense to use this together with the repo attribute:

    $c = Pithub::Repos::Commits->new( user => 'plu', repo => 'Pithub' );
    $result = $c->list;
    $result = $c->list_comments;
    $reuslt = $c->get('6b6127383666e8ecb41ec20a669e4f0552772363');

METHODS

request

This method is the central point: All Pithub are using this method for making requests to the Github. If Github adds a new API call that is not yet supported, this method can be used directly. It accepts following parameters:

  • $method: mandatory string, one of the following:

    • DELETE

    • GET

    • PATCH

    • POST

    • PUT

  • $path: mandatory string of the relative path used for making the API call.

  • $data: optional data reference, usually a reference to an array or hash. It must be possible to serialize this using JSON::Any. This will be the HTTP request body.

  • $options: optional hash reference to set additional options on the request. So far only prepare_uri is supported. See more about that in the examples below.

Usually you should not end up using this method at all. It's only available if Pithub is missing anything from the Github v3 API. Though here are some examples how to use it:

  • Same as "get" in Pithub::Users:

        $p = Pithub->new;
        $result = $p->request( GET => '/users/plu' );

    Same as "create" in Pithub::Gists:

        $p      = Pithub->new;
        $method = 'POST';
        $path   = '/gists';
        $data   = {
            description => 'the description for this gist',
            public      => 1,
            files       => { 'file1.txt' => { content => 'String file content' } }
        };
        $result = $p->request( $method, $path, $data );

    Same as "get" in Pithub::GitData::Trees:

        $p       = Pithub->new;
        $method  = 'GET';
        $path    = '/repos/plu/Pithub/git/trees/aac667c5aaa6e49572894e8c722d0705bb00fab2';
        $data    = undef;
        $options = {
            prepare_uri => sub {
                my ($uri) = @_;
                $uri->query_form( recursive => 1 );
            },
        };
        $result = $p->request( $method, $path, $data, $options );

    This method always returns a Pithub::Result object.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 342:

'=item' outside of any '=over'

=over without closing =back