diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2019-06-20 18:08:42 +0200 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2019-06-20 18:08:42 +0200 |
commit | bafb529a0052e001ef739a98532892e9cbad1e97 (patch) | |
tree | ea03f1a36e65e6d386fa8e028851251f4193680d /lib/Travel/Status/DE | |
parent | 4f50886ba7a415ded18f5288bab5919aced86af7 (diff) |
Allow JSON input to be passed to constructor
Diffstat (limited to 'lib/Travel/Status/DE')
-rw-r--r-- | lib/Travel/Status/DE/DBWagenreihung.pm | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/Travel/Status/DE/DBWagenreihung.pm b/lib/Travel/Status/DE/DBWagenreihung.pm index 918dde9..4623225 100644 --- a/lib/Travel/Status/DE/DBWagenreihung.pm +++ b/lib/Travel/Status/DE/DBWagenreihung.pm @@ -30,6 +30,7 @@ sub new { developer_mode => $opt{developer_mode}, cache => $opt{cache}, departure => $opt{departure}, + from_json => $opt{from_json}, json => JSON->new, serializable => $opt{serializable}, train_number => $opt{train_number}, @@ -62,15 +63,19 @@ sub get_wagonorder { $datetime = $datetime->strftime('%Y%m%d%H%M'); } - my ( $content, $err ) - = $self->get_with_cache( $cache, - "${api_base}/${train_number}/${datetime}" ); + my $json = $self->{from_json}; - if ($err) { - $self->{errstr} = "Failed to fetch station data: $err"; - return; + if ( not $json ) { + my ( $content, $err ) + = $self->get_with_cache( $cache, + "${api_base}/${train_number}/${datetime}" ); + + if ($err) { + $self->{errstr} = "Failed to fetch station data: $err"; + return; + } + $json = $self->{json}->utf8->decode($content); } - my $json = $self->{json}->utf8->decode($content); if ( exists $json->{error} ) { $self->{errstr} = 'Backend error: ' . $json->{error}{msg}; |