diff --git a/compass/app/Http/Controllers/Api.php b/compass/app/Http/Controllers/Api.php
index 2dbfc83..8569264 100644
--- a/compass/app/Http/Controllers/Api.php
+++ b/compass/app/Http/Controllers/Api.php
@@ -258,6 +258,14 @@ class Api extends BaseController
}
}
+ if($num > 0) {
+ // 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(['result' => 'ok', 'saved' => $num, 'trips' => $trips]))->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/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 @@
+
+
+
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.