App/Chart/DownloadHandler/DividendsPage.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 80 CC 2 SCAR 9.8
CC
2
Cov
0%
dividends_download
6.0
new
2.0
BEGIN
2.0
CRAP 2.7
1 # Copyright 2008, 2009, 2010, 2011, 2024 Kevin Ryde
2  
3 # This file is part of Chart.
4 #
5 # Chart is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3, or (at your option) any later version.
8 #
9 # Chart is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Chart. If not, see <http://www.gnu.org/licenses/>.
16  
17 package App::Chart::DownloadHandler::DividendsPage;
18 use 5.010;
19 use strict;
20 use warnings;
21 use Carp;
22 # use Locale::TextDomain ('App-Chart');
23  
24 use base 'App::Chart::DownloadHandler';
25 use App::Chart;
26 use App::Chart::Database;
27 use App::Chart::Download;
28  
29  
30 use constant DEFAULT_DIVIDENDS_CHECK_DAYS => 3;
31  
32 sub new {
33 my ($class, %options) = @_;
34 $options{'name'} or croak "missing name for ".__PACKAGE__;
35 $options{'key'} or croak "missing key for ".__PACKAGE__;
36 $options{'url'} or croak "missing url for ".__PACKAGE__;
37 $options{'recheck_days'} ||= DEFAULT_DIVIDENDS_CHECK_DAYS;
38 return $class->SUPER::new (%options,
39 proc => \&dividends_download,
40 proc_with_self => 1,
41 recheck_key => $options{'key'} . '-timestamp');
42 }
43  
44 sub dividends_download {
45 my ($self, $symbol_list) = @_;
46 my $pred = $self->{'pred'};
47  
48 my $key = $self->{'key'};
49 my $etag_key = $key . '-etag';
50 my $lastmod_key = $key . '-last-modified';
51 my $etag = App::Chart::Database->read_extra ('', $etag_key);
52 my $lastmod = App::Chart::Database->read_extra ('', $lastmod_key);
53  
54 App::Chart::Download::status ($self->{'name'});
55 my $resp = App::Chart::Download->get ($self->{'url'},
56 etag => $etag,
57 last_modified => $lastmod);
58  
59 my $h;
60 if ($resp->is_success) {
61 # got data
62 $h = $self->{'parse'}->($resp);
63 $h->{'url_tags_key'} = $key;
64 } else {
65 # no data, 304 unmodified, empty to just update times
66 $h = { dividends => [] };
67 }
68 $h->{'recheck_key'} = $self->{'recheck_key'};
69 $h->{'recheck_pred'} = $self->{'pred'};
70  
71 App::Chart::Download::write_daily_group ($h);
72 }
73  
74 1;
75 __END__