Commit bafb529a authored by Daniel Friesel's avatar Daniel Friesel
Browse files

Allow JSON input to be passed to constructor

parent 4f50886b
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -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,6 +63,9 @@ sub get_wagonorder {
		$datetime = $datetime->strftime('%Y%m%d%H%M');
	}

	my $json = $self->{from_json};

	if ( not $json ) {
		my ( $content, $err )
		  = $self->get_with_cache( $cache,
			"${api_base}/${train_number}/${datetime}" );
@@ -70,7 +74,8 @@ sub get_wagonorder {
			$self->{errstr} = "Failed to fetch station data: $err";
			return;
		}
	my $json = $self->{json}->utf8->decode($content);
		$json = $self->{json}->utf8->decode($content);
	}

	if ( exists $json->{error} ) {
		$self->{errstr} = 'Backend error: ' . $json->{error}{msg};