Commit d52cc6f4 authored by Mike Jones's avatar Mike Jones 🌶

Final API method wrapping

parent 695011b9
......@@ -21,6 +21,7 @@ use WebService::Mattermost::V4::API::Resource::Email;
use WebService::Mattermost::V4::API::Resource::Emoji;
use WebService::Mattermost::V4::API::Resource::File;
use WebService::Mattermost::V4::API::Resource::Files;
use WebService::Mattermost::V4::API::Resource::Job;
use WebService::Mattermost::V4::API::Resource::Jobs;
use WebService::Mattermost::V4::API::Resource::LDAP;
use WebService::Mattermost::V4::API::Resource::Logs;
......@@ -74,6 +75,7 @@ has email => (is => 'ro', isa => InstanceOf[v4 'Email'],
has emoji => (is => 'ro', isa => InstanceOf[v4 'Emoji'], lazy => 1, builder => 1);
has file => (is => 'ro', isa => InstanceOf[v4 'File'], lazy => 1, builder => 1);
has files => (is => 'ro', isa => InstanceOf[v4 'Files'], lazy => 1, builder => 1);
has job => (is => 'ro', isa => InstanceOf[v4 'Job'], lazy => 1, builder => 1);
has jobs => (is => 'ro', isa => InstanceOf[v4 'Jobs'], lazy => 1, builder => 1);
has ldap => (is => 'ro', isa => InstanceOf[v4 'LDAP'], lazy => 1, builder => 1);
has logs => (is => 'ro', isa => InstanceOf[v4 'Logs'], lazy => 1, builder => 1);
......@@ -155,8 +157,9 @@ sub _build_database { shift->_new_resource('Database')
sub _build_elasticsearch { shift->_new_resource('ElasticSearch') }
sub _build_email { shift->_new_resource('Email') }
sub _build_emoji { shift->_new_resource('Emoji') }
sub _build_files { shift->_new_resource('Files', 'files') }
sub _build_files { shift->_new_resource('Files') }
sub _build_file { shift->_new_resource('File', 'files') }
sub _build_job { shift->_new_resource('Job', 'jobs') }
sub _build_jobs { shift->_new_resource('Jobs') }
sub _build_ldap { shift->_new_resource('LDAP') }
sub _build_logs { shift->_new_resource('Logs') }
......@@ -267,6 +270,10 @@ See C<WebService::Mattermost::V4::API::Resource::File>.
See C<WebService::Mattermost::V4::API::Resource::Files>.
=item C<job>
See C<WebService::Mattermost::V4::API::Resource::Job>.
=item C<jobs>
See C<WebService::Mattermost::V4::API::Resource::Jobs>.
......
......@@ -5,6 +5,7 @@ use Types::Standard qw(Bool Int Maybe Str);
extends 'WebService::Mattermost::V4::API::Object';
with qw(
WebService::Mattermost::V4::API::Object::Role::APIMethods
WebService::Mattermost::V4::API::Object::Role::BelongingToPost
WebService::Mattermost::V4::API::Object::Role::BelongingToUser
WebService::Mattermost::V4::API::Object::Role::ID
......@@ -29,6 +30,22 @@ sub _build_has_preview_image { shift->raw_data->{has_preview_image} ? 1 : 0 }
################################################################################
sub BUILD {
my $self = shift;
$self->api_resource_name('file');
$self->set_available_api_methods([ qw(
get_thumbnail
get_preview
get_link
get_metadata
) ]);
return 1;
}
################################################################################
1;
__END__
......@@ -40,6 +57,31 @@ WebService::Mattermost::V4::API::Object::File
Details a Mattermost File object.
=head2 METHODS
See matching methods in C<WebService::Mattermost::V4::API::Resource::File>
for full documentation.
ID parameters are not required:
my $response = $mattermost->api->file->get('ID-HERE')->item->get_thumbnail();
Is the same as:
my $response = $mattermost->api->file->get_thumbnail('ID-HERE');
=over 4
=item C<get_thumbnail()>
=item C<get_preview()>
=item C<get_link()>
=item C<get_metadata()>
=back
=head2 ATTRIBUTES
=over 4
......@@ -62,6 +104,10 @@ Details a Mattermost File object.
=over 4
=item C<WebService::Mattermost::V4::API::Resource::File>
=item C<WebService::Mattermost::V4::API::Resource::Files>
=item C<WebService::Mattermost::V4::API::Object::Role::BelongingToPost>
=item C<WebService::Mattermost::V4::API::Object::Role::BelongingToUser>
......
......@@ -5,6 +5,7 @@ use Types::Standard qw(HashRef Int Maybe Object Str);
extends 'WebService::Mattermost::V4::API::Object';
with qw(
WebService::Mattermost::V4::API::Object::Role::APIMethods
WebService::Mattermost::V4::API::Object::Role::ID
WebService::Mattermost::V4::API::Object::Role::CreatedAt
WebService::Mattermost::V4::API::Object::Role::Status
......@@ -21,6 +22,17 @@ has started_at => (is => 'ro', isa => Maybe[Object], lazy => 1, builder =
################################################################################
sub BUILD {
my $self = shift;
$self->api_resource_name('job');
$self->set_available_api_methods([ 'cancel' ]);
return 1;
}
################################################################################
sub _build_type {
my $self = shift;
......@@ -68,6 +80,25 @@ WebService::Mattermost::V4::API::Object::Job
=head1 DESCRIPTION
=head2 METHODS
See matching methods in C<WebService::Mattermost::V4::API::Resource::Job>
for full documentation.
ID parameters are not required:
my $response = $mattermost->api->job->get('ID-HERE')->item->cancel();
Is the same as:
my $response = $mattermost->api->job->cancel('ID-HERE');
=over 4
=item C<cancel()>
=back
=head2 ATTRIBUTES
=over 4
......@@ -92,6 +123,10 @@ DateTime.
=over 4
=item C<WebService::Mattermost::V4::API::Object::Job>
=item C<WebService::Mattermost::V4::API::Object::Jobs>
=item C<WebService::Mattermost::V4::API::Object::Role::ID>
=item C<WebService::Mattermost::V4::API::Object::Role::CreatedAt>
......
......@@ -5,6 +5,7 @@ use Types::Standard qw(Bool HashRef Maybe Str);
extends 'WebService::Mattermost::V4::API::Object';
with qw(
WebService::Mattermost::V4::API::Object::Role::APIMethods
WebService::Mattermost::V4::API::Object::Role::Description
WebService::Mattermost::V4::API::Object::Role::Name
WebService::Mattermost::V4::API::Object::Role::ID
......@@ -31,6 +32,15 @@ around BUILDARGS => sub {
return $self->$orig($args);
};
sub BUILD {
my $self = shift;
$self->api_resource_name('plugin');
$self->set_available_api_methods([ qw(remove activate deactivate) ]);
return 1;
}
################################################################################
1;
......@@ -44,6 +54,29 @@ WebService::Mattermost::V4::API::Object::Plugin
An active or inactive plugin.
=head2 METHODS
See matching methods in C<WebService::Mattermost::V4::API::Resource::Plugin>
for full documentation.
ID parameters are not required:
my @responses = map { $_->deactivate } @{$mattermost->api->plugins->all->item->active};
Is the same as:
my @responses = map { $mattermost->api->plugin->deactivate($_) } qw(PLUGIN-IDS-HERE);
=over 4
=item C<remove()>
=item C<activate()>
=item C<deactivate()>
=back
=head2 ATTRIBUTES
=over 4
......@@ -64,6 +97,10 @@ An active or inactive plugin.
=over 4
=item C<WebService::Mattermost::V4::API::Resource::Plugin>
=item C<WebService::Mattermost::V4::API::Resource::Plugins>
=item C<WebService::Mattermost::V4::API::Object::Role::Description>
=item C<WebService::Mattermost::V4::API::Object::Role::Name>
......
......@@ -5,6 +5,7 @@ use Types::Standard qw(Bool Str);
extends 'WebService::Mattermost::V4::API::Object';
with qw(
WebService::Mattermost::V4::API::Object::Role::APIMethods
WebService::Mattermost::V4::API::Object::Role::Name
WebService::Mattermost::V4::API::Object::Role::Description
WebService::Mattermost::V4::API::Object::Role::ID
......@@ -22,6 +23,32 @@ has open_invite => (is => 'ro', isa => Bool, lazy => 1, builder => 1);
################################################################################
sub BUILD {
my $self = shift;
$self->api_resource_name('team');
$self->set_available_api_methods([ qw(
add_member
add_members
delete
get_icon
invite_by_emails
members
members_by_ids
patch
remove_icon
search_posts
set_icon
set_scheme
stats
update
) ]);
return 1;
}
################################################################################
sub _build_company_name { shift->raw_data->{company_name} }
sub _build_display_name { shift->raw_data->{display_name} }
sub _build_email { shift->raw_data->{email} }
......@@ -42,6 +69,51 @@ WebService::Mattermost::V4::API::Object::Team
Object version of a Mattermost team.
=head2 METHODS
See matching methods in C<WebService::Mattermost::V4::API::Resource::Team>
for full documentation.
ID parameters are not required:
my $response = $mattermost->api->team->get('ID-HERE')->item->delete();
Is the same as:
my $response = $mattermost->api->team->delete('ID-HERE');
=over 4
=item C<add_member()>
=item C<add_members()>
=item C<delete()>
=item C<get_icon()>
=item C<invite_by_emails()>
=item C<members()>
=item C<members_by_ids()>
=item C<patch()>
=item C<remove_icon()>
=item C<search_posts()>
=item C<set_icon()>
=item C<set_scheme()>
=item C<stats()>
=item C<update()>
=back
=head2 ATTRIBUTES
=over 4
......@@ -76,6 +148,10 @@ Boolean.
=over 4
=item C<WebService::Mattermost::V4::API::Resource::Team>
=item C<WebService::Mattermost::V4::API::Resource::Teams>
=item C<WebService::Mattermost::V4::API::Object::Role::Name>
=item C<WebService::Mattermost::V4::API::Object::Role::Description>
......
package WebService::Mattermost::V4::API::Resource::Job;
use Moo;
extends 'WebService::Mattermost::V4::API::Resource';
################################################################################
around [ qw(get cancel) ] => sub {
my $orig = shift;
my $self = shift;
my $id = shift;
return $self->_validate_id($orig, $id, @_);
};
sub get {
my $self = shift;
my $id = shift;
return $self->_single_view_get({
view => 'Job',
endpoint => '%s',
ids => [ $id ],
});
}
sub cancel {
my $self = shift;
my $id = shift;
return $self->_single_view_post({
view => 'Job',
endpoint => '%s/cancel',
ids => [ $id ],
});
}
################################################################################
1;
__END__
=head1 NAME
WebService::Mattermost::V4::API::Resource::Job
=head1 DESCRIPTION
=head2 USAGE
use WebService::Mattermost;
my $mm = WebService::Mattermost->new({
authenticate => 1,
username => 'me@somewhere.com',
password => 'hunter2',
base_url => 'https://my.mattermost.server.com/api/v4/',
});
my $resource = $mm->api->teams->job;
=head2 METHODS
=over 4
=item C<get()>
L<Get a job|https://api.mattermost.com/#tag/jobs%2Fpaths%2F~1jobs~1%7Bjob_id%7D%2Fget>
my $response = $resource->get('JOB-ID-HERE');
=item C<cancel()>
L<Cancel a job|https://api.mattermost.com/#tag/jobs%2Fpaths%2F~1jobs~1%7Bjob_id%7D~1cancel%2Fpost>
my $response = $resource->cancel('JOB-ID-HERE');
=back
=head1 SEE ALSO
=over 4
=item L<Official Jobs documentation|https://api.mattermost.com/#tag/jobs>
=back
=head1 AUTHOR
Mike Jones L<email:mike@netsplit.org.uk>
......@@ -6,14 +6,6 @@ extends 'WebService::Mattermost::V4::API::Resource';
################################################################################
around [ qw(get_by_id cancel_by_id) ] => sub {
my $orig = shift;
my $self = shift;
my $id = shift;
return $self->_validate_id($orig, $id, @_);
};
sub all {
my $self = shift;
my $args = shift;
......@@ -35,28 +27,6 @@ sub create {
});
}
sub get_by_id {
my $self = shift;
my $id = shift;
return $self->_single_view_get({
view => 'Job',
endpoint => '%s',
ids => [ $id ],
});
}
sub cancel_by_id {
my $self = shift;
my $id = shift;
return $self->_single_view_post({
view => 'Job',
endpoint => '%s/cancel',
ids => [ $id ],
});
}
sub get_by_type {
my $self = shift;
my $type = shift;
......@@ -124,18 +94,6 @@ L<Create a new job|https://api.mattermost.com/#tag/jobs%2Fpaths%2F~1jobs%2Fpost>
data => {},
});
=item C<get_by_id()>
L<Get a job|https://api.mattermost.com/#tag/jobs%2Fpaths%2F~1jobs~1%7Bjob_id%7D%2Fget>
my $response = $resource->get_by_id('JOB-ID-HERE');
=item C<cancel_by_id()>
L<Cancel a job|https://api.mattermost.com/#tag/jobs%2Fpaths%2F~1jobs~1%7Bjob_id%7D~1cancel%2Fpost>
my $response = $resource->cancel_by_id('JOB-ID-HERE');
=item C<get_by_type()>
L<https://api.mattermost.com/#tag/jobs%2Fpaths%2F~1jobs~1type~1%7Btype%7D%2Fget>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment