Skip to content

Commit

Permalink
Merge pull request #333 from royharink/feature/add-vimeo-support
Browse files Browse the repository at this point in the history
Added an Adapter and OEmbed provider for Vimeo urls.
  • Loading branch information
oscarotero authored Jan 31, 2020
2 parents d7f4e2f + be11826 commit eb05178
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Adapters/Vimeo.php
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();
}

}
38 changes: 38 additions & 0 deletions src/Providers/OEmbed/Vimeo.php
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(),
];
}
}

0 comments on commit eb05178

Please sign in to comment.