blib/lib/WebService/Mattermost/V4/API/Resource/Channels.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 3 | 22 | 13.6 |
branch | 0 | 8 | 0.0 |
condition | 0 | 3 | 0.0 |
subroutine | 1 | 4 | 25.0 |
pod | 3 | 3 | 100.0 |
total | 7 | 40 | 17.5 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package WebService::Mattermost::V4::API::Resource::Channels; 2: 3: # ABSTRACT: Wrapped API methods for the channels API endpoints. 4: 5: use Moo; 6: 7: extends 'WebService::Mattermost::V4::API::Resource'; 8: 9: ################################################################################ 10: 11: sub create { 12: my $self = shift; 13: my $args = shift; 14: 15: $args->{type} = uc $args->{type} if $args->{type}; 16: 17: # O for public, P for private 18: if (!$args->{type} || !grep { $_ eq $args->{type} } qw(O P)) { 19: return $self->error_return('"type" must be O or P'); 20: } 21: 22: return $self->_post({ 23: parameters => $args, 24: required => [ qw(team_id name display_name type) ], 25: }); 26: } 27: 28: sub create_direct_channel { 29: my $self = shift; 30: my $user_ids = shift; 31: 32: if (scalar @{$user_ids} != 2) { 33: return $self->error_return('Two user IDs must be passed'); 34: } 35: 36: return $self->_post({ 37: endpoint => 'direct', 38: parameters => $user_ids, 39: }); 40: } 41: 42: sub create_group_channel { 43: my $self = shift; 44: my $user_ids = shift; 45: 46: if (scalar @{$user_ids} < 2) { 47: return $self->error_return('At least two user IDs must be passed'); 48: } 49: 50: return $self->_post({ 51: endpoint => 'group', 52: parameters => $user_ids, 53: }); 54: } 55: 56: ################################################################################ 57: 58: 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 151: |