1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
|
package Net::GitHub::V3;
use Moo;
use Types::Standard qw(InstanceOf);
our $VERSION = '1.05';
our $AUTHORITY = 'cpan:FAYLAND';
with 'Net::GitHub::V3::Query';
use Net::GitHub::V3::Users;
use Net::GitHub::V3::Repos;
use Net::GitHub::V3::Issues;
use Net::GitHub::V3::PullRequests;
use Net::GitHub::V3::Orgs;
use Net::GitHub::V3::GitData;
use Net::GitHub::V3::Gists;
use Net::GitHub::V3::OAuth;
use Net::GitHub::V3::Events;
use Net::GitHub::V3::Gitignore;
use Net::GitHub::V3::Search;
use Net::GitHub::V3::Actions;
has '+is_main_module' => (default => 1);
has 'user' => (
is => 'rw',
isa => InstanceOf['Net::GitHub::V3::Users'],
lazy => 1,
default => sub {
my $self = shift;
return Net::GitHub::V3::Users->new( $self->args_to_pass );
},
);
has 'org' => (
is => 'rw',
isa => InstanceOf['Net::GitHub::V3::Orgs'],
lazy => 1,
default => sub {
my $self = shift;
return Net::GitHub::V3::Orgs->new( $self->args_to_pass );
},
);
has 'gist' => (
is => 'rw',
isa => InstanceOf['Net::GitHub::V3::Gists'],
lazy => 1,
default => sub {
my $self = shift;
return Net::GitHub::V3::Gists->new( $self->args_to_pass );
},
);
has 'repos' => (
is => 'rw',
isa => InstanceOf['Net::GitHub::V3::Repos'],
lazy => 1,
predicate => 'is_repos_init',
default => sub {
my $self = shift;
return Net::GitHub::V3::Repos->new( $self->args_to_pass );
},
);
has 'issue' => (
is => 'rw',
isa => InstanceOf['Net::GitHub::V3::Issues'],
lazy => 1,
predicate => 'is_issue_init',
default => sub {
my $self = shift;
return Net::GitHub::V3::Issues->new( $self->args_to_pass );
},
);
has 'pull_request' => (
is => 'rw',
isa => InstanceOf['Net::GitHub::V3::PullRequests'],
lazy => 1,
predicate => 'is_pull_request_init',
default => sub {
my $self = shift;
return Net::GitHub::V3::PullRequests->new( $self->args_to_pass );
},
);
has 'git_data' => (
is => 'rw',
isa => InstanceOf['Net::GitHub::V3::GitData'],
lazy => 1,
predicate => 'is_git_data_init',
default => sub {
my $self = shift;
return Net::GitHub::V3::GitData->new( $self->args_to_pass );
},
);
has 'oauth' => (
is => 'rw',
isa => InstanceOf['Net::GitHub::V3::OAuth'],
lazy => 1,
default => sub {
my $self = shift;
return Net::GitHub::V3::OAuth->new( $self->args_to_pass );
},
);
has 'event' => (
is => 'rw',
isa => InstanceOf['Net::GitHub::V3::Events'],
lazy => 1,
default => sub {
my $self = shift;
return Net::GitHub::V3::Events->new( $self->args_to_pass );
},
);
has 'search' => (
is => 'rw',
isa => InstanceOf['Net::GitHub::V3::Search'],
lazy => 1,
default => sub {
my $self = shift;
return Net::GitHub::V3::Search->new( $self->args_to_pass );
},
);
has 'gitignore' => (
is => 'rw',
isa => InstanceOf['Net::GitHub::V3::Gitignore'],
lazy => 1,
default => sub {
my $self = shift;
return Net::GitHub::V3::Gitignore->new( $self->args_to_pass );
},
);
has 'actions' => (
is => 'rw',
isa => InstanceOf['Net::GitHub::V3::Actions'],
lazy => 1,
default => sub {
my $self = shift;
return Net::GitHub::V3::Actions->new( $self->args_to_pass );
},
);
no Moo;
1;
__END__
=head1 NAME
Net::GitHub::V3 - Github API v3
=head1 SYNOPSIS
Prefer:
use Net::GitHub;
my $gh = Net::GitHub->new(
version => 3,
login => 'fayland', pass => 'mypass',
# or
# access_token => $oauth_token
);
Or:
use Net::GitHub::V3;
my $gh = Net::GitHub::V3->new(
login => 'fayland', pass => 'mypass',
# or
# access_token => $oauth_token
);
=head1 DESCRIPTION
L<http://developer.github.com/v3/>
=head2 ATTRIBUTES
=head3 Authentication
There are two ways to authenticate through GitHub API v3:
=over 4
=item login/pass
my $gh = Net::GitHub::V3->new( login => $ENV{GITHUB_USER}, pass => $ENV{GITHUB_PASS} );
=item access_token
my $gh = Net::GitHub->new( access_token => $ENV{GITHUB_ACCESS_TOKEN} );
=back
=head3 raw_response
my $gh = Net::GitHub->new(
# login/pass or access_token
raw_response => 1
);
return raw L<HTTP::Response> object
=head3 raw_string
my $gh = Net::GitHub->new(
# login/pass or access_token
raw_string => 1
);
return L<HTTP::Response> response content as string
=head3 api_throttle
my $gh = Net::GitHub->new(
# login/pass or access_token
api_throttle => 0
);
To disable call rate limiting (e.g. if your account is whitelisted), set B<api_throttle> to 0.
=head3 RaiseError
By default, error responses are propagated to the user as they are received
from the API. By switching B<RaiseError> on you can make the be turned into
exceptions instead, so that you don't have to check for error response after
every call.
=head3 Iterating over pages: next_url, last_url, prev_url, first_url, per_page
Any methods which return multiple results I<may> be paginated. After performing
a query you should check to see if there are more results. These attributes will
be reset for each query.
The predicates to check these attributes are C<has_next_page>, C<has_last_page>,
C<has_prev_page> and C<has_first_page>.
C<per_page> defaults to 100. It will be applied to GET urls no matter it supports or not.
See Github's documentation: L<http://developer.github.com/v3/#pagination>
my @issues = $gh->issue->repos_issues;
while ($gh->issue->has_next_page) {
push @issues, $gh->issue->query($gh->issue->next_url);
## OR ##
push @issues, $gh->issue->next_page;
}
=head3 Iterating over individual items: next_xxx and close_xxx
The queries which can return paginated results can also be evaluated one by
one, like this:
while (my $issue = $gh->issue->next_repos_issue( @args )) {
# do something with $issue
}
The arguments to next_repos_issue are the same as for repos_issues,
and is also applicable to all other interfaces which offer a next_xxx
method. All available next_xxx methods are listed in the
documentation of the corresponding modules, see the list below.
If you loop over the next_xxx interfaces, new API calls will be
performed automatically, but only when needed to fetch more items. An
undefined return value means there are no more items.
To start over with the first item, you need to close the iteration.
Every next_xxx method has a corresponding close_xxx method which must
be called with exactly the same parameters as the next_xxx method to
take effect:
$gh->issue->close_repos_issue(@args);
If you use Net::GitHub::V3 in a command line program, there is no need
to call the close_xxx methods at all. As soon as the Net::GitHub::V3
object $gh goes out of scope, everything is neatly cleaned up.
However, if you have a long-lived Net::GitHub::V3 object, e.g. in a
persistent service process which provides an own interface to its
users and talks to GitHub under the hood, then it is advisable to
close the iterations when you're done with them.
For brevity and because they usually are not needed, the close_xxx
methods are not listed with their modules. It is guaranteed that
I<every> next_xxx method has a corresponding close_xxx method.
=head3 Alternate iterator over individual items:
If next_xxx and close_xxx methods are not available for your pagination
method you can use a generic iterator using the C<iterate> helper.
$gh->issues->iterate( 'repos_issues', [ @args ], sub {
my $issue = shift;
... # do something with $issue
return 1; # if you want to continue iterating
return; # when you want to interrupt the iteration process
} );
=head3 ua
To set the proxy for ua, you can do something like following
$gh->ua->proxy('https', 'socks://127.0.0.1:9050');
$gh->ua is an instance of L<LWP::UserAgent>
=head2 METHODS
=head3 query($method, $url, $data)
my $data = $gh->query('/user');
$gh->query('PATCH', '/user', $data);
$gh->query('DELETE', '/user/emails', [ 'myemail@somewhere.com' ]);
query API directly
=head3 next_page
When the results have been paginated, C<next_page> is sugar for the common case
of iterating through all the pages in order. It simply calls C<query> with the C<next_url>.
=head3 set_default_user_repo
$gh->set_default_user_repo('fayland', 'perl-net-github'); # take effects for all $gh->
$gh->repos->set_default_user_repo('fayland', 'perl-net-github'); # take effects on $gh->repos
B<To ease the keyboard, we provided two ways to call any method which starts with :user/:repo>
1. SET user/repos before call methods below
$gh->set_default_user_repo('fayland', 'perl-net-github');
my @contributors = $gh->repos->contributors;
2. If it is just for once, we can pass :user, :repo before any arguments
my @contributors = $repos->contributors($user, $repo);
=head2 MODULES
=head3 user
my $user = $gh->user->show('nothingmuch');
$gh->user->update( bio => 'Just Another Perl Programmer' );
L<Net::GitHub::V3::Users>
=head3 repos
my @repos = $gh->repos->list;
my $rp = $gh->repos->create( {
"name" => "Hello-World",
"description" => "This is your first repo",
"homepage" => "https://github.com"
} );
L<Net::GitHub::V3::Repos>
=head3 issue
my @issues = $gh->issue->issues();
my $issue = $gh->issue->issue($issue_number);
L<Net::GitHub::V3::Issues>
=head3 pull_request
my @pulls = $gh->pull_request->pulls();
L<Net::GitHub::V3::PullRequests>
=head3 org
my @orgs = $gh->org->orgs;
L<Net::GitHub::V3::Orgs>
=head3 git_data
L<Net::GitHub::V3::GitData>
=head3 gist
L<Net::GitHub::V3::Gists>
=head3 oauth
L<Net::GitHub::V3::OAuth>
=head3 event
L<Net::GitHub::V3::Events>
=head3 search
L<Net::GitHub::V3::Search>
=head1 SEE ALSO
L<Pithub>
=head1 AUTHOR & COPYRIGHT & LICENSE
Refer L<Net::GitHub>
|