File Coverage

blib/lib/WebService/Mattermost/V4/API.pm
Criterion Covered Total %
statement 186 187 99.4
branch 2 2 100.0
condition 2 3 66.6
subroutine 87 88 98.8
pod 0 1 0.0
total 277 281 98.5


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

3: # ABSTRACT: Mattermost API v4 wrapper. 4:
5: use Moo;
6: use MooX::HandlesVia;
7: use Types::Standard qw(ArrayRef Bool InstanceOf Str);
8:
9: use WebService::Mattermost::V4::API::Resource::Analytics;
10: use WebService::Mattermost::V4::API::Resource::Audits;
11: use WebService::Mattermost::V4::API::Resource::Bots;
12: use WebService::Mattermost::V4::API::Resource::Brand;
13: use WebService::Mattermost::V4::API::Resource::Cache;
14: use WebService::Mattermost::V4::API::Resource::Channel;
15: use WebService::Mattermost::V4::API::Resource::Channel::Member;
16: use WebService::Mattermost::V4::API::Resource::Channels;
17: use WebService::Mattermost::V4::API::Resource::Cluster;
18: use WebService::Mattermost::V4::API::Resource::Compliance;
19: use WebService::Mattermost::V4::API::Resource::Compliance::Report;
20: use WebService::Mattermost::V4::API::Resource::DataRetention;
21: use WebService::Mattermost::V4::API::Resource::Database;
22: use WebService::Mattermost::V4::API::Resource::ElasticSearch;
23: use WebService::Mattermost::V4::API::Resource::Email;
24: use WebService::Mattermost::V4::API::Resource::Emoji;
25: use WebService::Mattermost::V4::API::Resource::File;
26: use WebService::Mattermost::V4::API::Resource::Files;
27: use WebService::Mattermost::V4::API::Resource::Job;
28: use WebService::Mattermost::V4::API::Resource::Jobs;
29: use WebService::Mattermost::V4::API::Resource::LDAP;
30: use WebService::Mattermost::V4::API::Resource::Logs;
31: use WebService::Mattermost::V4::API::Resource::OAuth;
32: use WebService::Mattermost::V4::API::Resource::OAuth::Application;
33: use WebService::Mattermost::V4::API::Resource::Plugin;
34: use WebService::Mattermost::V4::API::Resource::Plugins;
35: use WebService::Mattermost::V4::API::Resource::Post;
36: use WebService::Mattermost::V4::API::Resource::Posts;
37: use WebService::Mattermost::V4::API::Resource::Reactions;
38: use WebService::Mattermost::V4::API::Resource::Roles;
39: use WebService::Mattermost::V4::API::Resource::S3;
40: use WebService::Mattermost::V4::API::Resource::SAML;
41: use WebService::Mattermost::V4::API::Resource::Schemes;
42: use WebService::Mattermost::V4::API::Resource::System;
43: use WebService::Mattermost::V4::API::Resource::Team;
44: use WebService::Mattermost::V4::API::Resource::Teams;
45: use WebService::Mattermost::V4::API::Resource::User;
46: use WebService::Mattermost::V4::API::Resource::Users;
47: use WebService::Mattermost::V4::API::Resource::Webhook;
48: use WebService::Mattermost::V4::API::Resource::WebRTC;
49: use WebService::Mattermost::Helper::Alias 'v4';
50:
51: ################################################################################
52:
53: has auth_token => (is => 'ro', isa => Str, required => 1);
54: has base_url => (is => 'ro', isa => Str, required => 1);
55:
56: has authenticate => (is => 'ro', isa => Bool, default => 0);
57: has debug => (is => 'ro', isa => Bool, default => 0);
58: has resources => (is => 'rw', isa => ArrayRef, default => sub { [] },
59: handles_via => 'Array',
60: handles => {
61: add_resource => 'push',
62: });
63:
64: has analytics => (is => 'lazy', isa => InstanceOf[v4 'Analytics']);
65: has application => (is => 'lazy', isa => InstanceOf[v4 'OAuth::Application']);
66: has audits => (is => 'lazy', isa => InstanceOf[v4 'Audits']);
67: has bots => (is => 'lazy', isa => InstanceOf[v4 'Bots']);
68: has brand => (is => 'lazy', isa => InstanceOf[v4 'Brand']);
69: has cache => (is => 'lazy', isa => InstanceOf[v4 'Cache']);
70: has channel => (is => 'lazy', isa => InstanceOf[v4 'Channel']);
71: has channel_member => (is => 'lazy', isa => InstanceOf[v4 'Channel::Member']);
72: has channels => (is => 'lazy', isa => InstanceOf[v4 'Channels']);
73: has cluster => (is => 'lazy', isa => InstanceOf[v4 'Cluster']);
74: has compliance => (is => 'lazy', isa => InstanceOf[v4 'Compliance']);
75: has compliance_report => (is => 'lazy', isa => InstanceOf[v4 'Compliance::Report']);
76: has data_retention => (is => 'lazy', isa => InstanceOf[v4 'DataRetention']);
77: has database => (is => 'lazy', isa => InstanceOf[v4 'Database']);
78: has elasticsearch => (is => 'lazy', isa => InstanceOf[v4 'ElasticSearch']);
79: has email => (is => 'lazy', isa => InstanceOf[v4 'Email']);
80: has emoji => (is => 'lazy', isa => InstanceOf[v4 'Emoji']);
81: has file => (is => 'lazy', isa => InstanceOf[v4 'File']);
82: has files => (is => 'lazy', isa => InstanceOf[v4 'Files']);
83: has job => (is => 'lazy', isa => InstanceOf[v4 'Job']);
84: has jobs => (is => 'lazy', isa => InstanceOf[v4 'Jobs']);
85: has ldap => (is => 'lazy', isa => InstanceOf[v4 'LDAP']);
86: has logs => (is => 'lazy', isa => InstanceOf[v4 'Logs']);
87: has oauth => (is => 'lazy', isa => InstanceOf[v4 'OAuth']);
88: has plugin => (is => 'lazy', isa => InstanceOf[v4 'Plugin']);
89: has plugins => (is => 'lazy', isa => InstanceOf[v4 'Plugins']);
90: has post => (is => 'lazy', isa => InstanceOf[v4 'Post']);
91: has posts => (is => 'lazy', isa => InstanceOf[v4 'Posts']);
92: has reactions => (is => 'lazy', isa => InstanceOf[v4 'Reactions']);
93: has roles => (is => 'lazy', isa => InstanceOf[v4 'Roles']);
94: has s3 => (is => 'lazy', isa => InstanceOf[v4 'S3']);
95: has saml => (is => 'lazy', isa => InstanceOf[v4 'SAML']);
96: has schemes => (is => 'lazy', isa => InstanceOf[v4 'Schemes']);
97: has system => (is => 'lazy', isa => InstanceOf[v4 'System']);
98: has team => (is => 'lazy', isa => InstanceOf[v4 'Team']);
99: has team_channels => (is => 'lazy', isa => InstanceOf[v4 'Team::Channels']);
100: has teams => (is => 'lazy', isa => InstanceOf[v4 'Teams']);
101: has user => (is => 'lazy', isa => InstanceOf[v4 'User']);
102: has users => (is => 'lazy', isa => InstanceOf[v4 'Users']);
103: has webhooks => (is => 'lazy', isa => InstanceOf[v4 'Webhook']);
104: has webrtc => (is => 'lazy', isa => InstanceOf[v4 'WebRTC']);
105:
106: ################################################################################
107:
108: sub BUILD {
109: my $self = shift;
110:
111: foreach my $name (sort $self->meta->get_attribute_list) {
112: my $attr = $self->meta->get_attribute($name);
113:
114: if ($attr->has_builder) {
115: my $cref = $self->can($name);
116:
117: $self->$cref;
118: }
119: }
120:
121: return 1;
122: }
123:
124: ################################################################################
125:
126: sub _new_resource {
127: my $self = shift;
128: my $name = shift;
129: my $alt_name = shift || lc $name;
130:
131: my $resource = v4($name)->new({
132: api => $self,
133: auth_token => $self->auth_token,
134: base_url => $self->base_url,
135: resource => $alt_name,
136: debug => $self->debug,
137: });
138:
139: $self->add_resource($resource);
140:
141: return $resource;
142: }
143:
144: ################################################################################
145:
146: # The optional second parameter in some of these builders sets the "resource
147: # name", i.e. DataRetention's base resource is "data_retention", not
148: # "dataretention".
149:
150: sub _build_analytics { shift->_new_resource('Analytics') }
151: sub _build_application { shift->_new_resource('OAuth::Application', 'oauth') }
152: sub _build_audits { shift->_new_resource('Audits') }
153: sub _build_bots { shift->_new_resource('Bots') }
154: sub _build_brand { shift->_new_resource('Brand') }
155: sub _build_cache { shift->_new_resource('Cache', 'caches') }
156: sub _build_channel { shift->_new_resource('Channel', 'channels') }
157: sub _build_channel_member { shift->_new_resource('Channel::Member', 'channels') }
158: sub _build_channels { shift->_new_resource('Channels') }
159: sub _build_cluster { shift->_new_resource('Cluster') }
160: sub _build_compliance { shift->_new_resource('Compliance') }
161: sub _build_compliance_report { shift->_new_resource('Compliance::Report', 'compliance') }
162: sub _build_config { shift->_new_resource('Config') }
163: sub _build_data_retention { shift->_new_resource('DataRetention', 'data_retention') }
164: sub _build_database { shift->_new_resource('Database') }
165: sub _build_elasticsearch { shift->_new_resource('ElasticSearch') }
166: sub _build_email { shift->_new_resource('Email') }
167: sub _build_emoji { shift->_new_resource('Emoji') }
168: sub _build_files { shift->_new_resource('Files') }
169: sub _build_file { shift->_new_resource('File', 'files') }
170: sub _build_job { shift->_new_resource('Job', 'jobs') }
171: sub _build_jobs { shift->_new_resource('Jobs') }
172: sub _build_ldap { shift->_new_resource('LDAP') }
173: sub _build_logs { shift->_new_resource('Logs') }
174: sub _build_oauth { shift->_new_resource('OAuth') }
175: sub _build_plugin { shift->_new_resource('Plugin', 'plugins') }
176: sub _build_plugins { shift->_new_resource('Plugins') }
177: sub _build_post { shift->_new_resource('Post', 'posts') }
178: sub _build_posts { shift->_new_resource('Posts') }
179: sub _build_reactions { shift->_new_resource('Reactions') }
180: sub _build_roles { shift->_new_resource('Roles') }
181: sub _build_s3 { shift->_new_resource('S3', 'file') }
182: sub _build_saml { shift->_new_resource('SAML') }
183: sub _build_schemes { shift->_new_resource('Schemes') }
184: sub _build_system { shift->_new_resource('System') }
185: sub _build_team { shift->_new_resource('Team', 'teams') }
186: sub _build_teams { shift->_new_resource('Teams') }
187: sub _build_team_channels { shift->_new_resource('Team::Channels', 'team') }
188: sub _build_user { shift->_new_resource('User', 'users') }
189: sub _build_users { shift->_new_resource('Users') }
190: sub _build_webhooks { shift->_new_resource('Webhook', 'hooks') }
191: sub _build_webrtc { shift->_new_resource('WebRTC') }
192:
193: ################################################################################
194:
195: 1;
196:
197: __END__
198:
199: =pod
200:
201: =encoding UTF-8
202:
203: =head1 NAME
204:
205: WebService::Mattermost::V4::API - Mattermost API v4 wrapper.
206:
207: =head1 VERSION
208:
209: version 0.28
210:
211: =head1 DESCRIPTION
212:
213: Container for API resources.
214:
215: =head2 ATTRIBUTES
216:
217: =over 4
218:
219: =item * C<analytics>
220:
221: See L<WebService::Mattermost::V4::API::Resource::Analytics>
222:
223: =item * C<application>
224:
225: See L<WebService::Mattermost::V4::API::Resource::OAuth::Application>
226:
227: =item * C<audits>
228:
229: See L<WebService::Mattermost::V4::API::Resource::Audits>
230:
231: =item * C<brand>
232:
233: See L<WebService::Mattermost::V4::API::Resource::Brand>.
234:
235: =item * C<bots>
236:
237: See L<WebService::Mattermost::V4::API::Resource::Bots>.
238:
239: =item * C<channels>
240:
241: See L<WebService::Mattermost::V4::API::Resource::Channels>.
242:
243: =item * C<channel>
244:
245: See L<WebService::Mattermost::V4::API::Resource::Channel>.
246:
247: =item * C<channel_member>
248:
249: See L<WebService::Mattermost::V4::API::Resource::Channel::Member>.
250:
251: =item * C<cluster>
252:
253: See L<WebService::Mattermost::V4::API::Resource::Cluster>.
254:
255: =item * C<config>
256:
257: See L<WebService::Mattermost::V4::API::Resource::Config>.
258:
259: =item * C<compliance>
260:
261: See L<WebService::Mattermost::V4::API::Resource::Compliance>.
262:
263: =item * C<compliance_report>
264:
265: See L<WebService::Mattermost::V4::API::Resource::Compliance::Report>.
266:
267: =item * C<data_retention>
268:
269: See L<WebService::Mattermost::V4::API::Resource::DataRetention>.
270:
271: =item * C<database>
272:
273: See L<WebService::Mattermost::V4::API::Resource::Database>.
274:
275: =item * C<elasticsearch>
276:
277: See L<WebService::Mattermost::V4::API::Resource::ElasticSearch>.
278:
279: =item * C<email>
280:
281: See L<WebService::Mattermost::V4::API::Resource::Email>.
282:
283: =item * C<emoji>
284:
285: See L<WebService::Mattermost::V4::API::Resource::Emoji>.
286:
287: =item * C<file>
288:
289: See L<WebService::Mattermost::V4::API::Resource::File>.
290:
291: =item * C<files>
292:
293: See L<WebService::Mattermost::V4::API::Resource::Files>.
294:
295: =item * C<job>
296:
297: See L<WebService::Mattermost::V4::API::Resource::Job>.
298:
299: =item * C<jobs>
300:
301: See L<WebService::Mattermost::V4::API::Resource::Jobs>.
302:
303: =item * C<ldap>
304:
305: See L<WebService::Mattermost::V4::API::Resource::LDAP>.
306:
307: =item * C<logs>
308:
309: See L<WebService::Mattermost::V4::API::Resource::Logs>.
310:
311: =item * C<oauth>
312:
313: See L<WebService::Mattermost::V4::API::Resource::OAuth>.
314:
315: =item * C<plugin>
316:
317: See L<WebService::Mattermost::V4::API::Resource::Plugin>.
318:
319: =item * C<plugins>
320:
321: See L<WebService::Mattermost::V4::API::Resource::Plugins>.
322:
323: =item * C<post>
324:
325: See L<WebService::Mattermost::V4::API::Resource::Post>.
326:
327: =item * C<posts>
328:
329: See L<WebService::Mattermost::V4::API::Resource::Posts>.
330:
331: =item * C<reactions>
332:
333: See L<WebService::Mattermost::V4::API::Resource::Reactions>.
334:
335: =item * C<roles>
336:
337: See L<WebService::Mattermost::V4::API::Resource::Roles>.
338:
339: =item * C<s3>
340:
341: See L<WebService::Mattermost::V4::API::Resource::S3>.
342:
343: =item * C<saml>
344:
345: See L<WebService::Mattermost::V4::API::Resource::SAML>.
346:
347: =item * C<schemes>
348:
349: See L<WebService::Mattermost::V4::API::Resource::Schemes>.
350:
351: =item * C<system>
352:
353: See L<WebService::Mattermost::V4::API::Resource::System>.
354:
355: =item * C<team>
356:
357: See L<WebService::Mattermost::V4::API::Resource::Team>.
358:
359: =item * C<teams>
360:
361: See L<WebService::Mattermost::V4::API::Resource::Teams>.
362:
363: =item * C<user>
364:
365: See L<WebService::Mattermost::V4::API::Resource::User>.
366:
367: =item * C<users>
368:
369: See L<WebService::Mattermost::V4::API::Resource::Users>.
370:
371: =item * C<webhooks>
372:
373: See L<WebService::Mattermost::V4::API::Resource::Webhook>.
374:
375: =item * C<webrtc>
376:
377: See L<WebService::Mattermost::V4::API::Resource::WebRTC>.
378:
379: =back
380:
381: =head1 AUTHOR
382:
383: Mike Jones <mike@netsplit.org.uk>
384:
385: =head1 COPYRIGHT AND LICENSE
386:
387: This software is Copyright (c) 2020 by Mike Jones.
388:
389: This is free software, licensed under:
390:
391: The MIT (X11) License
392:
393: =cut
394: