blib/lib/WebService/Mattermost/V4/API/Resource/Team/Channels.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 3 | 11 | 27.2 |
branch | 0 | 4 | 0.0 |
condition | n/a | ||
subroutine | 1 | 2 | 50.0 |
pod | 0 | 1 | 0.0 |
total | 4 | 18 | 22.2 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package WebService::Mattermost::V4::API::Resource::Team::Channels; 2: 3: # ABSTRACT: Wrapped API methods for the team channels API endpoints. 4: 5: use Moo; 6: 7: extends 'WebService::Mattermost::V4::API::Resource'; 8: 9: ################################################################################ 10: 11: around [ qw(by_ids public deleted autocomplete search by_name) ] => sub { 12: my $orig = shift; 13: my $self = shift; 14: my $id = shift; 15: 16: return $self->validate_id($orig, $id, @_); 17: }; 18: 19: sub by_ids { 20: my $self = shift; 21: my $team_id = shift; 22: my $channel_ids = shift; 23: 24: unless (scalar @{$channel_ids}) { 25: return $self->error_return('The second argument should be an arrayref of channel_ids'); 26: } 27: 28: return $self->_post({ 29: parameters => $channel_ids, 30: endpoint => '%s/channels/ids', 31: ids => [ $team_id ], 32: view => 'Channel', 33: }); 34: } 35: 36: sub public { 37: my $self = shift; 38: my $team_id = shift || $self->id; 39: my $args = shift; 40: 41: return $self->_get({ 42: endpoint => '%s/channels', 43: ids => [ $team_id ], 44: parameters => $args, 45: view => 'Channel', 46: }); 47: } 48: 49: sub deleted { 50: my $self = shift; 51: my $team_id = shift; 52: my $args = shift; 53: 54: return $self->_get({ 55: endpoint => '%s/channels/deleted', 56: ids => [ $team_id ], 57: parameters => $args, 58: view => 'Channel', 59: }); 60: } 61: 62: sub autocomplete { 63: my $self = shift; 64: my $team_id = shift; 65: my $args = shift; 66: 67: return $self->_get({ 68: endpoint => '%s/channels/autocomplete', 69: ids => [ $team_id ], 70: parameters => $args, 71: required => [ 'name' ], 72: view => 'Channel', 73: }); 74: } 75: 76: sub search { 77: my $self = shift; 78: my $team_id = shift; 79: my $args = shift; 80: 81: return $self->_post({ 82: endpoint => '%s/channels/search', 83: ids => [ $team_id ], 84: parameters => $args, 85: required => [ 'term' ], 86: view => 'Channel', 87: }); 88: } 89: 90: sub by_name { 91: my $self = shift; 92: my $team_id = shift; 93: my $name = shift; 94: 95: unless ($name) { 96: return $self->error_return('The second argument should be a channel name'); 97: } 98: 99: return $self->_single_view_get({ 100: endpoint => '%s/channels/name/%s', 101: ids => [ $team_id, $name ], 102: view => 'Channel', 103: }); 104: } 105: 106: sub by_name_and_team_name { 107: my $self = shift; 108: my $team_name = shift; 109: my $channel_name = shift; 110: 111: unless ($team_name) { 112: return $self->error_return('The first argument should be a team name'); 113: } 114: 115: unless ($channel_name) { 116: return $self->error_return('The second argument should be a channel name'); 117: } 118: 119: return $self->_single_view_get({ 120: endpoint => 'name/%s/channels/name/%s', 121: ids => [ $team_name, $channel_name ], 122: view => 'Channel', 123: }); 124: } 125: 126: ################################################################################ 127: 128: 1; 129: 130: __END__ 131: 132: =pod 133: 134: =encoding UTF-8 135: 136: =head1 NAME 137: 138: WebService::Mattermost::V4::API::Resource::Team::Channels - Wrapped API methods for the team channels API endpoints. 139: 140: =head1 VERSION 141: 142: version 0.30 143: 144: =head1 DESCRIPTION 145: 146: =head2 USAGE 147: 148: use WebService::Mattermost; 149: 150: my $mm = WebService::Mattermost->new({ 151: authenticate => 1, 152: username => 'me@somewhere.com', 153: password => 'hunter2', 154: base_url => 'https://my.mattermost.server.com/api/v4/', 155: }); 156: 157: my $resource = $mm->api->team->channels; 158: 159: =head2 METHODS 160: 161: =over 4 162: 163: =item C<by_ids()> 164: 165: L<Get a list of channels by IDs|https://api.mattermost.com/#tag/channels%2Fpaths%2F~1teams~1%7Bteam_id%7D~1channels~1ids%2Fpost> 166: 167: my $response = $resource->get_by_ids('team-id-here', [ qw( 168: first_channel_id 169: second_channel_id 170: third_channel_id 171: ) ]); 172: 173: =item C<public()> 174: 175: L<Get public channels|https://api.mattermost.com/#tag/channels%2Fpaths%2F~1teams~1%7Bteam_id%7D~1channels%2Fget> 176: 177: my $response = $resource->public('team-id-here', { 178: # Optional arguments 179: page => 1, 180: per_page => 60, 181: }); 182: 183: =item C<deleted()> 184: 185: L<Get deleted channels|https://api.mattermost.com/#tag/channels%2Fpaths%2F~1teams~1%7Bteam_id%7D~1channels~1deleted%2Fget> 186: 187: my $response = $resource->deleted('team-id-here', { 188: # Optional arguments 189: page => 1, 190: per_page => 60, 191: }); 192: 193: =item C<autocomplete()> 194: 195: L<Autocomplete channels|https://api.mattermost.com/#tag/channels%2Fpaths%2F~1teams~1%7Bteam_id%7D~1channels~1autocomplete%2Fget> 196: 197: my $response = $resource->autocomplete('team-id-here', { 198: # Required arguments 199: name => 'Something', 200: }); 201: 202: =item C<search()> 203: 204: L<Search channels|https://api.mattermost.com/#tag/channels%2Fpaths%2F~1teams~1%7Bteam_id%7D~1channels~1search%2Fpost> 205: 206: my $response = $resource->search('team-id-here', { 207: # Required arguments 208: term => 'Something', 209: }); 210: 211: =back 212: 213: =head1 AUTHOR 214: 215: Mike Jones <mike@netsplit.org.uk> 216: 217: =head1 COPYRIGHT AND LICENSE 218: 219: This software is Copyright (c) 2023 by Mike Jones. 220: 221: This is free software, licensed under: 222: 223: The MIT (X11) License 224: 225: =cut 226: |