| 1 | package WebService::Mattermost::V4::API::Resource::Posts; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Wrapped API methods for the posts API endpoints. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 12 | extends 'WebService::Mattermost::V4::API::Resource'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 12 | with 'WebService::Mattermost::V4::API::Resource::Role::View::Post'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | ################################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | sub create { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | my $args = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | $args->{message} = $self->_stringify_message($args->{message}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | return $self->_post({ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | parameters => $args, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | required => [ qw(channel_id message) ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | sub create_ephemeral { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_ephemeral: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my $args = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | unless ($self->_validate_minimum_post_args($args->{post})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | return $self->error_return('The "post" argument must contain message and channel_id keys'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | $args->{post}->{message} = $self->_stringify_message($args->{post}->{message}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | return $self->_post({ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | endpoint => 'ephemeral', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | parameters => $args, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | required => [ qw(user_id post) ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ################################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | sub _stringify_message { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stringify_message: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | my $message = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # This catch is in place to ensure a message of 1 or 0 are not interpreted | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # as a boolean value, and are instead sent as a string | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | ▶ | $message .= '' if $message && $message =~ /^\d+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$message and $message =~ /^\d+$/
MC/DC0%0/2
$message and $message =~ /^\d+$/
$message
$message =~ /^\d+$/
Truth table33%1/3
A and B
A= $messageB= $message =~ /^\d+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | return $message; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | sub _validate_minimum_post_args { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_minimum_post_args: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my $post = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | return ref $post | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | && ref $post eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | && $post->{channel_id} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | && $post->{message}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
ref $post && ref $post eq 'HASH' && $post->{'channel_id'} && $post->{'message'}
ref $post and ref $post eq "HASH" and $post->{"channel_id"}
ref $post and ref $post eq "HASH"
MC/DC0%0/4
ref $post && ref $post eq 'HASH' && $post->{'channel_id'} && $post->{'message'}
ref $post
ref $post eq "HASH"
$post->{"channel_id"}
$post->{'message'}
Truth table0%0/5
A and B and C && D
A= ref $postB= ref $post eq "HASH"C= $post->{"channel_id"}D= $post->{'message'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | ################################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | WebService::Mattermost::V4::API::Resource::Posts - Wrapped API methods for the posts API endpoints. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | version 0.28 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | =head2 USAGE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | use WebService::Mattermost; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | my $mm = WebService::Mattermost->new({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | authenticate => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | username => 'email@address.com', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | password => 'passwordhere', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | base_url => 'https://my.mattermost.server.com/api/v4/', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | my $resource = $mm->api->posts; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | =head2 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | =item C<create()> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | L<Create a post|https://api.mattermost.com/#tag/posts%2Fpaths%2F~1posts%2Fpost> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | my $response = $resource->create({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # Required parameters: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | message => '...', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | channel_id => 'CHANNEL-ID-HERE', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # Optional parameters: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | root_id => 'PARENT-POST-ID-HERE', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | file_ids => [ '...' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | props => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | =item C<create_ephemeral()> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | L<Create a ephemeral post|https://api.mattermost.com/#tag/posts%2Fpaths%2F~1posts~1ephemeral%2Fpost> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | my $response = $resource->create_ephemeral({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # Required parameters: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | user_id => 'USER-ID-HERE', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | post => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | channel_id => '...', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | message => '...', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | =item L<https://api.mattermost.com/#tag/posts> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | Official "posts" API documentation. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | Mike Jones <mike@netsplit.org.uk> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | This software is Copyright (c) 2020 by Mike Jones. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | The MIT (X11) License | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||