File Coverage

blib/lib/WebService/Toggl/Role/Report.pm
Criterion Covered Total %
statement 12 23 52.1
branch n/a
condition n/a
subroutine 4 10 40.0
pod n/a
total 16 33 48.4


line stmt bran cond sub pod time code
1             package WebService::Toggl::Role::Report;
2              
3 1     1   1192 use DateTime;
  1         95145  
  1         35  
4 1     1   7 use Sub::Quote qw(quote_sub);
  1         2  
  1         59  
5 1     1   5 use Types::Standard qw(Int InstanceOf);
  1         2  
  1         9  
6              
7 1     1   500 use Moo::Role;
  1         2  
  1         10  
8             with 'WebService::Toggl::Role::Base';
9              
10             requires 'api_path';
11              
12             has base_url => (is => 'ro', default => '/reports/api/v2');
13              
14             has my_url => (is => 'ro', lazy => 1, builder => 1);
15 0     0     sub _build_my_url { $_[0]->base_url . '/' . $_[0]->api_path }
16              
17             has raw => (is => 'ro', lazy => 1, builder => 1);
18             sub _build_raw {
19 0     0     my ($self) = @_;
20 0           my $response = $self->api_get($self->my_url, $self->req_params);
21 0           return $response->data;
22             }
23 0     0     sub _req_params { [qw(workspace_id since until)] }
24             sub req_params {
25 0     0     my ($self) = @_;
26             return {
27 0           (map {$_ => $_[0]->$_()} @{ $_[0]->_req_params() }),
  0            
  0            
28             since => $self->since->ymd(), until => $self->until->ymd,
29             user_agent => $self->_request->user_agent_id,
30             };
31             }
32              
33             # request params
34             has workspace_id => (is => 'ro', isa => Int, required => 1,);
35             has since => (is => 'ro', isa => InstanceOf['DateTime'], lazy => 1, builder => 1,);
36             has until => (is => 'ro', isa => InstanceOf['DateTime'], lazy => 1, builder => 1,);
37 0     0     sub _build_since { shift->until->clone->subtract(days => 6) }
38 0     0     sub _build_until { DateTime->now }
39              
40              
41             # response params
42             has $_ => (is => 'ro', lazy => 1, builder => quote_sub(qq| \$_[0]->raw->{$_} |))
43             for (qw(total_grand total_billable total_currencies data));
44              
45              
46              
47             1;
48             __END__
49              
50             =encoding utf-8
51              
52             =head1 NAME
53              
54             WebService::Toggl::Report - Base Role for WebService::Toggl::Report objects
55              
56             =head1 DESCRIPTION
57              
58             This role provide behavoir common to all C<WebService::Toggl::Report::>
59             objects.
60              
61             =head1 REQUIRES
62              
63             =head2 api_path
64              
65             Consuming classes must provide their endpoint on the Reports API.
66             Ex. The L<WebService::Toggl::Report::Summary> object's C<api_path> is
67             C<summary>.
68              
69             =head1 ATTRIBUTES
70              
71             =head2 base_url
72              
73             The base of the URL for the Toggl Reports API. Defaults to C</reports/api/v8>.
74              
75             =head2 my_url
76              
77             URL for the current Report object.
78              
79             =head2 raw
80              
81             The raw data structure returned by querying the API.
82              
83             =head1 REQUEST ATTRIBUTES
84              
85             =head2 workspace_id
86              
87             The ID of the workspace for which the report is being generated.
88              
89             =head2 since / until
90              
91             L<DateTime> objects representing the bounding period for the report.
92             Defaults to C<until> = today, C<since> = today - 6 days
93              
94             =head1 RESPONSE ATTRIBUTES
95              
96             These attributes are common to all reports. See the L<Toggl API
97             Docs|https://github.com/toggl/toggl_api_docs/blob/master/reports.md#successful-response>
98             for more information
99              
100             =head2 total_grand
101              
102             Total time (in milliseconds) represented by the entries in the report.
103              
104             =head2 total_billable
105              
106             Total billable time (in milliseconds) represented by the entries in
107             the report.
108              
109             =head2 total_currencies
110              
111             Total earnings represented by the entries in the report.
112              
113             =head2 data
114              
115             The detailed contents of the report. This will differ between each
116             type of report.
117              
118              
119             =head1 LICENSE
120              
121             Copyright (C) Fitz Elliott.
122              
123             This library is free software; you can redistribute it and/or modify
124             it under the same terms as Perl itself.
125              
126             =head1 AUTHOR
127              
128             Fitz Elliott E<lt>felliott@fiskur.orgE<gt>
129              
130             =cut