File Coverage

blib/lib/WebService/Mattermost/V4/API/Resource/Roles.pm
Criterion Covered Total %
statement 3 9 33.3
branch 0 2 0.0
condition 0 2 0.0
subroutine 1 2 50.0
pod 1 1 100.0
total 5 16 31.2


line stmt bran cond sub pod time code
1             package WebService::Mattermost::V4::API::Resource::Roles;
2:

3: # ABSTRACT: Wrapped API methods for the roles API endpoints. 4:
5: use Moo;
6:
7: extends 'WebService::Mattermost::V4::API::Resource';
8:
9: ################################################################################
10:
11: around [ qw(get_by_id get_by_name update_by_id) ] => 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 get_by_id {
20: my $self = shift;
21: my $id = shift;
22:
23: return $self->_get({
24: endpoint => '%s',
25: ids => [ $id ],
26: });
27: }
28:
29: sub get_by_name {
30: my $self = shift;
31: my $name = shift;
32:
33: return $self->_get({
34: endpoint => 'name/%s',
35: ids => [ $name ],
36: });
37: }
38:
39: sub update_by_id {
40: my $self = shift;
41: my $id = shift;
42: my $args = shift;
43:
44: return $self->_patch({
45: endpoint => '%s/patch',
46: parameters => $args,
47: });
48: }
49:
50: sub get_by_names {
51: my $self = shift;
52: my $names = shift;
53:
54: unless (ref $names eq 'ARRAY' && scalar @{$names}) {
55: return $self->error_return('The first argument must be an ArrayRef of names');
56: }
57:
58: return $self->_post({
59: endpoint => 'names',
60: parameters => $names,
61: });
62: }
63:
64: ################################################################################
65:
66: 1;
67:
68: __END__
69:
70: =pod
71:
72: =encoding UTF-8
73:
74: =head1 NAME
75:
76: WebService::Mattermost::V4::API::Resource::Roles - Wrapped API methods for the roles 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 => 'me@somewhere.com',
91: password => 'hunter2',
92: base_url => 'https://my.mattermost.server.com/api/v4/',
93: });
94:
95: my $resource = $mm->api->roles;
96:
97: =head2 METHODS
98:
99: =over 4
100:
101: =item C<get_by_id()>
102:
103: L<Get a role|https://api.mattermost.com/#tag/roles%2Fpaths%2F~1roles~1%7Brole_id%7D%2Fget>
104:
105: my $response = $resource->get_by_id('ID-HERE');
106:
107: =item C<get_by_name()>
108:
109: L<Get a role|https://api.mattermost.com/#tag/roles%2Fpaths%2F~1roles~1name~1%7Brole_name%7D%2Fget>
110:
111: my $response = $resource->get_by_name('NAME-HERE');
112:
113: =item C<update_by_id()>
114:
115: L<Patch a role|https://api.mattermost.com/#tag/roles%2Fpaths%2F~1roles~1%7Brole_id%7D~1patch%2Fput>
116:
117: my $response = $resource->update_by_id('ID-HERE', {
118: permissions => [ qw(
119: PERMISSION-HERE
120: ANOTHER-PERMISSION-HERE
121: ) ],
122: });
123:
124: =item C<get_by_names()>
125:
126: L<Get a list of roles by name|https://api.mattermost.com/#tag/roles%2Fpaths%2F~1roles~1names%2Fpost>
127:
128: my $response = $resource->get_by_names([ qw(NAME-1-HERE NAME-2-HERE) ]);
129:
130: =back
131:
132: =head1 AUTHOR
133:
134: Mike Jones <mike@netsplit.org.uk>
135:
136: =head1 COPYRIGHT AND LICENSE
137:
138: This software is Copyright (c) 2020 by Mike Jones.
139:
140: This is free software, licensed under:
141:
142: The MIT (X11) License
143:
144: =cut
145: