Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
✨ Watch Google resources
- Loading branch information
1 parent
3e8b4aa
commit 3e75ff9
Showing
5 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Jobs\WatchGoogleResource; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
|
||
class WatchGoogleCalendars extends WatchGoogleResource implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
public function getGoogleRequest($service, $channel) | ||
{ | ||
return $service->calendarList->watch($channel); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Jobs\WatchGoogleResource; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
|
||
class WatchGoogleEvents extends WatchGoogleResource implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
public function getGoogleRequest($service, $channel) | ||
{ | ||
return $service->events->watch( | ||
$this->synchronizable->google_id, $channel | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use Illuminate\Support\Carbon; | ||
|
||
abstract class WatchGoogleResource | ||
{ | ||
protected $synchronizable; | ||
|
||
public function __construct($synchronizable) | ||
{ | ||
$this->synchronizable = $synchronizable; | ||
} | ||
|
||
public function handle() | ||
{ | ||
$synchronization = $this->synchronizable->synchronization; | ||
|
||
try { | ||
$response = $this->getGoogleRequest( | ||
$this->synchronizable->getGoogleService('Calendar'), | ||
$synchronization->asGoogleChannel() | ||
); | ||
|
||
$synchronization->update([ | ||
'resource_id' => $response->getResourceId(), | ||
'expired_at' => Carbon::createFromTimestampMs($response->getExpiration()) | ||
]); | ||
|
||
} catch (\Google_Service_Exception $e) { | ||
// If we reach an error at this point, it is likely that | ||
// push notifications are not allowed for this resource. | ||
// Instead we will sync it manually at regular interval. | ||
} | ||
} | ||
|
||
abstract public function getGoogleRequest($service, $channel); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters