Browse Source

don't run web hooks for manually created trips

pull/23/head
Aaron Parecki 6 years ago
parent
commit
1f67e854bb
No known key found for this signature in database GPG Key ID: 276C2817346D6056
1 changed files with 31 additions and 28 deletions
  1. +31
    -28
      compass/app/Jobs/TripComplete.php

+ 31
- 28
compass/app/Jobs/TripComplete.php View File

@ -34,34 +34,37 @@ class TripComplete extends Job implements SelfHandling, ShouldQueue
//////////////////////////////////
// Web Hooks
$urls = preg_split('/\s+/', $db->ping_urls);
// Build a trip object that looks like the active trip format from Overland
$trip = [
'trip' => [
'mode' => $this->_data['properties']['mode'],
'start_location' => $this->_data['properties']['start_location'],
'end_location' => $this->_data['properties']['end_location'],
'distance' => $this->_data['properties']['distance'],
'start' => $this->_data['properties']['start'],
'end' => $this->_data['properties']['end']
]
];
$trip = json_encode($trip, JSON_UNESCAPED_SLASHES);
foreach($urls as $url) {
if(trim($url)) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer '.$db->read_token,
'Compass-Url: '.env('BASE_URL').'api/trip?token='.$db->read_token
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $trip);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
Log::info("Notifying ".$url." of a completed trip");
// Don't run the web hooks for manually created trips
if(isset($this->_data['properties']['end_location'])) {
$urls = preg_split('/\s+/', $db->ping_urls);
// Build a trip object that looks like the active trip format from Overland
$trip = [
'trip' => [
'mode' => $this->_data['properties']['mode'],
'start_location' => $this->_data['properties']['start_location'],
'end_location' => $this->_data['properties']['end_location'],
'distance' => $this->_data['properties']['distance'],
'start' => $this->_data['properties']['start'],
'end' => $this->_data['properties']['end']
]
];
$trip = json_encode($trip, JSON_UNESCAPED_SLASHES);
foreach($urls as $url) {
if(trim($url)) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer '.$db->read_token,
'Compass-Url: '.env('BASE_URL').'api/trip?token='.$db->read_token
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $trip);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
Log::info("Notifying ".$url." of a completed trip");
}
}
}

Loading…
Cancel
Save