mirror of
https://gitlab.com/t6353/sharee.bike.git
synced 2025-02-22 11:46:27 +01:00
api sigo and bootstylesheet
This commit is contained in:
parent
d6c5a31192
commit
2a9099acd2
3 changed files with 49 additions and 14 deletions
|
@ -5,6 +5,8 @@ package APIsigoclient;
|
|||
#
|
||||
#Client for sigo
|
||||
#
|
||||
#380116b5-0522-43da-ab66-477744a731a3
|
||||
#
|
||||
#use lib qw(/var/www/copri-bike/shareeapp-fr01/src);
|
||||
use warnings;
|
||||
use strict;
|
||||
|
@ -46,7 +48,7 @@ my %apikeyconf = $aconf->getall;
|
|||
my $ua = LWP::UserAgent->new;
|
||||
$ua->agent("sharee sigo-client");
|
||||
my $size = $ua->max_size;
|
||||
my $bytes = 1000;
|
||||
my $bytes = 100000;
|
||||
$ua->max_size( $bytes );
|
||||
$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 {
|
||||
my $self = shift;
|
||||
my $uri_operator = shift || "";
|
||||
|
||||
open(FILE,">>$varenv{logdir}/APIsigo_client.log");
|
||||
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";
|
||||
print "$endpoint\n";
|
||||
|
||||
my $rest_json = "";
|
||||
my $ret_json = get_sigo("","$endpoint",$rest_json);
|
||||
eval {
|
||||
$response_in = decode_json($ret_json);
|
||||
print FILE "<--- get_bikes response_in:\n" . Dumper($response_in);
|
||||
};
|
||||
if ($@){
|
||||
print FILE "<--- failure get_bikes raw response_in:\n" . Dumper($ret_json) . "\n";
|
||||
warn $@;
|
||||
}
|
||||
my $return = {};
|
||||
my $rest_json = "";
|
||||
my $ret_json = get_sigo("","$endpoint",$rest_json);
|
||||
eval {
|
||||
$response_in = decode_json($ret_json);
|
||||
print FILE "<--- get_bikes response_in:\n" . Dumper($response_in);
|
||||
if(ref($response_in) eq "HASH"){
|
||||
foreach my $resp (@{ $response_in->{items} }) {
|
||||
#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
|
||||
|
|
|
@ -30,6 +30,7 @@ my $todo = $ARGV[1];
|
|||
|
||||
|
||||
if($todo eq "get_bikes"){
|
||||
$si->get_bikes();
|
||||
my $return = $si->get_bikes("https://shareeapp-sx.copri-bike.de");
|
||||
print Dumper($return);
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ my %apikeyconf = $aconf->getall;
|
|||
my $ua = LWP::UserAgent->new;
|
||||
$ua->agent("sharee veloclient");
|
||||
my $size = $ua->max_size;
|
||||
my $bytes = 1000;
|
||||
my $bytes = 100000;
|
||||
$ua->max_size( $bytes );
|
||||
$ua->default_header( 'Authorization' => $apikeyconf{velofaktur}->{bearer} );
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue