예제 #1
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     DB::connection()->reconnect();
     $pin = Pin::findOrFail($this->pinId);
     $client = new Client(['base_uri' => 'https://timeline-api.getpebble.com/v1/user/pins/']);
     try {
         $response = $client->delete($pin->pin_id, ['headers' => ['Content-Type' => 'application/json', 'X-User-Token' => $this->timelineToken]]);
         if ($response->getStatusCode() === 200) {
             $pin->status = 'deleted';
             $pin->status_code = $response->getStatusCode();
             $pin->response = $response->getBody();
             $pin->update();
         } else {
             Log::error('Pin Delete Failure - ' . $pin->id . ' due to ' . $response->getStatusCode() . ' - ' . $response->getBody());
         }
     } catch (RequestException $e) {
         $responseCode = $e->getResponse()->getStatusCode();
         $responseBody = $e->getResponse()->getBody();
         Log::error('Pin Delete Failure - API - ' . $pin->id . ' due to ' . $responseCode . ' - ' . $responseBody);
     } catch (TransferException $e) {
         $responseCode = $e->getResponse()->getStatusCode();
         $responseBody = $e->getResponse()->getBody();
         Log::error('Pin Delete Failure - Network - ' . $pin->id . ' due to ' . $responseCode . ' - ' . $responseBody);
     }
 }
예제 #2
0
 public static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         // Ensure a unique API token is generated
         $pinId = 'timetable-' . Pin::generateUniquePinId();
         $model->pin_id = $pinId;
     });
 }