-
-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #333 from royharink/feature/add-vimeo-support
Added an Adapter and OEmbed provider for Vimeo urls.
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Embed\Adapters; | ||
|
||
use Embed\Request; | ||
use Embed\Providers; | ||
|
||
/** | ||
* Adapter to provide information from Vimeo. | ||
* Required when Vimeo returns a 403 status code. | ||
*/ | ||
class Vimeo extends Webpage implements AdapterInterface | ||
{ | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function check(Request $request) | ||
{ | ||
return $request->isValid([200, 403]) && $request->match([ | ||
'https?://*.vimeo.com*', | ||
'https?://vimeo.com*', | ||
]); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function run() | ||
{ | ||
if ($this->request->getHttpCode() === 403) { | ||
$this->addProvider('oembed', new Providers\OEmbed()); | ||
|
||
return; | ||
} | ||
|
||
parent::run(); | ||
} | ||
|
||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace Embed\Providers\OEmbed; | ||
|
||
use Embed\Url; | ||
|
||
class Vimeo extends OEmbedImplementation | ||
{ | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function getEndPoint(Url $url) | ||
{ | ||
return 'https://vimeo.com/api/oembed.json'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function getPatterns() | ||
{ | ||
return [ | ||
'https?://*.vimeo.com*', | ||
'https?://vimeo.com*', | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function getParams(Url $url) | ||
{ | ||
return [ | ||
'url' => $url->withScheme('http')->getUrl(), | ||
]; | ||
} | ||
} |