Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions lib/Net/GitHub/Upload.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ has download_scraper => (
date => '@title';
process '//p/strong',
size => 'TEXT';
process '//li/a',
id => '@href';
};

my $downloads = scraper {
Expand Down Expand Up @@ -103,6 +105,7 @@ sub upload {
);
die qq[Failed to post file info: "@{[ $res->status_line ]}"]
unless $res->is_success;
#" make vim happy

my $upload_info = decode_json $res->content;

Expand Down Expand Up @@ -138,6 +141,43 @@ sub upload {
}
}

sub delete {
my $self = shift;
my $info = @_ > 1 ? {@_} : $_[0];

die "required repository name" unless $info->{repos};
$info->{repos} = $self->login . '/' . $info->{repos} unless $info->{repos} =~ m!/!;

die qq[required 'name' or 'fileinfo' parameter to delete]
unless $info->{name} or $info->{fileinfo};

my $idpath = do {
if ($info->{fileinfo}) {
$info->{fileinfo}->{id}
} else {
my @ids = grep { $_->{name} eq $info->{name} } @{ $self->list_files( $info->{repos} ) || []};
die qq[Multiple downloads matching "$info->{name}" found] if @ids > 1;
die qq[No download matching "$info->{name}" found] unless @ids;
${ids[0]}->{id}
}
};

$idpath =~ s!^/!!;

my $res = $self->ua->request(
POST "https://github.com/$idpath",
[ _method => "delete",
login => $self->login,
token => $self->token,
],
);
die qq[Failed to post file info: "@{[ $res->status_line ]}"]
unless $res->is_success || $res->is_redirect;
#" happy vim

return 1;
}

sub list_files {
my ($self, $repos) = @_;

Expand Down Expand Up @@ -186,6 +226,13 @@ $github->upload(
data => $data,
);


# delete a previously uploaded file
$github->delete(
repos => 'username/repository',
name => 'filename',
);

=head1 DESCRIPTION

Stub documentation for this module was created by ExtUtils::ModuleMaker.
Expand Down