Skip to content

Commit

Permalink
improved oembed detection
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed May 30, 2020
1 parent e623b6b commit 2c73fb7
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Providers/OEmbed/Deviantart.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function getEndPoint()
{
return Url::create(static::$endPoint)
->withQueryParameters([
'url' => (string) $this->response->getUrl(),
'url' => (string) $this->getUrl(),
'format' => 'json',
'for' => 'embed',
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/OEmbed/Embedly.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getEndPoint()
{
return Url::create('http://api.embed.ly/1/oembed')
->withQueryParameters([
'url' => (string) $this->response->getUrl(),
'url' => (string) $this->getUrl(),

This comment has been minimized.

Copy link
@NathanBaulch

NathanBaulch Jul 15, 2022

Embedly doesn't extend EndPoint so this line fails since there is no getUrl method.

This comment has been minimized.

Copy link
@oscarotero

oscarotero Jul 15, 2022

Author Owner

God catch. Thanks

This comment has been minimized.

Copy link
@oscarotero

oscarotero Jul 15, 2022

Author Owner

God catch. Thanks

'format' => 'json',
'key' => $this->key,
]);
Expand Down
15 changes: 13 additions & 2 deletions src/Providers/OEmbed/EndPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
abstract class EndPoint
{
protected $response;
protected $url;
protected static $pattern;
protected static $endPoint;

Expand All @@ -25,16 +26,21 @@ public static function create(Adapter $adapter)
if ($response->getUrl()->match(static::$pattern)) {
return new static($response);
}

if ($response->getStartingUrl()->match(static::$pattern)) {
return new static($response, $response->getStartingUrl());
}
}

/**
* Constructor.
*
* @param Response $response
*/
protected function __construct(Response $response)
protected function __construct(Response $response, Url $url = null)
{
$this->response = $response;
$this->url = $url;
}

/**
Expand All @@ -44,8 +50,13 @@ public function getEndPoint()
{
return Url::create(static::$endPoint)
->withQueryParameters([
'url' => (string) $this->response->getUrl(),
'url' => (string) $this->getUrl(),
'format' => 'json',
]);
}

public function getUrl()
{
return $this->url ?: $this->response->getUrl();
}
}
4 changes: 2 additions & 2 deletions src/Providers/OEmbed/Facebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ class Facebook extends EndPoint implements EndPointInterface
*/
public function getEndPoint()
{
if ($this->response->getUrl()->match(['*/videos/*', '/video.php'])) {
if ($this->getUrl()->match(['*/videos/*', '/video.php'])) {
$endPoint = Url::create('https://www.facebook.com/plugins/video/oembed.json');
} else {
$endPoint = Url::create('https://www.facebook.com/plugins/post/oembed.json');
}

return $endPoint->withQueryParameters([
'url' => (string) $this->response->getUrl(),
'url' => (string) $this->getUrl(),
'format' => 'json',
]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/OEmbed/Iframely.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getEndPoint()
{
return Url::create('http://open.iframe.ly/api/oembed')
->withQueryParameters([
'url' => (string) $this->response->getUrl(),
'url' => (string) $this->getUrl(),
'format' => 'json',
'api_key' => $this->key,
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/OEmbed/Infogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Infogram extends EndPoint implements EndPointInterface
*/
public function getEndPoint()
{
$url = $this->response->getUrl()->withScheme('https');
$url = $this->getUrl()->withScheme('https');

return Url::create(static::$endPoint)
->withQueryParameters([
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/OEmbed/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Instagram extends EndPoint implements EndPointInterface
*/
public function getEndPoint()
{
$url = $this->response->getUrl()->withScheme('http');
$url = $this->getUrl()->withScheme('http');

return Url::create(static::$endPoint)
->withQueryParameters([
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/OEmbed/Jsbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Jsbin extends EndPoint implements EndPointInterface
*/
public function getEndPoint()
{
$url = $this->response->getUrl()->withDirectoryPosition(2, 'embed');
$url = $this->getUrl()->withDirectoryPosition(2, 'embed');

return Url::create(static::$endPoint)
->withQueryParameters([
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/OEmbed/Scribd.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Scribd extends EndPoint implements EndPointInterface
*/
public function getEndPoint()
{
$url = $this->response->getUrl()->withDirectoryPosition(0, 'doc');
$url = $this->getUrl()->withDirectoryPosition(0, 'doc');

return Url::create(static::$endPoint)
->withQueryParameters([
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/OEmbed/Spotify.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function getEndPoint()
{
return Url::create(static::$endPoint)
->withQueryParameters([
'url' => (string) $this->response->getUrl()->withQueryParameters([]),
'url' => (string) $this->getUrl()->withQueryParameters([]),
'format' => 'json'
]);
}
Expand Down

0 comments on commit 2c73fb7

Please sign in to comment.