/** * Creates a new Gist from the GitHub API. * * @param EloquentGist $eloquentGist * @param $gitHubGist * @return Gist */ public static function fromGitHub(EloquentGist $eloquentGist, $gitHubGist) { $gist = new self(); $gist->id = $gitHubGist['gist']['id']; $gist->description = $gitHubGist['gist']['description']; $gist->public = $gitHubGist['gist']['public']; $gist->voting = $eloquentGist->enable_voting; $comments = []; if (is_array($gitHubGist['comments'])) { foreach ($gitHubGist['comments'] as $comment) { $comments[] = new GistComment($comment, $gist); } } $gist->comments = collect($comments); $gist->commentCount = $gist->comments->count(); $files = []; if (is_array($gitHubGist['gist']['files'])) { foreach ($gitHubGist['gist']['files'] as $file) { $files[] = new GistFile($gist, $file['filename'], $file['language'], $file['content']); } } $gist->files = collect($files); $gist->fileCount = $gist->files->count(); $gist->created_at = Carbon::parse($gitHubGist['gist']['created_at']); $gist->updated_at = Carbon::parse($gitHubGist['gist']['updated_at']); $gist->owner = $gitHubGist['gist']['owner']['login']; $gist->setUserEntity($eloquentGist); return $gist; }