| 1 | package Pithub::Repos::Downloads; | ||||||||||
| 2 | 16 | our $AUTHORITY = 'cpan:PLU'; | |||||||||
| 3 | 16 | our $VERSION = '0.01041'; | |||||||||
| 4 | |||||||||||
| 5 | # ABSTRACT: Github v3 Repo Downloads API | ||||||||||
| 6 | |||||||||||
| 7 | 16 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 16 | ▶ | use Carp qw( croak ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 16 | ▶ | use HTTP::Request::Common qw( POST ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 16 | extends 'Pithub::Base'; | |||||||||
| 11 | |||||||||||
| 12 | |||||||||||
| 13 | sub create { | ||||||||||
| 14 | 5 | ▶ | my ( $self, %args ) = @_; | ||||||||
|
Subroutine
create: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 15 | croak 'Missing key in parameters: data (hashref)' | ||||||||||
| 16 | 5 | ▶ | unless ref $args{data} eq 'HASH'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 4 | $self->_validate_user_repo_args( \%args ); | |||||||||
| 18 | return $self->request( | ||||||||||
| 19 | method => 'POST', | ||||||||||
| 20 | path => sprintf( | ||||||||||
| 21 | '/repos/%s/%s/downloads', delete $args{user}, delete $args{repo} | ||||||||||
| 22 | 4 | ), | |||||||||
| 23 | %args, | ||||||||||
| 24 | ); | ||||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | sub delete { | ||||||||||
| 29 | 4 | ▶ | my ( $self, %args ) = @_; | ||||||||
|
Subroutine
delete: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 30 | 4 | ▶ | croak 'Missing key in parameters: download_id' unless $args{download_id}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 3 | $self->_validate_user_repo_args( \%args ); | |||||||||
| 32 | return $self->request( | ||||||||||
| 33 | method => 'DELETE', | ||||||||||
| 34 | path => sprintf( | ||||||||||
| 35 | '/repos/%s/%s/downloads/%s', delete $args{user}, | ||||||||||
| 36 | delete $args{repo}, delete $args{download_id} | ||||||||||
| 37 | 3 | ), | |||||||||
| 38 | %args, | ||||||||||
| 39 | ); | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | |||||||||||
| 43 | sub get { | ||||||||||
| 44 | 3 | ▶ | my ( $self, %args ) = @_; | ||||||||
|
Subroutine
get: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 45 | 3 | ▶ | croak 'Missing key in parameters: download_id' unless $args{download_id}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 2 | $self->_validate_user_repo_args( \%args ); | |||||||||
| 47 | return $self->request( | ||||||||||
| 48 | method => 'GET', | ||||||||||
| 49 | path => sprintf( | ||||||||||
| 50 | '/repos/%s/%s/downloads/%s', delete $args{user}, | ||||||||||
| 51 | delete $args{repo}, delete $args{download_id} | ||||||||||
| 52 | 2 | ), | |||||||||
| 53 | %args, | ||||||||||
| 54 | ); | ||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | |||||||||||
| 58 | sub list { | ||||||||||
| 59 | 19 | ▶ | my ( $self, %args ) = @_; | ||||||||
|
Subroutine
list: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 60 | 19 | $self->_validate_user_repo_args( \%args ); | |||||||||
| 61 | return $self->request( | ||||||||||
| 62 | method => 'GET', | ||||||||||
| 63 | path => sprintf( | ||||||||||
| 64 | '/repos/%s/%s/downloads', delete $args{user}, delete $args{repo} | ||||||||||
| 65 | 13 | ), | |||||||||
| 66 | %args, | ||||||||||
| 67 | ); | ||||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | |||||||||||
| 71 | sub upload { | ||||||||||
| 72 | 4 | ▶ | my ( $self, %args ) = @_; | ||||||||
|
Subroutine
upload: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 73 | croak 'Missing key in parameters: result (Pithub::Result object)' | ||||||||||
| 74 | 4 | ▶ | unless ref $args{result} eq 'Pithub::Result'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 3 | ▶ | croak 'Missing key in parameters: file' unless $args{file}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 2 | my $result = $args{result}->content; | |||||||||
| 77 | 2 | foreach | |||||||||
| 78 | my $key (qw(path acl name accesskeyid policy signature mime_type)) { | ||||||||||
| 79 | 8 | ▶ | croak "Missing key in Pithub::Result content: ${key}" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | unless grep $_ eq $key, keys %$result; | ||||||||||
| 81 | } | ||||||||||
| 82 | my %data = ( | ||||||||||
| 83 | Content_Type => 'form-data', | ||||||||||
| 84 | Content => [ | ||||||||||
| 85 | 'key' => $result->{path}, | ||||||||||
| 86 | 'acl' => $result->{acl}, | ||||||||||
| 87 | 'success_action_status' => 201, | ||||||||||
| 88 | 'Filename' => $result->{name}, | ||||||||||
| 89 | 'AWSAccessKeyId' => $result->{accesskeyid}, | ||||||||||
| 90 | 'Policy' => $result->{policy}, | ||||||||||
| 91 | 'Signature' => $result->{signature}, | ||||||||||
| 92 | 'Content-Type' => $result->{mime_type}, | ||||||||||
| 93 | 1 | 'file' => [ $args{file} ], | |||||||||
| 94 | ], | ||||||||||
| 95 | ); | ||||||||||
| 96 | 1 | my $request = POST $result->{s3_url}, %data; | |||||||||
| 97 | 1 | return $self->ua->request($request); | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 16 | 1; | |||||||||
| 101 | |||||||||||
| 102 | __END__ | ||||||||||