File Coverage

blib/lib/WebService/Mattermost/V4/API/Object/Post.pm
Criterion Covered Total %
statement 9 37 24.3
branch 0 4 0.0
condition n/a
subroutine 3 17 17.6
pod 0 1 0.0
total 12 59 20.3


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

3: # ABSTRACT: A post item. 4:
5: use Moo;
6: use Types::Standard qw(ArrayRef Maybe Str InstanceOf);
7:
8: use WebService::Mattermost::Helper::Alias 'view';
9:
10: extends 'WebService::Mattermost::V4::API::Object';
11: with qw(
12: WebService::Mattermost::V4::API::Object::Role::APIMethods
13: WebService::Mattermost::V4::API::Object::Role::BelongingToChannel
14: WebService::Mattermost::V4::API::Object::Role::BelongingToUser
15: WebService::Mattermost::V4::API::Object::Role::ID
16: WebService::Mattermost::V4::API::Object::Role::Message
17: WebService::Mattermost::V4::API::Object::Role::Props
18: WebService::Mattermost::V4::API::Object::Role::Timestamps
19: );
20:
21: ################################################################################
22:
23: has [ qw(
24: hashtag
25: original_id
26: parent_id
27: pending_post_id
28: root_id
29: ) ] => (is => 'ro', isa => Maybe[Str], lazy => 1, builder => 1);
30:
31: has [ qw(
32: original_post
33: parent_post
34: pending_post
35: root_post
36: ) ] => (is => 'ro', isa => Maybe[InstanceOf[view 'Post']], lazy => 1, builder => 1);
37:
38: has [ qw(
39: filenames
40: file_ids
41: ) ] => (is => 'ro', isa => Maybe[ArrayRef], lazy => 1, builder => 1);
42:
43: has files => (is => 'ro', lazy => 1, builder => 1);
44:
45: ################################################################################
46:
47: sub BUILD {
48: my $self = shift;
49:
50: $self->api_resource_name('post');
51: $self->available_api_methods([ qw(
52: delete
53: update
54: patch
55: thread
56: files
57: pin
58: inpin
59: reactions
60: perform_action
61: ) ]);
62:
63: return 1;
64: }
65:
66: ################################################################################
67:
68: sub _get_related_post {
69: my $self = shift;
70: my $id = shift;
71:
72: return unless $id;
73: return $self->api->post->get($id)->item;
74: }
75:
76: ################################################################################
77:
78: sub _build_hashtag { shift->raw_data->{hashtag} }
79: sub _build_original_id { shift->raw_data->{original_id} }
80: sub _build_parent_id { shift->raw_data->{parent_id} }
81: sub _build_pending_post_id { shift->raw_data->{pending_post_id} }
82: sub _build_root_id { shift->raw_data->{root_id} }
83: sub _build_filenames { shift->raw_data->{filenames} }
84: sub _build_file_ids { shift->raw_data->{file_ids} }
85:
86: sub _build_original_post {
87: my $self = shift;
88:
89: return $self->_get_related_post($self->original_id);
90: }
91:
92: sub _build_parent_post {
93: my $self = shift;
94:
95: return $self->_get_related_post($self->parent_id);
96: }
97:
98: sub _build_pending_post {
99: my $self = shift;
100:
101: return $self->_get_related_post($self->pending_post_id);
102: }
103:
104: sub _build_root_post {
105: my $self = shift;
106:
107: return $self->_get_related_post($self->root_id);
108: }
109:
110: sub _build_files {
111: my $self = shift;
112:
113: return [] unless $self->file_ids;
114: return [ map { $self->api->file->get($_) } @{$self->file_ids} ];
115: }
116:
117: ################################################################################
118:
119: 1;
120:
121: __END__
122:
123: =pod
124:
125: =encoding UTF-8
126:
127: =head1 NAME
128:
129: WebService::Mattermost::V4::API::Object::Post - A post item.
130:
131: =head1 VERSION
132:
133: version 0.28
134:
135: =head1 DESCRIPTION
136:
137: Describes a Mattermost post.
138:
139: =head2 METHODS
140:
141: See matching methods in L<WebService::Mattermost::V4::API::Resource::Post>
142: for full documentation.
143:
144: ID parameters are not required:
145:
146: my $response = $mattermost->api->post->get('ID-HERE')->item->delete();
147:
148: Is the same as:
149:
150: my $response = $mattermost->api->post->delete('ID-HERE');
151:
152: =over 4
153:
154: =item C<delete()>
155:
156: =item C<update()>
157:
158: =item C<patch()>
159:
160: =item C<thread()>
161:
162: =item C<files()>
163:
164: =item C<pin()>
165:
166: =item C<inpin()>
167:
168: =item C<reactions()>
169:
170: =item C<perform_action()>
171:
172: =back
173:
174: =head2 ATTRIBUTES
175:
176: =over 4
177:
178: =item C<hashtag>
179:
180: A string containing any hashtags in the message.
181:
182: =item C<original_id>
183:
184: =item C<parent_id>
185:
186: =item C<pending_post_id>
187:
188: =item C<root_id>
189:
190: =item C<filenames>
191:
192: A list of filenames attached to the post.
193:
194: =item C<file_ids>
195:
196: A list of file IDs attached to the post.
197:
198: =item C<original_post>
199:
200: Related original post object.
201:
202: =item C<parent_post>
203:
204: Related parent post object.
205:
206: =item C<pending_post>
207:
208: Related pending post object.
209:
210: =item C<root_post>
211:
212: Related root post object.
213:
214: =back
215:
216: =head1 SEE ALSO
217:
218: =over 4
219:
220: =item L<WebService::Mattermost::V4::API::Object::Post>
221:
222: =item L<WebService::Mattermost::V4::API::Object::Role::BelongingToChannel>
223:
224: =item L<WebService::Mattermost::V4::API::Object::Role::BelongingToUser>
225:
226: =item L<WebService::Mattermost::V4::API::Object::Role::ID>
227:
228: =item L<WebService::Mattermost::V4::API::Object::Role::Message>
229:
230: =item L<WebService::Mattermost::V4::API::Object::Role::Props>
231:
232: =item L<WebService::Mattermost::V4::API::Object::Role::Timestamps>
233:
234: =back
235:
236: =head1 AUTHOR
237:
238: Mike Jones <mike@netsplit.org.uk>
239:
240: =head1 COPYRIGHT AND LICENSE
241:
242: This software is Copyright (c) 2020 by Mike Jones.
243:
244: This is free software, licensed under:
245:
246: The MIT (X11) License
247:
248: =cut
249: