| 1 | package Plagger::Plugin::CustomFeed::GitHub; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use base qw(Plagger::Plugin); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | our $VERSION = "0.01"; | |||||||||
| 9 | |||||||||||
| 10 | 0 | ▶ | sub register { | ||||||||
|
Subroutine
register: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 11 | 0 | my ( $self, $context ) = @_; | |||||||||
| 12 | |||||||||||
| 13 | 0 | $context->register_hook( $self, 'subscription.load' => $self->can('load'), ); | |||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | sub load { | ||||||||
|
Subroutine
load: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 17 | 0 | my ( $self, $context, $args ) = @_; | |||||||||
| 18 | |||||||||||
| 19 | 0 | my $feed = Plagger::Feed->new; | |||||||||
| 20 | 0 | ▶ | $feed->aggregator( sub { $self->aggregate(@_) } ); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 21 | 0 | $context->subscription->add($feed); | |||||||||
| 22 | |||||||||||
| 23 | 0 | return; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 0 | ▶ | sub aggregate { | ||||||||
|
Subroutine
aggregate: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||
| 27 | 0 | my ( $self, $context, $args ) = @_; | |||||||||
| 28 | |||||||||||
| 29 | 0 | ▶ | my $token = $self->conf->{token} or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 0 | ▶ | my $users = $self->conf->{users} or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | ▶ | $users = [$users] unless ref $users; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | |||||||||||
| 33 | 0 | my $ua = LWP::UserAgent->new; | |||||||||
| 34 | 0 | my $header = HTTP::Headers->new( | |||||||||
| 35 | "Authorization" => "token $token", | ||||||||||
| 36 | "Accept" => "application/atom+xml" | ||||||||||
| 37 | ); | ||||||||||
| 38 | 0 | for my $user (@$users) { | |||||||||
| 39 | 0 | my $url = "https://github.com/$user"; | |||||||||
| 40 | 0 | my $req = HTTP::Request->new( 'GET', $url, $header ); | |||||||||
| 41 | |||||||||||
| 42 | 0 | $context->log( debug => "Fetch feed from $url" ); | |||||||||
| 43 | |||||||||||
| 44 | 0 | my $res = $ua->request($req); | |||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | unless ( $res->is_success ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | $context->log( error => "GitHub API failed: " . $res->status_line ); | |||||||||
| 48 | 0 | next; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 0 | my $content = HTML::Entities::decode( $res->content ); | |||||||||
| 52 | |||||||||||
| 53 | 0 | Plagger::Plugin::Aggregator::Simple->handle_feed( $url, \$content ); | |||||||||
| 54 | } | ||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 1 | 1; | |||||||||
| 58 | |||||||||||
| 59 | __END__ | ||||||||||