| 1 | package WebService::Mattermost::V4::API::Request; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: A request to be sent to the Mattermost API. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use Mojo::URL; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use Mojo::Util 'url_escape'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use Types::Standard qw(Any ArrayRef Bool Enum InstanceOf Str); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 12 | with 'WebService::Mattermost::Role::Logger'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | ################################################################################ | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 12 | has base_url => (is => 'ro', isa => Str, required => 1); | |||||||||||||||||||||||||||
| 15 | 12 | has endpoint => (is => 'ro', isa => Str, required => 1); | |||||||||||||||||||||||||||
| 16 | 12 | has method => (is => 'ro', isa => Enum [ qw(DELETE GET POST PUT) ], required => 1); | |||||||||||||||||||||||||||
| 17 | 12 | has resource => (is => 'ro', isa => Str, required => 1); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # Some endpoints require parameters as a HashRef, some as an ArrayRef | ||||||||||||||||||||||||||||
| 20 | 12 | has debug => (is => 'ro', isa => Bool, default => 0); | |||||||||||||||||||||||||||
| 21 | 10 | ▶ | has ids => (is => 'ro', isa => ArrayRef, default => sub { [] }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | has parameters => (is => 'ro', isa => Any, default => sub { {} }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 12 | has url => (is => 'ro', isa => InstanceOf['Mojo::URL'], lazy => 1, builder => 1); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | ################################################################################ | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | sub _build_url { | ||||||||||||||||||||||||||||
| 29 | 16 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_url: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 16 | my $base_url = $self->base_url; | |||||||||||||||||||||||||||
| 32 | 16 | my $resource = $self->resource; | |||||||||||||||||||||||||||
| 33 | 16 | my $endpoint = $self->endpoint; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 16 | ▶ | $base_url .= '/' if $base_url !~ /\/$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 16 | ▶ | $resource .= '/' if $self->endpoint ne '' && $resource !~ /\/$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->endpoint ne "" and not $resource =~ m[/$]
MC/DC50%1/2
$self->endpoint ne "" and not $resource =~ m[/$]
$self->endpoint ne ""
not $resource =~ m[/$]
Truth table66%2/3
A and not(B)
A= $self->endpoint ne ""B= not $resource =~ m[/$]
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 16 | my @ids = map { url_escape($_) } @{$self->ids}; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 16 | $endpoint = sprintf($endpoint, @ids); | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 16 | my $url = sprintf('%s%s%s', $base_url, $resource, $endpoint); | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 16 | ▶ | $self->logger->debug($url) if $self->debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 16 | return Mojo::URL->new($url); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | ################################################################################ | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 12 | 1; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | __END__ | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =pod | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =head1 NAME | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | WebService::Mattermost::V4::API::Request - A request to be sent to the Mattermost API. | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =head1 VERSION | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | version 0.28 | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | A request to be sent to the Mattermost API. | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =head2 USAGE | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | See L<WebService::Mattermost::V4::API::Resource::_call()>. | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =head2 ATTRIBUTES | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =over 4 | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =item C<base_url> | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =item C<endpoint> | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =item C<method> | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | HTTP method. | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =item C<resource> | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | The API endpoint's namespace. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =item C<parameters> | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | Data to be sent to the API. | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =item C<ids> | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | IDs to replace into the URL with C<sprintf>. | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =item C<url> | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =back | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | Mike Jones <mike@netsplit.org.uk> | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | This software is Copyright (c) 2020 by Mike Jones. | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | This is free software, licensed under: | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | The MIT (X11) License | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =cut | ||||||||||||||||||||||||||||