| 1 | package WebService::Mattermost::V4::API::Resource::Channel; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | # ABSTRACT: Wrapped API methods for the channel 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 qw( | |||||||||||||
| 9 | WebService::Mattermost::V4::API::Resource::Role::Single | ||||||||||||||
| 10 | WebService::Mattermost::V4::API::Resource::Role::View::Channel | ||||||||||||||
| 11 | ); | ||||||||||||||
| 12 | |||||||||||||||
| 13 | ################################################################################ | ||||||||||||||
| 14 | |||||||||||||||
| 15 | around [ qw( | ||||||||||||||
| 16 | delete | ||||||||||||||
| 17 | get | ||||||||||||||
| 18 | patch | ||||||||||||||
| 19 | pinned | ||||||||||||||
| 20 | posts | ||||||||||||||
| 21 | restore | ||||||||||||||
| 22 | set_scheme | ||||||||||||||
| 23 | stats | ||||||||||||||
| 24 | toggle_private_status | ||||||||||||||
| 25 | update | ||||||||||||||
| 26 | ) ] => sub { | ||||||||||||||
| 27 | 0 | ▶ | my $orig = shift; | ||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||
| 28 | 0 | my $self = shift; | |||||||||||||
| 29 | 0 | my $id = shift; | |||||||||||||
| 30 | |||||||||||||||
| 31 | 0 | my @args = ($orig); | |||||||||||||
| 32 | |||||||||||||||
| 33 | 0 | ▶ | if ($id) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 34 | 0 | push @args, $id; | |||||||||||||
| 35 | } elsif ($self->id) { | ||||||||||||||
| 36 | 0 | push @args, $self->id; | |||||||||||||
| 37 | } else { | ||||||||||||||
| 38 | 0 | push @args, ''; | |||||||||||||
| 39 | } | ||||||||||||||
| 40 | |||||||||||||||
| 41 | 0 | push @args, @_; | |||||||||||||
| 42 | |||||||||||||||
| 43 | 0 | return $self->validate_id(@args); | |||||||||||||
| 44 | 12 | }; | |||||||||||||
| 45 | |||||||||||||||
| 46 | sub get { | ||||||||||||||
| 47 | my $self = shift; | ||||||||||||||
| 48 | my $id = shift; | ||||||||||||||
| 49 | |||||||||||||||
| 50 | return $self->_single_view_get({ | ||||||||||||||
| 51 | endpoint => '%s', | ||||||||||||||
| 52 | ids => [ $id ], | ||||||||||||||
| 53 | }); | ||||||||||||||
| 54 | } | ||||||||||||||
| 55 | |||||||||||||||
| 56 | sub update { | ||||||||||||||
| 57 | my $self = shift; | ||||||||||||||
| 58 | my $id = shift; | ||||||||||||||
| 59 | my $args = shift; | ||||||||||||||
| 60 | |||||||||||||||
| 61 | $args->{id} = $id; | ||||||||||||||
| 62 | |||||||||||||||
| 63 | return $self->_single_view_put({ | ||||||||||||||
| 64 | endpoint => '%s', | ||||||||||||||
| 65 | ids => [ $id ], | ||||||||||||||
| 66 | parameters => $args, | ||||||||||||||
| 67 | }); | ||||||||||||||
| 68 | } | ||||||||||||||
| 69 | |||||||||||||||
| 70 | sub delete { | ||||||||||||||
| 71 | my $self = shift; | ||||||||||||||
| 72 | my $id = shift; | ||||||||||||||
| 73 | |||||||||||||||
| 74 | return $self->_single_view_delete({ | ||||||||||||||
| 75 | endpoint => '%s', | ||||||||||||||
| 76 | ids => [ $id ], | ||||||||||||||
| 77 | view => 'Status', | ||||||||||||||
| 78 | }); | ||||||||||||||
| 79 | } | ||||||||||||||
| 80 | |||||||||||||||
| 81 | sub patch { | ||||||||||||||
| 82 | my $self = shift; | ||||||||||||||
| 83 | my $id = shift; | ||||||||||||||
| 84 | my $args = shift; | ||||||||||||||
| 85 | |||||||||||||||
| 86 | return $self->_single_view_put({ | ||||||||||||||
| 87 | endpoint => '%s/patch', | ||||||||||||||
| 88 | ids => [ $id ], | ||||||||||||||
| 89 | parameters => $args, | ||||||||||||||
| 90 | }); | ||||||||||||||
| 91 | } | ||||||||||||||
| 92 | |||||||||||||||
| 93 | sub toggle_private_status { | ||||||||||||||
| 94 | my $self = shift; | ||||||||||||||
| 95 | my $id = shift; | ||||||||||||||
| 96 | |||||||||||||||
| 97 | return $self->_single_view_post({ | ||||||||||||||
| 98 | endpoint => '%s/convert', | ||||||||||||||
| 99 | ids => [ $id ], | ||||||||||||||
| 100 | }); | ||||||||||||||
| 101 | } | ||||||||||||||
| 102 | |||||||||||||||
| 103 | sub restore { | ||||||||||||||
| 104 | my $self = shift; | ||||||||||||||
| 105 | my $id = shift; | ||||||||||||||
| 106 | |||||||||||||||
| 107 | return $self->_single_view_post({ | ||||||||||||||
| 108 | endpoint => '%s/restore', | ||||||||||||||
| 109 | ids => [ $id ], | ||||||||||||||
| 110 | }); | ||||||||||||||
| 111 | } | ||||||||||||||
| 112 | |||||||||||||||
| 113 | sub stats { | ||||||||||||||
| 114 | my $self = shift; | ||||||||||||||
| 115 | my $id = shift; | ||||||||||||||
| 116 | |||||||||||||||
| 117 | return $self->_single_view_get({ | ||||||||||||||
| 118 | endpoint => '%s/stats', | ||||||||||||||
| 119 | ids => [ $id ], | ||||||||||||||
| 120 | }); | ||||||||||||||
| 121 | } | ||||||||||||||
| 122 | |||||||||||||||
| 123 | sub pinned { | ||||||||||||||
| 124 | my $self = shift; | ||||||||||||||
| 125 | my $id = shift; | ||||||||||||||
| 126 | |||||||||||||||
| 127 | # TODO: convert to ordered view of Posts when the Posts integration is done | ||||||||||||||
| 128 | |||||||||||||||
| 129 | return $self->_single_view_get({ | ||||||||||||||
| 130 | endpoint => '%s/pinned', | ||||||||||||||
| 131 | ids => [ $id ], | ||||||||||||||
| 132 | view => '', | ||||||||||||||
| 133 | }); | ||||||||||||||
| 134 | } | ||||||||||||||
| 135 | |||||||||||||||
| 136 | sub set_scheme { | ||||||||||||||
| 137 | my $self = shift; | ||||||||||||||
| 138 | my $id = shift; | ||||||||||||||
| 139 | my $args = shift; | ||||||||||||||
| 140 | |||||||||||||||
| 141 | return $self->_single_view_put({ | ||||||||||||||
| 142 | endpoint => '%s/scheme', | ||||||||||||||
| 143 | ids => [ $id ], | ||||||||||||||
| 144 | parameters => $args, | ||||||||||||||
| 145 | required => [ 'scheme_id' ], | ||||||||||||||
| 146 | view => 'Status', | ||||||||||||||
| 147 | }); | ||||||||||||||
| 148 | } | ||||||||||||||
| 149 | |||||||||||||||
| 150 | sub posts { | ||||||||||||||
| 151 | my $self = shift; | ||||||||||||||
| 152 | my $id = shift; | ||||||||||||||
| 153 | my $args = shift; | ||||||||||||||
| 154 | |||||||||||||||
| 155 | return $self->_single_view_get({ | ||||||||||||||
| 156 | endpoint => '%s/posts', | ||||||||||||||
| 157 | ids => [ $id ], | ||||||||||||||
| 158 | parameters => $args, | ||||||||||||||
| 159 | view => 'Thread', | ||||||||||||||
| 160 | }); | ||||||||||||||
| 161 | } | ||||||||||||||
| 162 | |||||||||||||||
| 163 | ################################################################################ | ||||||||||||||
| 164 | |||||||||||||||
| 165 | 12 | 1; | |||||||||||||
| 166 | |||||||||||||||
| 167 | __END__ | ||||||||||||||
| 168 | |||||||||||||||
| 169 | =pod | ||||||||||||||
| 170 | |||||||||||||||
| 171 | =encoding UTF-8 | ||||||||||||||
| 172 | |||||||||||||||
| 173 | =head1 NAME | ||||||||||||||
| 174 | |||||||||||||||
| 175 | WebService::Mattermost::V4::API::Resource::Channel - Wrapped API methods for the channel API endpoints. | ||||||||||||||
| 176 | |||||||||||||||
| 177 | =head1 VERSION | ||||||||||||||
| 178 | |||||||||||||||
| 179 | version 0.28 | ||||||||||||||
| 180 | |||||||||||||||
| 181 | =head1 DESCRIPTION | ||||||||||||||
| 182 | |||||||||||||||
| 183 | =head2 USAGE | ||||||||||||||
| 184 | |||||||||||||||
| 185 | my $mm = WebService::Mattermost->new({ | ||||||||||||||
| 186 | authenticate => 1, | ||||||||||||||
| 187 | username => 'me@somewhere.com', | ||||||||||||||
| 188 | password => 'hunter2', | ||||||||||||||
| 189 | base_url => 'https://my.mattermost.server.com/api/v4/', | ||||||||||||||
| 190 | }); | ||||||||||||||
| 191 | |||||||||||||||
| 192 | my $resource = $mm->api->channel; | ||||||||||||||
| 193 | |||||||||||||||
| 194 | Optionally, you can set a global channel ID and not pass that argument to | ||||||||||||||
| 195 | every method: | ||||||||||||||
| 196 | |||||||||||||||
| 197 | $resource->id('CHANNEL-ID-HERE'); | ||||||||||||||
| 198 | |||||||||||||||
| 199 | This would make the C<get()> call look like: | ||||||||||||||
| 200 | |||||||||||||||
| 201 | my $response = $resource->get(); | ||||||||||||||
| 202 | |||||||||||||||
| 203 | =head2 METHODS | ||||||||||||||
| 204 | |||||||||||||||
| 205 | =over 4 | ||||||||||||||
| 206 | |||||||||||||||
| 207 | =item C<get()> | ||||||||||||||
| 208 | |||||||||||||||
| 209 | L<Get a channel|https://api.mattermost.com/#tag/channels%2Fpaths%2F~1channels~1%7Bchannel_id%7D%2Fget> | ||||||||||||||
| 210 | |||||||||||||||
| 211 | my $response = $resource->get('CHANNEL-ID-HERE'); | ||||||||||||||
| 212 | |||||||||||||||
| 213 | =item C<update()> | ||||||||||||||
| 214 | |||||||||||||||
| 215 | L<Update a channel|https://api.mattermost.com/#tag/channels%2Fpaths%2F~1channels~1%7Bchannel_id%7D%2Fput> | ||||||||||||||
| 216 | |||||||||||||||
| 217 | my $response = $resource->update('CHANNEL-ID-HERE', { | ||||||||||||||
| 218 | # Optional parameters | ||||||||||||||
| 219 | name => '...', | ||||||||||||||
| 220 | display_name => '...', | ||||||||||||||
| 221 | purpose => '...', | ||||||||||||||
| 222 | header => '...', | ||||||||||||||
| 223 | type => '...', | ||||||||||||||
| 224 | }); | ||||||||||||||
| 225 | |||||||||||||||
| 226 | =item C<delete()> | ||||||||||||||
| 227 | |||||||||||||||
| 228 | L<Delete a channel|https://api.mattermost.com/#tag/channels%2Fpaths%2F~1channels~1%7Bchannel_id%7D%2Fdelete> | ||||||||||||||
| 229 | |||||||||||||||
| 230 | my $response = $resource->delete('CHANNEL-ID-HERE'); | ||||||||||||||
| 231 | |||||||||||||||
| 232 | =item C<patch()> | ||||||||||||||
| 233 | |||||||||||||||
| 234 | L<Patch a channel|https://api.mattermost.com/#tag/channels%2Fpaths%2F~1channels~1%7Bchannel_id%7D~1patch%2Fput> | ||||||||||||||
| 235 | |||||||||||||||
| 236 | my $response = $resource->patch('CHANNEL-ID-HERE', { | ||||||||||||||
| 237 | # Optional parameters | ||||||||||||||
| 238 | name => '...', | ||||||||||||||
| 239 | display_name => '...', | ||||||||||||||
| 240 | purpose => '...', | ||||||||||||||
| 241 | header => '...', | ||||||||||||||
| 242 | }); | ||||||||||||||
| 243 | |||||||||||||||
| 244 | =item C<toggle_private_status()> | ||||||||||||||
| 245 | |||||||||||||||
| 246 | L<Convert a channel from public to private|https://api.mattermost.com/#tag/channels%2Fpaths%2F~1channels~1%7Bchannel_id%7D~1convert%2Fpost> | ||||||||||||||
| 247 | |||||||||||||||
| 248 | my $response = $resource->toggle_private_status('CHANNEL-ID-HERE'); | ||||||||||||||
| 249 | |||||||||||||||
| 250 | =item C<restore()> | ||||||||||||||
| 251 | |||||||||||||||
| 252 | L<Restore a channel|https://api.mattermost.com/#tag/channels%2Fpaths%2F~1channels~1%7Bchannel_id%7D~1restore%2Fpost> | ||||||||||||||
| 253 | |||||||||||||||
| 254 | my $response = $resource->restore('CHANNEL-ID-HERE'); | ||||||||||||||
| 255 | |||||||||||||||
| 256 | =item C<stats()> | ||||||||||||||
| 257 | |||||||||||||||
| 258 | L<Get channel statistics|https://api.mattermost.com/#tag/channels%2Fpaths%2F~1channels~1%7Bchannel_id%7D~1stats%2Fget> | ||||||||||||||
| 259 | |||||||||||||||
| 260 | my $response = $resource->stats('CHANNEL-ID-HERE'); | ||||||||||||||
| 261 | |||||||||||||||
| 262 | =item C<pinned()> | ||||||||||||||
| 263 | |||||||||||||||
| 264 | L<Get a channel's pinned posts|https://api.mattermost.com/#tag/channels%2Fpaths%2F~1channels~1%7Bchannel_id%7D~1pinned%2Fget> | ||||||||||||||
| 265 | |||||||||||||||
| 266 | my $response = $resource->pinned('CHANNEL-ID-HERE'); | ||||||||||||||
| 267 | |||||||||||||||
| 268 | =item C<set_scheme()> | ||||||||||||||
| 269 | |||||||||||||||
| 270 | L<Set a channel's scheme|https://api.mattermost.com/#tag/channels%2Fpaths%2F~1channels~1%7Bchannel_id%7D~1scheme%2Fput> | ||||||||||||||
| 271 | |||||||||||||||
| 272 | my $response = $resource->set_scheme('CHANNEL-ID-HERE', { | ||||||||||||||
| 273 | # Required parameters: | ||||||||||||||
| 274 | scheme_id => '...', | ||||||||||||||
| 275 | }); | ||||||||||||||
| 276 | |||||||||||||||
| 277 | =item C<posts()> | ||||||||||||||
| 278 | |||||||||||||||
| 279 | L<Get posts for a channel|https://api.mattermost.com/#tag/posts%2Fpaths%2F~1channels~1%7Bchannel_id%7D~1posts%2Fget> | ||||||||||||||
| 280 | |||||||||||||||
| 281 | my $response = $resource->posts('CHANNEL-ID-HERE', { | ||||||||||||||
| 282 | # Optional parameters: | ||||||||||||||
| 283 | page => 0, | ||||||||||||||
| 284 | per_page => 60, | ||||||||||||||
| 285 | since => 'UNIX-TIMESTAMP', # milliseconds | ||||||||||||||
| 286 | before => 'POST-ID-HERE', | ||||||||||||||
| 287 | after => 'POST-ID-HERE', | ||||||||||||||
| 288 | }); | ||||||||||||||
| 289 | |||||||||||||||
| 290 | =back | ||||||||||||||
| 291 | |||||||||||||||
| 292 | =head1 AUTHOR | ||||||||||||||
| 293 | |||||||||||||||
| 294 | Mike Jones <mike@netsplit.org.uk> | ||||||||||||||
| 295 | |||||||||||||||
| 296 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||
| 297 | |||||||||||||||
| 298 | This software is Copyright (c) 2020 by Mike Jones. | ||||||||||||||
| 299 | |||||||||||||||
| 300 | This is free software, licensed under: | ||||||||||||||
| 301 | |||||||||||||||
| 302 | The MIT (X11) License | ||||||||||||||
| 303 | |||||||||||||||
| 304 | =cut | ||||||||||||||