File Coverage

blib/lib/WebService/Mattermost/V4/API/Resource/Emoji.pm
Criterion Covered Total %
statement 3 23 13.0
branch 0 4 0.0
condition 0 3 0.0
subroutine 1 6 16.6
pod 4 5 80.0
total 8 41 19.5


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

3: # ABSTRACT: Wrapped API methods for the emoji API endpoints. 4:
5: use Moo;
6:
7: extends 'WebService::Mattermost::V4::API::Resource';
8:
9: ################################################################################
10:
11: around [ qw(get delete get_image) ] => 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 custom {
20: my $self = shift;
21:
22: return $self->_get({ view => 'Emoji' });
23: }
24:
25: sub create {
26: my $self = shift;
27: my $name = shift;
28: my $filename = shift;
29: my $creator_id = shift;
30:
31: unless ($filename && -f $filename) {
32: return $self->error_return("'${filename}' is not a real file");
33: }
34:
35: return $self->_single_view_post({
36: view => 'Emoji',
37: override_data_type => 'form',
38: parameters => {
39: image => { file => $filename },
40: emoji => {
41: name => $name,
42: creator_id => $creator_id,
43: },
44: },
45: });
46: }
47:
48: sub get {
49: my $self = shift;
50: my $id = shift;
51:
52: return $self->_single_view_get({
53: view => 'Emoji',
54: endpoint => '%s',
55: ids => [ $id ],
56: });
57: }
58:
59: sub delete {
60: my $self = shift;
61: my $id = shift;
62:
63: return $self->_single_view_delete({
64: view => 'Emoji',
65: endpoint => '%s',
66: ids => [ $id ],
67: });
68: }
69:
70: sub get_by_name {
71: my $self = shift;
72: my $name = shift;
73:
74: unless ($name) {
75: return $self->error_return('The first argument should be an emoji name');
76: }
77:
78: return $self->_single_view_get({
79: view => 'Emoji',
80: endpoint => 'name/%s',
81: ids => [ $name ],
82: });
83: }
84:
85: sub get_image {
86: my $self = shift;
87: my $id = shift;
88:
89: return $self->_single_view_get({
90: view => 'Emoji',
91: endpoint => '%s/image',
92: ids => [ $id ],
93: });
94: }
95:
96: sub search {
97: my $self = shift;
98: my $args = shift;
99:
100: return $self->_post({
101: view => 'Emoji',
102: endpoint => 'search',
103: parameters => $args,
104: required => [ 'term' ],
105: });
106: }
107:
108: sub autocomplete {
109: my $self = shift;
110: my $name = shift;
111:
112: return $self->_single_view_get({
113: view => 'Emoji',
114: endpoint => 'autocomplete',
115: parameters => { name => $name },
116: });
117: }
118:
119: ################################################################################
120:
121: 1;
122:
123: __END__
124:
125: =pod
126:
127: =encoding UTF-8
128:
129: =head1 NAME
130:
131: WebService::Mattermost::V4::API::Resource::Emoji - Wrapped API methods for the emoji API endpoints.
132:
133: =head1 VERSION
134:
135: version 0.28
136:
137: =head1 DESCRIPTION
138:
139: use WebService::Mattermost;
140:
141: my $mm = WebService::Mattermost->new({
142: authenticate => 1,
143: username => 'me@somewhere.com',
144: password => 'hunter2',
145: base_url => 'https://my.mattermost.server.com/api/v4/',
146: });
147:
148: my $resource = $mm->api->emoji;
149:
150: =head2 METHODS
151:
152: =over 4
153:
154: =item C<custom()>
155:
156: Get all custom emojis.
157:
158: my $response = $resource->custom();
159:
160: =item C<get()>
161:
162: Get an emoji by its ID.
163:
164: my $response = $resource->get('EMOJI-ID-HERE');
165:
166: =item C<delete()>
167:
168: Delete an emoji by its ID.
169:
170: my $response = $resource->delete('EMOJI-ID-HERE');
171:
172: =item C<get_by_name()>
173:
174: Get an emoji by its name.
175:
176: my $response = $resource->get_by_name('EMOJI-NAME-HERE');
177:
178: =item C<get_image()>
179:
180: Get an emoji's image by its ID.
181:
182: my $response = $resource->get_image('EMOJI-ID-HERE');
183:
184: =item C<search()>
185:
186: Search custom emojis.
187:
188: my $response = $resource->search({
189: # Required arguments
190: term => 'Term here',
191:
192: # Optional arguments
193: prefix_only => 'Prefix here',
194: });
195:
196: =item C<autocomplete()>
197:
198: Autocomplete an emoji name.
199:
200: my $response = $resource->autocomplete('START-OF-EMOJI-NAME');
201:
202: =back
203:
204: =head1 SEE ALSO
205:
206: =over 4
207:
208: =item L<Official Emoji documentation|https://api.mattermost.com/#tag/emoji>
209:
210: =back
211:
212: =head1 AUTHOR
213:
214: Mike Jones <mike@netsplit.org.uk>
215:
216: =head1 COPYRIGHT AND LICENSE
217:
218: This software is Copyright (c) 2020 by Mike Jones.
219:
220: This is free software, licensed under:
221:
222: The MIT (X11) License
223:
224: =cut
225: