File Coverage

blib/lib/WebService/Mattermost/V4/API/Object.pm
Criterion Covered Total %
statement 19 22 86.3
branch 1 2 50.0
condition n/a
subroutine 6 7 85.7
pod n/a
total 26 31 83.8


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

3: # ABSTRACT: Base class for results returned from the API. 4:
5: use DateTime;
6: use Moo;
7: use Types::Standard qw(HashRef InstanceOf Str);
8:
9: use WebService::Mattermost::V4::API;
10:
11: with qw(
12: WebService::Mattermost::Role::Returns
13: WebService::Mattermost::V4::API::Role::NewRelatedResource
14: );
15:
16: ################################################################################
17:
18: has [ qw(auth_token base_url) ] => (is => 'ro', isa => Str, required => 1);
19: has raw_data => (is => 'ro', isa => HashRef, required => 1);
20:
21: has api => (is => 'ro', isa => InstanceOf['WebService::Mattermost::V4::API'], lazy => 1, builder => 1);
22:
23: ################################################################################
24:
25: sub _from_epoch {
26: my $self = shift;
27: my $unix_timestamp = shift;
28:
29: return undef unless $unix_timestamp;
30:
31: # The timestamp is too precise - trim away the end
32: $unix_timestamp =~ s/...$//s;
33:
34: return DateTime->from_epoch(epoch => $unix_timestamp);
35: }
36:
37: sub _related_args {
38: my $self = shift;
39: my $args = shift;
40:
41: return {
42: auth_token => $self->auth_token,
43: base_url => $self->base_url,
44: raw_data => $args,
45: };
46: }
47:
48: ################################################################################
49:
50: sub _build_api {
51: my $self = shift;
52:
53: return WebService::Mattermost::V4::API->new({
54: auth_token => $self->auth_token,
55: base_url => $self->base_url,
56: });
57: }
58:
59: ################################################################################
60:
61: 1;
62:
63: __END__
64:
65: =pod
66:
67: =encoding UTF-8
68:
69: =head1 NAME
70:
71: WebService::Mattermost::V4::API::Object - Base class for results returned from the API.
72:
73: =head1 VERSION
74:
75: version 0.28
76:
77: =head1 DESCRIPTION
78:
79: Base class for wrappers for individual results returned from the Mattermost API.
80:
81: =head2 METHODS
82:
83: =over 4
84:
85: =item C<_from_epoch()>
86:
87: Converts a UNIX timestamp from Mattermost to a DateTime object. The last three
88: characters of the timestamp are trimmed to make it the expected length.
89:
90: =back
91:
92: =head2 ATTRIBUTES
93:
94: =over 4
95:
96: =item C<raw_data>
97:
98: The raw response from Mattermost.
99:
100: =item C<auth_token>
101:
102: The current session's auth token, for rebuilding the API.
103:
104: =item C<base_url>
105:
106: The server's base URL.
107:
108: =item C<api>
109:
110: API access for the Object classes.
111:
112: =back
113:
114: =head1 AUTHOR
115:
116: Mike Jones <mike@netsplit.org.uk>
117:
118: =head1 COPYRIGHT AND LICENSE
119:
120: This software is Copyright (c) 2020 by Mike Jones.
121:
122: This is free software, licensed under:
123:
124: The MIT (X11) License
125:
126: =cut
127: