| 1 | package WebService::Mattermost::V4::API::Resource::Channels; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Wrapped API methods for the channels 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 | |||||||||||||||||||||||||||||
| 9 | ################################################################################ | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub create { | ||||||||||||||||||||||||||||
| 12 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
create: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 0 | my $args = shift; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | $args->{type} = uc $args->{type} if $args->{type}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | # O for public, P for private | ||||||||||||||||||||||||||||
| 18 | 0 | ▶ | if (!$args->{type} || !grep { $_ eq $args->{type} } qw(O P)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args->{"type"} and grep {$_ eq $args->{"type"};} "O", "P"
MC/DC0%0/2
$args->{"type"} and grep {$_ eq $args->{"type"};} "O", "P"
$args->{"type"}
grep {$_ eq $args->{"type"};} "O", "P"
Truth table0%0/3
A and B
A= $args->{"type"}B= grep {$_ eq $args->{"type"};} "O", "P"
| |||||||||||||||||||||||||||||
| 19 | 0 | return $self->error_return('"type" must be O or P'); | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | return $self->_post({ | |||||||||||||||||||||||||||
| 23 | parameters => $args, | ||||||||||||||||||||||||||||
| 24 | required => [ qw(team_id name display_name type) ], | ||||||||||||||||||||||||||||
| 25 | }); | ||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | sub create_direct_channel { | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
create_direct_channel: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 0 | my $user_ids = shift; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if (scalar @{$user_ids} != 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | return $self->error_return('Two user IDs must be passed'); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | return $self->_post({ | |||||||||||||||||||||||||||
| 37 | endpoint => 'direct', | ||||||||||||||||||||||||||||
| 38 | parameters => $user_ids, | ||||||||||||||||||||||||||||
| 39 | }); | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | sub create_group_channel { | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
create_group_channel: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 0 | my $user_ids = shift; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if (scalar @{$user_ids} < 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | return $self->error_return('At least two user IDs must be passed'); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | return $self->_post({ | |||||||||||||||||||||||||||
| 51 | endpoint => 'group', | ||||||||||||||||||||||||||||
| 52 | parameters => $user_ids, | ||||||||||||||||||||||||||||
| 53 | }); | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | ################################################################################ | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 12 | 1; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =pod | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =head1 NAME | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | WebService::Mattermost::V4::API::Resource::Channels - Wrapped API methods for the channels API endpoints. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =head1 VERSION | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | version 0.28 | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =head2 USAGE | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | use WebService::Mattermost; | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | my $mm = WebService::Mattermost->new({ | ||||||||||||||||||||||||||||
| 81 | authenticate => 1, | ||||||||||||||||||||||||||||
| 82 | username => 'me@somewhere.com', | ||||||||||||||||||||||||||||
| 83 | password => 'hunter2', | ||||||||||||||||||||||||||||
| 84 | base_url => 'https://my.mattermost.server.com/api/v4/', | ||||||||||||||||||||||||||||
| 85 | }); | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | my $resource = $mm->api->channels; | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =head2 METHODS | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =over 4 | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =item C<create()> | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | L<Create a channel|https://api.mattermost.com/#tag/channels%2Fpaths%2F~1channels%2Fpost> | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | Create a public or private channel. | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | my $response = $resource->create({ | ||||||||||||||||||||||||||||
| 100 | # Required arguments | ||||||||||||||||||||||||||||
| 101 | type => 'P', # P for private, O for public | ||||||||||||||||||||||||||||
| 102 | team_id => '1234abcd', | ||||||||||||||||||||||||||||
| 103 | name => 'my-new-channel', | ||||||||||||||||||||||||||||
| 104 | display_name => 'MyNewChannel', | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | # Optional arguments | ||||||||||||||||||||||||||||
| 107 | purpose => 'A channel for testing', | ||||||||||||||||||||||||||||
| 108 | header => 'Channel topic', | ||||||||||||||||||||||||||||
| 109 | }); | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =item C<create_direct_channel()> | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | L<Create a direct message channel|https://api.mattermost.com/#tag/channels%2Fpaths%2F~1channels~1direct%2Fpost> | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | Create a direct message channel between two users. Two user IDs must be | ||||||||||||||||||||||||||||
| 116 | provided. | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | my $response = $resource->create_direct_channel([ qw( | ||||||||||||||||||||||||||||
| 119 | user_1_id_here | ||||||||||||||||||||||||||||
| 120 | user_2_id_here | ||||||||||||||||||||||||||||
| 121 | ) ]); | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =item C<create_group_channel()> | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | L<Create a group message channel|https://api.mattermost.com/#tag/channels%2Fpaths%2F~1channels~1group%2Fpost> | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | Create a direct message channel between two users. Two user IDs must be | ||||||||||||||||||||||||||||
| 128 | provided. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | my $response = $resource->create_group_channel([ qw( | ||||||||||||||||||||||||||||
| 131 | user_1_id_here | ||||||||||||||||||||||||||||
| 132 | user_2_id_here | ||||||||||||||||||||||||||||
| 133 | user_3_id_here | ||||||||||||||||||||||||||||
| 134 | ) ]); | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =back | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | Mike Jones <mike@netsplit.org.uk> | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | This software is Copyright (c) 2020 by Mike Jones. | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | This is free software, licensed under: | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | The MIT (X11) License | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =cut | ||||||||||||||||||||||||||||