| 1 | package WebService::Pixela::Webhook; | ||||||||||||||||||||
| 2 | 6 | ▶ | use 5.010001; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 6 | ▶ | use Carp qw/croak/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 6 | ▶ | use JSON qw/decode_json/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 6 | our $VERSION = "0.021"; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 44 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 11 | 44 | my ($class,$pixela_client) = @_; | |||||||||||||||||||
| 12 | 44 | return bless +{ | |||||||||||||||||||
| 13 | client => $pixela_client, | ||||||||||||||||||||
| 14 | }, $class; | ||||||||||||||||||||
| 15 | } | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 22 | ▶ | sub client { | ||||||||||||||||||
|
Subroutine
client: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 19 | 22 | my $self = shift; | |||||||||||||||||||
| 20 | 22 | return $self->{client}; | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 16 | ▶ | sub hash { | ||||||||||||||||||
|
Subroutine
hash: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 24 | 16 | my $self = shift; | |||||||||||||||||||
| 25 | 16 | ▶ | if (@_){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 6 | $self->{hash} = shift; | |||||||||||||||||||
| 27 | 6 | return $self; | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | 10 | return $self->{hash}; | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 6 | ▶ | sub create { | ||||||||||||||||||
|
Subroutine
create: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||
| 33 | 6 | my ($self,%args) = @_; | |||||||||||||||||||
| 34 | 6 | my $params = {}; | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | #check graphID | ||||||||||||||||||||
| 37 | 6 | ▶ | $params->{graphID} = $args{graph_id} // $self->client->graph->id; | ||||||||||||||||||
|
Condition100%3/3
$args{"graph_id"} // $self->client->graph->id
MC/DC100%2/2
$args{"graph_id"} // $self->client->graph->id
$args{"graph_id"}
$self->client->graph->id
Truth table100%3/3
A // B
A= $args{"graph_id"}B= $self->client->graph->id
| |||||||||||||||||||||
| 38 | 6 | ▶ | croak 'require graph_id' unless $params->{graphID}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | #check type | ||||||||||||||||||||
| 41 | 5 | ▶ | croak 'require type' unless $args{type}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | map { | ||||||||||||||||||||
| 43 | 4 | ▶ | if( $args{type} =~ /^$_$/i){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 3 | $params->{type} = lc($args{type}); | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | } (qw/increment decrement/); | ||||||||||||||||||||
| 47 | 4 | ▶ | croak 'invalid type' unless $params->{type}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 3 | my $path = 'users/'.$self->client->username.'/webhooks'; | |||||||||||||||||||
| 50 | 3 | my $res = $self->client->request_with_xuser_in_header('POST',$path,$params); | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 3 | ▶ | my $res_json = $self->client->decode() ? $res : decode_json($res); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 3 | ▶ | if($res_json->{isSuccess}){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | 3 | $self->hash($res_json->{webhookHash}); | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 3 | return $res; | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 2 | ▶ | sub get { | ||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 62 | 2 | my $self = shift; | |||||||||||||||||||
| 63 | 2 | my $client = $self->client; | |||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 2 | my $path = 'users/'.$client->username.'/webhooks/'; | |||||||||||||||||||
| 66 | 2 | my $res = $client->request_with_xuser_in_header('GET',$path); | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 2 | ▶ | return $client->decode() ? $res->{webhooks} : $res; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 2 | ▶ | sub invoke { | ||||||||||||||||||
|
Subroutine
invoke: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||
| 72 | 2 | my ($self,$hash) = @_; | |||||||||||||||||||
| 73 | 2 | my $client = $self->client; | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 2 | ▶ | $hash //= $self->hash(); | ||||||||||||||||||
|
Condition66%2/3
$hash //= $self->hash
MC/DC0%0/2
$hash //= $self->hash
$hash
$self->hash
Truth table66%2/3
A //= B
A= $hashB= $self->hash
| |||||||||||||||||||||
| 76 | 2 | ▶ | croak 'require webhookHash' unless $hash; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 2 | my $path = 'users/'.$client->username.'/webhooks/'.$hash; | |||||||||||||||||||
| 79 | 2 | return $client->request_with_content_length_in_header('POST',$path,0); | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 4 | ▶ | sub delete { | ||||||||||||||||||
|
Subroutine
delete: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 83 | 4 | my ($self,$hash) = @_; | |||||||||||||||||||
| 84 | 4 | my $client = $self->client; | |||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 4 | ▶ | $hash //= $self->hash(); | ||||||||||||||||||
|
Condition100%3/3
$hash //= $self->hash
MC/DC100%2/2
$hash //= $self->hash
$hash
$self->hash
Truth table100%3/3
A //= B
A= $hashB= $self->hash
| |||||||||||||||||||||
| 87 | 4 | ▶ | croak 'require webhookHash' unless $hash; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 2 | my $path = 'users/'.$client->username.'/webhooks/'.$hash; | |||||||||||||||||||
| 90 | 2 | return $self->client->request_with_xuser_in_header('DELETE',$path); | |||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 6 | 1; | |||||||||||||||||||
| 95 | __END__ | ||||||||||||||||||||