diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/compass/.gitignore b/compass/.gitignore index 24ba008..58dd97b 100644 --- a/compass/.gitignore +++ b/compass/.gitignore @@ -1,3 +1,4 @@ /vendor .env .DS_Store +data/ diff --git a/compass/app/Http/Controllers/Api.php b/compass/app/Http/Controllers/Api.php index 069fb31..bb9ac28 100644 --- a/compass/app/Http/Controllers/Api.php +++ b/compass/app/Http/Controllers/Api.php @@ -275,6 +275,12 @@ class Api extends BaseController 'country' => $geocode->country ]; #$response['geocode'] = null; + + // Notify subscribers that new data is available + if($db->ping_urls) { + $job = (new NotifyOfNewLocations($db->id))->onQueue('compass'); + $this->dispatch($job); + } } return response(json_encode($response))->header('Content-Type', 'application/json'); diff --git a/compass/app/Http/Controllers/Controller.php b/compass/app/Http/Controllers/Controller.php index 9f87c29..77b4f7f 100644 --- a/compass/app/Http/Controllers/Controller.php +++ b/compass/app/Http/Controllers/Controller.php @@ -181,6 +181,13 @@ class Controller extends BaseController 'micropub_token' => $request->input('micropub_token'), ]); + return redirect('/settings/'.$db->name); + } else if($request->input('ping_urls')) { + DB::table('databases')->where('id', $db->id) + ->update([ + 'ping_urls' => $request->input('ping_urls'), + ]); + return redirect('/settings/'.$db->name); } } diff --git a/compass/app/Jobs/NotifyOfNewLocations.php b/compass/app/Jobs/NotifyOfNewLocations.php new file mode 100644 index 0000000..52e49d4 --- /dev/null +++ b/compass/app/Jobs/NotifyOfNewLocations.php @@ -0,0 +1,31 @@ +_dbid = $dbid; + } + + public function handle() { + $db = DB::table('databases')->where('id','=',$this->_dbid)->first(); + $urls = preg_split('/\s+/', $db->ping_urls); + foreach($urls as $url) { + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([ + 'url' => env('BASE_URL').'api/last?token='.$db->token.'&geocode=1' + ])); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_exec($ch); + } + } +} diff --git a/compass/app/Jobs/TripComplete.php b/compass/app/Jobs/TripComplete.php index 8920e01..7600318 100644 --- a/compass/app/Jobs/TripComplete.php +++ b/compass/app/Jobs/TripComplete.php @@ -129,6 +129,11 @@ class TripComplete extends Job implements SelfHandling, ShouldQueue $endDate->setTimeZone(new DateTimeZone($end->timezone)); } + if($endDate->format('U') - $startDate->format('U') < 15) { + Log::info("Skipping trip since it was too short"); + return; + } + $params = [ 'h' => 'entry', 'published' => $endDate->format('c'), diff --git a/compass/database/migrations/2017_05_21_093158_add_ping_urls.php b/compass/database/migrations/2017_05_21_093158_add_ping_urls.php new file mode 100644 index 0000000..4a381f8 --- /dev/null +++ b/compass/database/migrations/2017_05_21_093158_add_ping_urls.php @@ -0,0 +1,29 @@ +string('ping_urls', 1024); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/compass/resources/views/settings.blade.php b/compass/resources/views/settings.blade.php index 43c9bb5..b334d00 100644 --- a/compass/resources/views/settings.blade.php +++ b/compass/resources/views/settings.blade.php @@ -80,6 +80,25 @@ +
+ +

Ping on New Location

+ +

Enter one or more URLs to ping when new location data is available. This will send a POST request to the URLs with the URL to fetch the last location from the database, e.g. url=https://compass.p3k.io/api/last?token=xxxx. Enter one or more URLs separated by whitespace.

+ +
+
+
+ + +
+ + +
+
+ +
+