line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CanvasCloud::API::Account::Report; |
2
|
|
|
|
|
|
|
$CanvasCloud::API::Account::Report::VERSION = '0.007'; |
3
|
|
|
|
|
|
|
# ABSTRACT: extends L<CanvasCloud::API::Account> |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1245
|
use Moose; |
|
1
|
|
|
|
|
482936
|
|
|
1
|
|
|
|
|
7
|
|
6
|
1
|
|
|
1
|
|
8335
|
use namespace::autoclean; |
|
1
|
|
|
|
|
8644
|
|
|
1
|
|
|
|
|
4
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends 'CanvasCloud::API::Account'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
augment 'uri' => sub { return '/reports'; }; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub list { |
15
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
16
|
1
|
|
|
|
|
11
|
return $self->send( $self->request( 'GET', $self->uri ) ); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub check { |
21
|
0
|
|
|
0
|
1
|
|
my ( $self, $report, $report_id ) = @_; |
22
|
0
|
|
|
|
|
|
return $self->send( $self->request( 'GET', join( '/', $self->uri, $report, $report_id ) ) ); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub run { |
27
|
0
|
|
|
0
|
1
|
|
my ( $self, $report, $args ) = @_; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $r = $self->request( 'POST', join( '/', $self->uri, $report ) ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
## Process Args |
32
|
0
|
0
|
0
|
|
|
|
if ( defined $args && ref( $args ) eq 'HASH' ) { |
33
|
0
|
|
|
|
|
|
$r->content( $self->encode_url( { map { $_ => $args->{$_} } keys %$args } ) ); |
|
0
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
return $self->send( $r ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub get { |
42
|
0
|
|
|
0
|
1
|
|
my ( $self, $report, $args ) = @_; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my $result = $self->run( $report, $args ); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
while ( $result->{status} =~ m/(running|created|compiling)/ ) { |
47
|
0
|
|
|
|
|
|
sleep 10; |
48
|
0
|
|
|
|
|
|
$result = $self->check( $report, $result->{id} ); |
49
|
|
|
|
|
|
|
#warn $result->{status}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
0
|
|
|
|
if ( exists $result->{attachment} && exists $result->{attachment}{url} ) { |
53
|
0
|
|
|
|
|
|
my $resp; |
54
|
0
|
|
|
|
|
|
my $attempts = 3; |
55
|
0
|
|
|
|
|
|
while ( $attempts > 0 ) { |
56
|
0
|
|
|
|
|
|
$resp = $self->ua->get( $result->{attachment}{url} ); ## Download report without using class specific headers |
57
|
0
|
0
|
|
|
|
|
if ( $resp->is_success ) { |
58
|
0
|
|
|
|
|
|
$attempts = 0; |
59
|
|
|
|
|
|
|
} else { |
60
|
0
|
|
|
|
|
|
sleep 20; ## sleep 20 seconds and try again |
61
|
0
|
|
|
|
|
|
$attempts--; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
0
|
0
|
|
|
|
|
die $resp->status_line unless ( $resp->is_success ); |
65
|
0
|
|
|
|
|
|
return $resp->decoded_content( charset => 'none' ); |
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
|
warn sprintf('Report->get ASSERT: id(%s) returned last status (%s)', $result->{id}, $result->{status} ); |
68
|
0
|
|
|
|
|
|
return undef; ## never should but nothing would be retured |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=pod |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=encoding UTF-8 |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 NAME |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
CanvasCloud::API::Account::Report - extends L<CanvasCloud::API::Account> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 VERSION |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
version 0.007 |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 uri |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
augments base uri to append '/reports' |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 METHODS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 list |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
return data object response from GET ->uri |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 check( $report, $report_id ) |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
return data object response from GET ->uri / $report / $report_id |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 run( $report, { 'parameters[enrollment_term_id]' => 1 } ) |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
return data object response from POST ->uri / $report |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
arguments are POST'ed |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
note(*): Most arguments will be in the form of parameters[named_argument_for_report] = "value" |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 get( $report, { 'parameters[enrollment_term_id]' => 1 } ) |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
perform the self->run( ... ) && self->check( ... ) until report is finished returning the text. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 AUTHOR |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Ted Katseres |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This software is copyright (c) 2019 by Ted Katseres. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
126
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |