Skip to content

Commit

Permalink
Add Vimeo as a provider
Browse files Browse the repository at this point in the history
Add Vimeo as a provider so as to take advantage of the oEmbed endpoint.

Vimeo has started to ban IP blocks from popular providers  (DigitalOcean, Vultr, Google Cloud) due to malicious behaviour from some IPs but subsequently affecting legitimate use cases. The ban results in 403 error codes when attempting to embed URLs using the standard "webpage" adapter, however oEmbed is unaffected.
  • Loading branch information
bendesilva committed Sep 16, 2019
1 parent 960bbd5 commit 55df81e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Adapters/Vimeo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Embed\Adapters;

use Embed\Http\Response;

/**
* Adapter to provide information from Vimeo.
* Required when Vimeo returns a 403 status code.
*/
class Vimeo extends Webpage
{
/**
* {@inheritdoc}
*/
public static function check(Response $response)
{
return $response->isValid([200, 403]) && $response->getUrl()->match([
'vimeo.com/*',
]);
}
}
9 changes: 9 additions & 0 deletions src/Providers/OEmbed/Vimeo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Embed\Providers\OEmbed;

class Vimeo extends EndPoint implements EndPointInterface
{
protected static $pattern = ['vimeo.com/*'];
protected static $endPoint = 'https://vimeo.com/api/oembed.json';
}
20 changes: 20 additions & 0 deletions tests/VimeoTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Embed\Tests;

class VimeoTest extends AbstractTestCase
{
public function testOne()
{
$this->assertEmbed(
'https://vimeo.com/235352744',
[
'title' => 'Vimeo Live is here',
'providerName' => 'Vimeo',
'width' => 640,
'height' => 360,
'code' => '<iframe src="https://player.vimeo.com/video/235352744?app_id=122963" width="640" height="360" frameborder="0" allow="autoplay; fullscreen" allowfullscreen title="Vimeo Live is here"></iframe>',
]
);
}
}

0 comments on commit 55df81e

Please sign in to comment.