| 1 | package WebService::Mattermost::V4::API::Resource::Post; | ||
| 2 | |||
| 3 | # ABSTRACT: Wrapped API methods for the post API endpoints. | ||
| 4 | |||
| 5 | 12 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 12 | extends 'WebService::Mattermost::V4::API::Resource'; | |
| 8 | 12 | with 'WebService::Mattermost::V4::API::Resource::Role::View::Post'; | |
| 9 | |||
| 10 | ################################################################################ | ||
| 11 | |||
| 12 | around [ qw( | ||
| 13 | get | ||
| 14 | delete | ||
| 15 | update | ||
| 16 | patch | ||
| 17 | |||
| 18 | thread | ||
| 19 | files | ||
| 20 | |||
| 21 | pin | ||
| 22 | unpin | ||
| 23 | |||
| 24 | reactions | ||
| 25 | |||
| 26 | perform_action | ||
| 27 | ) ] => sub { | ||
| 28 | 0 | ▶ | my $orig = shift; |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 29 | 0 | my $self = shift; | |
| 30 | 0 | my $id = shift; | |
| 31 | |||
| 32 | 0 | return $self->validate_id($orig, $id, @_); | |
| 33 | 12 | }; | |
| 34 | |||
| 35 | sub get { | ||
| 36 | my $self = shift; | ||
| 37 | my $id = shift; | ||
| 38 | |||
| 39 | return $self->_single_view_get({ | ||
| 40 | endpoint => '%s', | ||
| 41 | ids => [ $id ], | ||
| 42 | }); | ||
| 43 | } | ||
| 44 | |||
| 45 | sub delete { | ||
| 46 | my $self = shift; | ||
| 47 | my $id = shift; | ||
| 48 | |||
| 49 | return $self->_single_view_delete({ | ||
| 50 | endpoint => '%s', | ||
| 51 | ids => [ $id ], | ||
| 52 | view => 'Status', | ||
| 53 | }); | ||
| 54 | } | ||
| 55 | |||
| 56 | sub update { | ||
| 57 | my $self = shift; | ||
| 58 | my $id = shift; | ||
| 59 | my $args = shift; | ||
| 60 | |||
| 61 | return $self->_single_view_put({ | ||
| 62 | endpoint => '%s', | ||
| 63 | ids => [ $id ], | ||
| 64 | parameters => $args, | ||
| 65 | }); | ||
| 66 | } | ||
| 67 | |||
| 68 | sub patch { | ||
| 69 | my $self = shift; | ||
| 70 | my $id = shift; | ||
| 71 | my $args = shift; | ||
| 72 | |||
| 73 | return $self->_single_view_put({ | ||
| 74 | endpoint => '%s/patch', | ||
| 75 | ids => [ $id ], | ||
| 76 | parameters => $args, | ||
| 77 | }); | ||
| 78 | } | ||
| 79 | |||
| 80 | sub thread { | ||
| 81 | my $self = shift; | ||
| 82 | my $id = shift; | ||
| 83 | |||
| 84 | return $self->_single_view_get({ | ||
| 85 | endpoint => '%s/thread', | ||
| 86 | ids => [ $id ], | ||
| 87 | view => 'Thread', | ||
| 88 | }); | ||
| 89 | } | ||
| 90 | |||
| 91 | sub files { | ||
| 92 | my $self = shift; | ||
| 93 | my $id = shift; | ||
| 94 | |||
| 95 | return $self->_get({ | ||
| 96 | endpoint => '%s/files/info', | ||
| 97 | ids => [ $id ], | ||
| 98 | view => 'File', | ||
| 99 | }); | ||
| 100 | } | ||
| 101 | |||
| 102 | sub pin { | ||
| 103 | my $self = shift; | ||
| 104 | my $id = shift; | ||
| 105 | |||
| 106 | return $self->_single_view_post({ | ||
| 107 | endpoint => '%s/pin', | ||
| 108 | ids => [ $id ], | ||
| 109 | view => 'Status', | ||
| 110 | }); | ||
| 111 | } | ||
| 112 | |||
| 113 | sub unpin { | ||
| 114 | my $self = shift; | ||
| 115 | my $id = shift; | ||
| 116 | |||
| 117 | return $self->_single_view_post({ | ||
| 118 | endpoint => '%s/unpin', | ||
| 119 | ids => [ $id ], | ||
| 120 | view => 'Status', | ||
| 121 | }); | ||
| 122 | } | ||
| 123 | |||
| 124 | sub reactions { | ||
| 125 | my $self = shift; | ||
| 126 | my $id = shift; | ||
| 127 | |||
| 128 | return $self->_get({ | ||
| 129 | endpoint => '%s/reactions', | ||
| 130 | ids => [ $id ], | ||
| 131 | view => 'Reaction', | ||
| 132 | }); | ||
| 133 | } | ||
| 134 | |||
| 135 | sub perform_action { | ||
| 136 | my $self = shift; | ||
| 137 | my $post_id = shift; | ||
| 138 | my $action_id = shift; | ||
| 139 | |||
| 140 | unless ($action_id) { | ||
| 141 | return $self->error_return('An action ID is required'); | ||
| 142 | } | ||
| 143 | |||
| 144 | return $self->_single_view_post({ | ||
| 145 | endpoint => '%s/actions/%s', | ||
| 146 | ids => [ $post_id, $action_id ], | ||
| 147 | view => 'Status', | ||
| 148 | }); | ||
| 149 | } | ||
| 150 | |||
| 151 | ################################################################################ | ||
| 152 | |||
| 153 | 12 | 1; | |
| 154 | |||
| 155 | __END__ | ||
| 156 | |||
| 157 | =pod | ||
| 158 | |||
| 159 | =encoding UTF-8 | ||
| 160 | |||
| 161 | =head1 NAME | ||
| 162 | |||
| 163 | WebService::Mattermost::V4::API::Resource::Post - Wrapped API methods for the post API endpoints. | ||
| 164 | |||
| 165 | =head1 VERSION | ||
| 166 | |||
| 167 | version 0.28 | ||
| 168 | |||
| 169 | =head1 DESCRIPTION | ||
| 170 | |||
| 171 | =head2 USAGE | ||
| 172 | |||
| 173 | use WebService::Mattermost; | ||
| 174 | |||
| 175 | my $mm = WebService::Mattermost->new({ | ||
| 176 | authenticate => 1, | ||
| 177 | username => 'email@address.com', | ||
| 178 | password => 'passwordhere', | ||
| 179 | base_url => 'https://my.mattermost.server.com/api/v4/', | ||
| 180 | }); | ||
| 181 | |||
| 182 | my $resource = $mm->api->post; | ||
| 183 | |||
| 184 | =head2 METHODS | ||
| 185 | |||
| 186 | =over 4 | ||
| 187 | |||
| 188 | =item C<get()> | ||
| 189 | |||
| 190 | L<Get a post|https://api.mattermost.com/#tag/posts%2Fpaths%2F~1posts~1%7Bpost_id%7D%2Fget> | ||
| 191 | |||
| 192 | my $response = $resource->get('ID-HERE'); | ||
| 193 | |||
| 194 | =item C<delete()> | ||
| 195 | |||
| 196 | L<Delete a post|https://api.mattermost.com/#tag/posts%2Fpaths%2F~1posts~1%7Bpost_id%7D%2Fdelete> | ||
| 197 | |||
| 198 | my $response = $resource->delete('ID-HERE'); | ||
| 199 | |||
| 200 | =item C<update()> | ||
| 201 | |||
| 202 | L<Update a post|https://api.mattermost.com/#tag/posts%2Fpaths%2F~1posts~1%7Bpost_id%7D%2Fput> | ||
| 203 | |||
| 204 | Fields not sent will be treated as blank (and unset). Use C<patch()> for | ||
| 205 | updating individual fields. | ||
| 206 | |||
| 207 | my $response = $resource->update('ID-HERE', { | ||
| 208 | # Optional parameters: | ||
| 209 | is_pinned => \0, # or \1 for true | ||
| 210 | message => '...', | ||
| 211 | file_ids => [ '...' ], | ||
| 212 | has_reactions => \0, # or \1 for true | ||
| 213 | props => {}, | ||
| 214 | }); | ||
| 215 | |||
| 216 | =item C<patch()> | ||
| 217 | |||
| 218 | L<Patch a post|https://api.mattermost.com/#tag/posts%2Fpaths%2F~1posts~1%7Bpost_id%7D~1patch%2Fput> | ||
| 219 | |||
| 220 | my $response = $resource->patch('ID-HERE', { | ||
| 221 | # Optional parameters: | ||
| 222 | is_pinned => \0, # or \1 for true | ||
| 223 | message => '...', | ||
| 224 | file_ids => [ '...' ], | ||
| 225 | has_reactions => \0, # or \1 for true | ||
| 226 | props => {}, | ||
| 227 | }); | ||
| 228 | |||
| 229 | =item C<thread()> | ||
| 230 | |||
| 231 | L<Get a thread|https://api.mattermost.com/#tag/posts%2Fpaths%2F~1posts~1%7Bpost_id%7D~1thread%2Fget> | ||
| 232 | |||
| 233 | my $response = $resource->thread('ID-HERE'); | ||
| 234 | |||
| 235 | =item C<files()> | ||
| 236 | |||
| 237 | L<Get file info for post|https://api.mattermost.com/#tag/posts%2Fpaths%2F~1posts~1%7Bpost_id%7D~1files~1info%2Fget> | ||
| 238 | |||
| 239 | my $response = $resource->files('ID-HERE'); | ||
| 240 | |||
| 241 | =item C<pin()> | ||
| 242 | |||
| 243 | L<Pin a post to the channel|https://api.mattermost.com/#tag/posts%2Fpaths%2F~1posts~1%7Bpost_id%7D~1pin%2Fpost> | ||
| 244 | |||
| 245 | my $response = $resource->pin('ID-HERE'); | ||
| 246 | |||
| 247 | =item C<unpin()> | ||
| 248 | |||
| 249 | L<Unpin a post from the channel|https://api.mattermost.com/#tag/posts%2Fpaths%2F~1posts~1%7Bpost_id%7D~1unpin%2Fpost> | ||
| 250 | |||
| 251 | my $response = $resource->unpin('ID-HERE'); | ||
| 252 | |||
| 253 | =item C<reactions()> | ||
| 254 | |||
| 255 | L<Get a list of reactions to a post|https://api.mattermost.com/#tag/reactions%2Fpaths%2F~1posts~1%7Bpost_id%7D~1reactions%2Fget> | ||
| 256 | |||
| 257 | my $response = $resource->reactions('ID-HERE'); | ||
| 258 | |||
| 259 | =item C<perform_action()> | ||
| 260 | |||
| 261 | L<Perform a post action|https://api.mattermost.com/#tag/posts%2Fpaths%2F~1posts~1%7Bpost_id%7D~1actions~1%7Baction_id%7D%2Fpost> | ||
| 262 | |||
| 263 | my $response = $resource->perform_action('POST-ID-HERE', 'REACTION-ID-HERE'); | ||
| 264 | |||
| 265 | =back | ||
| 266 | |||
| 267 | =head1 AUTHOR | ||
| 268 | |||
| 269 | Mike Jones <mike@netsplit.org.uk> | ||
| 270 | |||
| 271 | =head1 COPYRIGHT AND LICENSE | ||
| 272 | |||
| 273 | This software is Copyright (c) 2020 by Mike Jones. | ||
| 274 | |||
| 275 | This is free software, licensed under: | ||
| 276 | |||
| 277 | The MIT (X11) License | ||
| 278 | |||
| 279 | =cut | ||