Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValidYoutubeVideo Rule #145

Merged
merged 10 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# General
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this file is included in the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me neither, will remove this

.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


/vendor
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now you totally removed the .gitignore in the repository.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Korko thank you, how do you remove the single file from the pull request?

Copy link

@Korko Korko May 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how using the github interface but in git, should be simple:
git fetch
git checkout origin/master -- .gitignore
should reset the file to the master version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how using the github interface but in git, should be simple:
git fetch
git checkout origin/master -- .gitignore
should reset the file to the master version

Thank you, this worked and I've pushed to PR

composer.phar
composer.lock
.DS_Store
.idea
48 changes: 48 additions & 0 deletions src/Rules/ValidYoutubeVideo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Alaouy\Youtube\Rules;

use Illuminate\Contracts\Validation\Rule;
use Alaouy\Youtube\Facades\Youtube;

class ValidYoutubeVideo implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
try {
$videoId = Youtube::parseVidFromURL($value);
$video = Youtube::getVideoInfo($videoId);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should define the $part argument as ['id'] (cost 0 quota) as you only need to check, not fetch the actual video data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, will change this

} catch (\Exception $exception) {
return false;
}

return $video != false;
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'The supplied URL does not look like a Youtube URL.';
}
}