api sigo and bootstylesheet

This commit is contained in:
Rainer Gümpelein 2022-03-31 07:28:37 +02:00
parent d6c5a31192
commit 2a9099acd2
3 changed files with 49 additions and 14 deletions

View file

@ -5,6 +5,8 @@ package APIsigoclient;
# #
#Client for sigo #Client for sigo
# #
#380116b5-0522-43da-ab66-477744a731a3
#
#use lib qw(/var/www/copri-bike/shareeapp-fr01/src); #use lib qw(/var/www/copri-bike/shareeapp-fr01/src);
use warnings; use warnings;
use strict; use strict;
@ -46,7 +48,7 @@ my %apikeyconf = $aconf->getall;
my $ua = LWP::UserAgent->new; my $ua = LWP::UserAgent->new;
$ua->agent("sharee sigo-client"); $ua->agent("sharee sigo-client");
my $size = $ua->max_size; my $size = $ua->max_size;
my $bytes = 1000; my $bytes = 100000;
$ua->max_size( $bytes ); $ua->max_size( $bytes );
$ua->default_header( 'x-api-key' => $apikeyconf{sigo}->{api_key} ); $ua->default_header( 'x-api-key' => $apikeyconf{sigo}->{api_key} );
@ -61,6 +63,7 @@ print FILE "\n*** $now_dt 'sigo client' \n";
sub get_bikes { sub get_bikes {
my $self = shift; my $self = shift;
my $uri_operator = shift || "";
open(FILE,">>$varenv{logdir}/APIsigo_client.log"); open(FILE,">>$varenv{logdir}/APIsigo_client.log");
print FILE "\n*** $now_dt 'sigo client' \n"; print FILE "\n*** $now_dt 'sigo client' \n";
@ -68,18 +71,49 @@ sub get_bikes {
my $endpoint = "https://sigo.dev.sigo.green/api/v1/bikes"; my $endpoint = "https://sigo.dev.sigo.green/api/v1/bikes";
print "$endpoint\n"; print "$endpoint\n";
my $rest_json = ""; my $return = {};
my $ret_json = get_sigo("","$endpoint",$rest_json); my $rest_json = "";
eval { my $ret_json = get_sigo("","$endpoint",$rest_json);
$response_in = decode_json($ret_json); eval {
print FILE "<--- get_bikes response_in:\n" . Dumper($response_in); $response_in = decode_json($ret_json);
}; print FILE "<--- get_bikes response_in:\n" . Dumper($response_in);
if ($@){ if(ref($response_in) eq "HASH"){
print FILE "<--- failure get_bikes raw response_in:\n" . Dumper($ret_json) . "\n"; foreach my $resp (@{ $response_in->{items} }) {
warn $@; #print Dumper($resp) . "\n";
} $return->{$resp->{mobile_bike_id}}->{bike} = "$resp->{mobile_bike_id}" || "";
$return->{$resp->{mobile_bike_id}}->{station} = "$resp->{site}->{address}" || "";
$return->{$resp->{mobile_bike_id}}->{uri_operator} = "$uri_operator" || "";
$return->{$resp->{mobile_bike_id}}->{description} = "E-Lastenrad";
$return->{$resp->{mobile_bike_id}}->{gps}->{latitude} = $resp->{site}->{lat} || "";
$return->{$resp->{mobile_bike_id}}->{gps}->{longitude} = $resp->{site}->{lon} || "";
$return->{$resp->{mobile_bike_id}}->{bike_charge} = "$resp->{energy_level}" || "0";
$return->{$resp->{mobile_bike_id}}->{state} = "";
if($resp->{status} eq "ACTIVE"){#?
$return->{$resp->{mobile_bike_id}}->{state} = "available";
}elsif($resp->{status} eq "MAINTANANCE"){
$return->{$resp->{mobile_bike_id}}->{state} = "maintanance";
}elsif($resp->{status} eq "OPERATION"){#?
$return->{$resp->{mobile_bike_id}}->{state} = "occupied";
}
close(FILE); $return->{$resp->{mobile_bike_id}}->{lock_state} = "unlocked";
if($resp->{state}->{locked}){
$return->{$resp->{mobile_bike_id}}->{lock_state} = "locked";
}
$return->{$resp->{mobile_bike_id}}->{system} = "sigo";
$return->{$resp->{mobile_bike_id}}->{unlock_allowed} = "1";
$return->{$resp->{mobile_bike_id}}->{tariff_description} = {};
}
}
};
if ($@){
print FILE "<--- failure get_bikes raw response_in:\n" . Dumper($ret_json) . "\n";
warn $@;
}
close(FILE);
return $return;
} }
#main GET #main GET

View file

@ -30,6 +30,7 @@ my $todo = $ARGV[1];
if($todo eq "get_bikes"){ if($todo eq "get_bikes"){
$si->get_bikes(); my $return = $si->get_bikes("https://shareeapp-sx.copri-bike.de");
print Dumper($return);
} }

View file

@ -48,7 +48,7 @@ my %apikeyconf = $aconf->getall;
my $ua = LWP::UserAgent->new; my $ua = LWP::UserAgent->new;
$ua->agent("sharee veloclient"); $ua->agent("sharee veloclient");
my $size = $ua->max_size; my $size = $ua->max_size;
my $bytes = 1000; my $bytes = 100000;
$ua->max_size( $bytes ); $ua->max_size( $bytes );
$ua->default_header( 'Authorization' => $apikeyconf{velofaktur}->{bearer} ); $ua->default_header( 'Authorization' => $apikeyconf{velofaktur}->{bearer} );