API-DeutscheBahn-Fahrplan
view release on metacpan or search on metacpan
lib/API/DeutscheBahn/Fahrplan.pm view on Meta::CPAN
Access token to sign requests. If provided the client will use the C<fahrplan_plus_url> endpoint.
=back
=cut
has 'fahrplan_free_url' => (
is => 'ro',
isa => 'Str',
default => 'https://api.deutschebahn.com/freeplan/v1',
);
has 'fahrplan_plus_url' => (
is => 'ro',
isa => 'Str',
default => 'https://api.deutschebahn.com/fahrplan-plus/v1',
);
has 'access_token' => (
is => 'ro',
isa => 'Str',
);
has '_client' => (
is => 'ro',
lazy => 1,
lib/API/DeutscheBahn/Fahrplan.pm view on Meta::CPAN
sub _build_client {
my $self = $_[0];
my @args;
push @args, 'Authorization' => sprintf( 'Bearer %s', $self->access_token )
if $self->access_token;
return HTTP::Tiny->new(
default_headers => {
'Accept' => 'application/json',
'User-Agent' => sprintf( 'Perl-%s::%s', __PACKAGE__, $VERSION ),
@args,
},
);
}
1;
=head1 LICENSE
t/01_main.t view on Meta::CPAN
my $fahrplan_plus = API::DeutscheBahn::Fahrplan->new( access_token => '123' );
isa_ok $fahrplan_plus, 'API::DeutscheBahn::Fahrplan';
# construct the user agent string
my $user_agent = sprintf 'Perl-API::DeutscheBahn::Fahrplan::%s',
$API::DeutscheBahn::Fahrplan::VERSION;
cmp_deeply $fahrplan_free->_client->default_headers,
{ Accept => 'application/json', 'User-Agent' => $user_agent },
'set correct headers for Fahrplan free';
cmp_deeply $fahrplan_plus->_client->default_headers,
{
Accept => 'application/json',
'User-Agent' => $user_agent,
Authorization => 'Bearer 123',
},
'set correct headers for Fahrplan plus';
note 'testing uri generation';
( run in 0.264 second using v1.01-cache-2.11-cpan-0a6323c29d9 )