Beispiel #1
0
 /**
  * Finds a gist by ID. Grabs data from Eloquent and GitHub API.
  *
  * @param $id
  * @return Gist
  */
 public function findById($id)
 {
     $eloquentGist = EloquentGist::find($id);
     $gh = new GitHub($eloquentGist->user);
     $gist = $gh->gist($id);
     $this->updateFromGitHub($id, $gist);
     return Gist::fromGitHub($eloquentGist, $gist);
 }
 /**
  * Handle the event.
  *
  * @param GistWasActivated $event
  */
 public function handle(GistWasActivated $event)
 {
     $gist = $event->gist;
     $gitHub = new GitHub($gist->user);
     if (!$gist->has_powered_by) {
         $gistUrl = route('gists.show', ['username' => $gist->user->username(), 'id' => $gist->id]);
         $comment = 'This gist has vote tracking powered by [Gist.vote](' . $gistUrl . ')';
         $gitHub->gistComment($gist->id, $comment);
         $gist->has_powered_by = true;
         $gist->save();
     }
 }
Beispiel #3
0
 /**
  * Saves a new comment/vote to a gist.
  *
  * @param Request $request
  * @param $username
  * @param $id
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function store(Request $request, $username, $id)
 {
     $gist = $this->repository->findById($id);
     if ($username != $gist->owner || $gist->isNotVoting()) {
         Flash::error($this->gistNotFoundMessage);
         return redirect('/');
     }
     $validator = Validator::make($request->all(), ['comment' => 'required']);
     if ($validator->fails()) {
         Flash::validation($validator->errors());
         return redirect()->back()->withInput();
     }
     $comment = Input::get('comment');
     $this->github->gistComment($id, $comment);
     Flash::success('Your comment was successfully posted.');
     return redirect()->route('gists.show', [$username, $id]);
 }