Skip to content

Commit e6dfe37

Browse files
authored
Merge pull request #279 from bazaarco/master
Tumblr provider
2 parents 03a0c0e + b53c8dd commit e6dfe37

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

src/Providers/OEmbed/Tumblr.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Embed\Providers\OEmbed;
4+
5+
use Embed\Adapters\Adapter;
6+
use Embed\Http\Response;
7+
use Embed\Http\Url;
8+
9+
class Tumblr extends EndPoint implements EndPointInterface
10+
{
11+
protected static $pattern = [
12+
'*.tumblr.com/post/*'
13+
];
14+
15+
protected static $endPoint = 'https://www.tumblr.com/oembed/1.0';
16+
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
public static function create(Adapter $adapter)
21+
{
22+
$response = $adapter->getResponse();
23+
if ($response->getStartingUrl()->match(static::$pattern)) {
24+
return new static($response);
25+
}
26+
}
27+
28+
/**
29+
* Constructor.
30+
*
31+
* @param Response $response
32+
*/
33+
private function __construct(Response $response)
34+
{
35+
$this->response = $response;
36+
}
37+
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
public function getEndPoint()
42+
{
43+
return Url::create(static::$endPoint)
44+
->withQueryParameters([
45+
'url' => (string) $this->response->getStartingUrl()
46+
]);
47+
}
48+
}

tests/TumblrTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Embed\Tests;
4+
5+
class TumblrTest extends AbstractTestCase
6+
{
7+
public function testOne()
8+
{
9+
$this->assertEmbed(
10+
'http://he-who-photographs-rather-ok.tumblr.com/post/165326273724',
11+
[
12+
'url' => 'http://he-who-photographs-rather-ok.tumblr.com/post/165326273724',
13+
'authorName' => 'He-who-photographs-rather-OK',
14+
'authorUrl' => 'http://he-who-photographs-rather-ok.tumblr.com/',
15+
'type' => 'rich',
16+
]
17+
);
18+
}
19+
}

0 commit comments

Comments
 (0)