Browse Source

merge conflict

pull/5/head
Aaron Parecki 7 years ago
parent
commit
962ef1cd86
8 changed files with 99 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. +1
    -0
      compass/.gitignore
  3. +6
    -0
      compass/app/Http/Controllers/Api.php
  4. +7
    -0
      compass/app/Http/Controllers/Controller.php
  5. +31
    -0
      compass/app/Jobs/NotifyOfNewLocations.php
  6. +5
    -0
      compass/app/Jobs/TripComplete.php
  7. +29
    -0
      compass/database/migrations/2017_05_21_093158_add_ping_urls.php
  8. +19
    -0
      compass/resources/views/settings.blade.php

+ 1
- 0
.gitignore View File

@ -0,0 +1 @@
.DS_Store

+ 1
- 0
compass/.gitignore View File

@ -1,3 +1,4 @@
/vendor
.env
.DS_Store
data/

+ 6
- 0
compass/app/Http/Controllers/Api.php View File

@ -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');

+ 7
- 0
compass/app/Http/Controllers/Controller.php View File

@ -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);
}
}

+ 31
- 0
compass/app/Jobs/NotifyOfNewLocations.php View File

@ -0,0 +1,31 @@
<?php
namespace App\Jobs;
use Log;
use App\Jobs\Job;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldQueue;
use DateTime, DateTimeZone;
class NotifyOfNewLocations extends Job implements SelfHandling, ShouldQueue
{
private $_dbid;
public function __construct($dbid, $data) {
$this->_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);
}
}
}

+ 5
- 0
compass/app/Jobs/TripComplete.php View File

@ -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'),

+ 29
- 0
compass/database/migrations/2017_05_21_093158_add_ping_urls.php View File

@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddPingUrls extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('databases', function ($table) {
$table->string('ping_urls', 1024);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

+ 19
- 0
compass/resources/views/settings.blade.php View File

@ -80,6 +80,25 @@
</form>
</div>
<br>
<h2>Ping on New Location</h2>
<p>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. <code>url=https://compass.p3k.io/api/last?token=xxxx</code>. Enter one or more URLs separated by whitespace.</p>
<div class="panel">
<form action="/settings/{{ $database->name }}" method="post" class="ui form">
<div class="field">
<label for="ping_urls">Ping URLs</label>
<textarea name="ping_urls" class="pure-input-1">{{ $database->ping_urls }}</textarea>
</div>
<button type="submit" class="ui button primary">Save</button>
</form>
</div>
<br>
</div>
<script>
jQuery(function($){

Loading…
Cancel
Save