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