Skip to content

Commit eb05178

Browse files
authored
Merge pull request #333 from royharink/feature/add-vimeo-support
Added an Adapter and OEmbed provider for Vimeo urls.
2 parents d7f4e2f + be11826 commit eb05178

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

src/Adapters/Vimeo.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Embed\Adapters;
4+
5+
use Embed\Request;
6+
use Embed\Providers;
7+
8+
/**
9+
* Adapter to provide information from Vimeo.
10+
* Required when Vimeo returns a 403 status code.
11+
*/
12+
class Vimeo extends Webpage implements AdapterInterface
13+
{
14+
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
public static function check(Request $request)
19+
{
20+
return $request->isValid([200, 403]) && $request->match([
21+
'https?://*.vimeo.com*',
22+
'https?://vimeo.com*',
23+
]);
24+
}
25+
26+
/**
27+
* @inheritDoc
28+
*/
29+
protected function run()
30+
{
31+
if ($this->request->getHttpCode() === 403) {
32+
$this->addProvider('oembed', new Providers\OEmbed());
33+
34+
return;
35+
}
36+
37+
parent::run();
38+
}
39+
40+
}

src/Providers/OEmbed/Vimeo.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Embed\Providers\OEmbed;
4+
5+
use Embed\Url;
6+
7+
class Vimeo extends OEmbedImplementation
8+
{
9+
10+
/**
11+
* @inheritDoc
12+
*/
13+
public static function getEndPoint(Url $url)
14+
{
15+
return 'https://vimeo.com/api/oembed.json';
16+
}
17+
18+
/**
19+
* @inheritDoc
20+
*/
21+
public static function getPatterns()
22+
{
23+
return [
24+
'https?://*.vimeo.com*',
25+
'https?://vimeo.com*',
26+
];
27+
}
28+
29+
/**
30+
* @inheritDoc
31+
*/
32+
public static function getParams(Url $url)
33+
{
34+
return [
35+
'url' => $url->withScheme('http')->getUrl(),
36+
];
37+
}
38+
}

0 commit comments

Comments
 (0)