Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor scripts to extract variables to global scope #2

Merged
merged 7 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,4 @@ Support for barrier, ticket system and distance based tolling configurations
### Support for trucks based on [height, weight, harardous goods, etc.](https://github.com/mapup/toll-ptv-maps/wiki/4.-Truck-parameters-supported-by-TollGuru)
You can receive tolls based on vehicle height, weight etc., while calculating toll: "truckType","shippedHazardousGoods","tunnelCategory","truckRestrictionPenalty" and [more](https://github.com/mapup/toll-ptv-maps/wiki/4.-Truck-parameters-supported-by-TollGuru).








For more examples of the different ways in which the responses from this endpoint can be configured, you can refer to: [Our API parameter examples repository.](https://github.com/mapup/tollguru-api-parameter-examples/tree/main/request-bodies/02-Complete-Polyline-To-Toll)
4 changes: 2 additions & 2 deletions php/__test__/test_location.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
$locdata = array(
0 => array(
'from' => '2500 Victory Ave Dallas TX 75201',
'to' => '6969 US-380 Prosper TX 75078'
'from' => 'Philadelphia, PA',
'to' => 'New York, NY'
),
1 => Array (
'from' => '1205 W Trinity Mills Rd #112 Carrollton TX 75006',
Expand Down
56 changes: 35 additions & 21 deletions php/__test__/test_php_ptv.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?php
error_reporting(0);

$PTV_API_KEY = getenv('PTV_API_KEY');
$PTV_API_URL = "https://xserver2-europe-eu-test.cloud.ptvgroup.com/services/rs/XRoute/experimental/calculateRoute";

$TOLLGURU_API_KEY = getenv('TOLLGURU_API_KEY');
$TOLLGURU_API_URL = "https://apis.tollguru.com/toll/v2";
$POLYLINE_ENDPOINT = "complete-polyline-from-mapping-service";

//calling helper files...
require_once(__DIR__.'/test_location.php');
require_once(__DIR__.'/get_lat_long.php');
Expand All @@ -14,11 +21,20 @@
$destination_longitude = $destination['y'];
$destination_latitude = $destination['x'];

// Explore https://tollguru.com/toll-api-docs to get the best of all the parameters that Tollguru has to offer
$request_parameters = array(
"vehicle" => array(
"type" => "2AxlesAuto"
),
// Visit https://en.wikipedia.org/wiki/Unix_time to know the time format
"departure_time" => "2021-01-05T09:46:08Z"
);

//connecting to ptv...
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => 'https://xserver2-europe-eu-test.cloud.ptvgroup.com/services/rs/XRoute/experimental/calculateRoute',
CURLOPT_URL => $PTV_API_URL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
Expand Down Expand Up @@ -96,7 +112,7 @@
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Accept-Charset: utf-8',
'Authorization: Basic <Authorization key>'
'Authorization: Basic ' . $PTV_API_KEY
),
));

Expand Down Expand Up @@ -129,32 +145,30 @@
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);


$postdata = array(
"vehicleType" => "2AxlesAuto",
"source" => "here",
"departure_time" => "2021-01-15T13:46:17",
"polyline" => $p_ptv
"polyline" => $p_ptv,
...$request_parameters,
);

//json encoding source and polyline to send as postfields...
$encode_postData = json_encode($postdata);

curl_setopt_array($curl, array(
CURLOPT_URL => "https://dev.tollguru.com/v1/calc/route",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 300,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",


//sending ptv polyline to tollguru..
CURLOPT_POSTFIELDS => $encode_postData,
CURLOPT_HTTPHEADER => array(
"content-type: application/json",
"x-api-key: tollguru_api_key"),
CURLOPT_URL => $TOLLGURU_API_URL . "/" . $POLYLINE_ENDPOINT,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 300,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",


//sending ptv polyline to tollguru..
CURLOPT_POSTFIELDS => $encode_postData,
CURLOPT_HTTPHEADER => array(
"content-type: application/json",
"x-api-key: " . $TOLLGURU_API_KEY),
));

$response = curl_exec($curl);
Expand Down Expand Up @@ -213,4 +227,4 @@
fwrite($dumpFile, ",");
fwrite($dumpFile, $cash.PHP_EOL);
}
?>
?>
52 changes: 34 additions & 18 deletions php/php_curl_ptv.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
<?php
error_reporting(0);

$PTV_API_KEY = getenv('PTV_API_KEY');
$PTV_API_URL = "https://xserver2-europe-eu-test.cloud.ptvgroup.com/services/rs/XRoute/experimental/calculateRoute";

$TOLLGURU_API_KEY = getenv('TOLLGURU_API_KEY');
$TOLLGURU_API_URL = "https://apis.tollguru.com/toll/v2";
$POLYLINE_ENDPOINT = "complete-polyline-from-mapping-service";

// Explore https://tollguru.com/toll-api-docs to get the best of all the parameters that Tollguru has to offer
$request_parameters = array(
"vehicle" => array(
"type" => "2AxlesAuto"
),
// Visit https://en.wikipedia.org/wiki/Unix_time to know the time format
"departure_time" => "2021-01-05T09:46:08Z"
);

//connecting to ptv...
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => 'https://xserver2-europe-eu-test.cloud.ptvgroup.com/services/rs/XRoute/experimental/calculateRoute',
CURLOPT_URL => $PTV_API_URL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
Expand Down Expand Up @@ -79,7 +95,7 @@
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Accept-Charset: utf-8',
'Authorization: Basic <Authorization key>'
'Authorization: Basic ' . $PTV_API_KEY
),
));

Expand Down Expand Up @@ -109,27 +125,27 @@

$postdata = array(
"source" => "here",
"polyline" => $p_ptv
"polyline" => $p_ptv,
...$request_parameters,
);

//json encoding source and polyline to send as postfields..
$encode_postData = json_encode($postdata);

curl_setopt_array($curl, array(
CURLOPT_URL => "https://dev.tollguru.com/v1/calc/route",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",


//sending ptv polyline to tollguru
CURLOPT_POSTFIELDS => $encode_postData,
CURLOPT_HTTPHEADER => array(
"content-type: application/json",
"x-api-key: tollguru_api_key"),
CURLOPT_URL => $TOLLGURU_API_URL . "/" . $POLYLINE_ENDPOINT,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",

//sending ptv polyline to tollguru
CURLOPT_POSTFIELDS => $encode_postData,
CURLOPT_HTTPHEADER => array(
"content-type: application/json",
"x-api-key: " . $TOLLGURU_API_KEY),
));

$response = curl_exec($curl);
Expand All @@ -146,4 +162,4 @@
//response from tollguru..
$data = json_decode($response, true);
print_r($data['route']['costs']);
?>
?>
Loading
Loading