Skip to content

Commit

Permalink
Merge pull request #14 from mapup/refactor-scripts
Browse files Browse the repository at this point in the history
minor changes
  • Loading branch information
ajay-padwal-mapup authored Mar 12, 2024
2 parents 37fbbe6 + a070a81 commit 66607c4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 28 deletions.
4 changes: 2 additions & 2 deletions go/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var requestParams = map[string]interface{}{

func main() {

// Getting polyline from MapmyIndia
// Getting polyline from MapMyIndia

// Key for MapmyIndia
url := fmt.Sprintf("%s/%s/route_adv/driving/%v,%v;%v,%v?geometries=polyline&overview=full", MAPMYINDIA_API_URL, MAPMYINDIA_API_KEY, source_longitude, source_latitude, destination_longitude, destination_latitude)
Expand Down Expand Up @@ -80,7 +80,7 @@ func main() {
polyline := result["routes"].([]interface{})[0].(map[string]interface{})["geometry"].(string)
fmt.Printf("\n\n%v\n\n", polyline)

// Tollguru API request
// TollGuru API request

url_tollguru := fmt.Sprintf("%s/%s", TOLLGURU_API_URL, POLYLINE_ENDPOINT)

Expand Down
3 changes: 0 additions & 3 deletions javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ const getPolyline = body => polyline.encode(getPoints(JSON.parse(body)));

const getRoute = (cb) => request.get(url, cb);

//const handleRoute = (e, r, body) => console.log(getPolyline(body));
//getRoute(handleRoute)

const tollguruUrl = `${TOLLGURU_API_URL}/${POLYLINE_ENDPOINT}`;

const handleRoute = (e, r, body) => {
Expand Down
22 changes: 10 additions & 12 deletions php/php_curl_mapmyindia.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
$TOLLGURU_API_URL = "https://apis.tollguru.com/toll/v2";
$POLYLINE_ENDPOINT = "complete-polyline-from-mapping-service";

//Source and Destination Coordinates..
//New Delhi coordinates
// From and To locations
// New Delhi
$source_longitude='77.18609677688849';
$source_latitude='28.68932119156764';

Expand All @@ -28,7 +28,7 @@

$url = $MAPMYINDIA_API_URL.'/'.$MAPMYINDIA_API_KEY.'/route_adv/driving/'.$source_longitude.','.$source_latitude.';'.$destination_longitude.','.$destination_latitude.'?geometries=polyline&overview=full';

//connection..
// Connection
$mapmyindia = curl_init();

curl_setopt($mapmyindia, CURLOPT_SSL_VERIFYHOST, false);
Expand All @@ -37,7 +37,7 @@
curl_setopt($mapmyindia, CURLOPT_URL, $url);
curl_setopt($mapmyindia, CURLOPT_RETURNTRANSFER, true);

//getting response from mapmyindia api...
// Getting response from MapMyIndia API
$response = curl_exec($mapmyindia);
$err = curl_error($mapmyindia);

Expand All @@ -49,27 +49,25 @@
echo "200 : OK\n";
}

//extracting polyline from the JSON response..
// Extracting polyline from the JSON response
$data_mapmyindia = json_decode($response, true);

//polyline..
// Polyline
$polyline_mapmyindia = $data_mapmyindia['routes']['0']['geometry'];


//using tollguru API..
// Using TollGuru API
$curl = curl_init();

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);


$postdata = array(
"source" => "mapmyindia",
"polyline" => $polyline_mapmyindia,
...$request_parameters,
);

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

curl_setopt_array($curl, array(
Expand All @@ -82,7 +80,7 @@
CURLOPT_CUSTOMREQUEST => "POST",


//sending mapmyindia polyline to tollguru
// Sending MapMyIndia polyline to TollGuru
CURLOPT_POSTFIELDS => $encode_postData,
CURLOPT_HTTPHEADER => array(
"content-type: application/json",
Expand All @@ -100,7 +98,7 @@
echo "200 : OK\n";
}

//response from tollguru..
// Response from TollGuru
$data = var_dump(json_decode($response, true));
print_r($data);
?>
14 changes: 7 additions & 7 deletions python/mapmyindia.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"departure_time": "2021-01-05T09:46:08Z",
}


def get_polyline_from_mapmyindia(
source_longitude, source_latitude, destination_longitude, destination_latitude
):
Expand All @@ -45,9 +44,9 @@ def get_polyline_from_mapmyindia(
e=destination_longitude,
f=destination_latitude,
)
# converting the response to json
# Converting the response to JSON
response = requests.get(url).json()
# checking for errors in response
# Checking for errors in response
if str(response).find("message") > -1:
raise Exception(
"{}: {} , check latitude,longitude perhaps".format(
Expand All @@ -67,18 +66,19 @@ def get_polyline_from_mapmyindia(
def get_rates_from_tollguru(polyline):
"""Calling Tollguru API"""

# Tollguru querry url
# TollGuru query URL
Tolls_URL = f"{TOLLGURU_API_URL}/{POLYLINE_ENDPOINT}"
# Tollguru resquest parameters
# TollGuru request parameters
headers = {"Content-type": "application/json", "x-api-key": TOLLGURU_API_KEY}
params = {
**request_parameters,
"source": "mapmyindia",
"polyline": polyline, # this is polyline that we fetched from the mapping service
}
# Requesting Tollguru with parameters

# Requesting TollGuru with parameters
response_tollguru = requests.post(Tolls_URL, json=params, headers=headers).json()
# checking for errors or printing rates
# Checking for errors or printing rates
if str(response_tollguru).find("message") == -1:
return response_tollguru["route"]["costs"]
else:
Expand Down
7 changes: 3 additions & 4 deletions ruby/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
TOLLGURU_API_URL = "https://apis.tollguru.com/toll/v2"
POLYLINE_ENDPOINT = "complete-polyline-from-mapping-service"

# Source Details - New Delhi Lat-Long coordinates
source = { longitude: '77.18609', latitude: '28.68932' }
# Destination Details - Mumbai Lat-long coordinates
destination = { longitude: '72.89902', latitude: '19.09258' }
# From and To locations
source = { longitude: '77.18609', latitude: '28.68932' } # New Delhi
destination = { longitude: '72.89902', latitude: '19.09258' } # Mumbai

# Explore https://tollguru.com/toll-api-docs to get the best of all the parameters that tollguru has to offer
request_parameters = {
Expand Down

0 comments on commit 66607c4

Please sign in to comment.