Skip to content

Commit debde83

Browse files
committed
new imageshack api provider
1 parent 39d0739 commit debde83

File tree

4 files changed

+152
-1
lines changed

4 files changed

+152
-1
lines changed

src/Adapters/Imageshack.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/**
4+
* Adapter to provide information from imageshack.
5+
*/
6+
namespace Embed\Adapters;
7+
8+
use Embed\Request;
9+
use Embed\Providers\Api;
10+
11+
class Imageshack extends Webpage implements AdapterInterface
12+
{
13+
/**
14+
* {@inheritdoc}
15+
*/
16+
public static function check(Request $request)
17+
{
18+
return $request->isValid() && $request->match([
19+
'https?://imageshack.com/i/*',
20+
]);
21+
}
22+
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
public function run()
27+
{
28+
$this->addProvider('imageshack', new Api\Imageshack());
29+
30+
parent::run();
31+
}
32+
}

src/Providers/Api/Imageshack.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
namespace Embed\Providers\Api;
4+
5+
use Embed\Providers\Provider;
6+
use Embed\Providers\ProviderInterface;
7+
8+
/**
9+
* Provider to use the API of imageshack.com.
10+
*/
11+
class Imageshack extends Provider implements ProviderInterface
12+
{
13+
/**
14+
* {@inheritdoc}
15+
*/
16+
public function run()
17+
{
18+
$id = $this->request->getDirectoryPosition(1);
19+
$api = $this->request->withUrl('https://api.imageshack.com/v2/images/'.$id);
20+
21+
if (($json = $api->getJsonContent()) && !empty($json['result'])) {
22+
$this->bag->set($json['result']);
23+
}
24+
}
25+
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
public function getTitle()
30+
{
31+
return $this->bag->get('title');
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
public function getDescription()
38+
{
39+
return $this->bag->get('description');
40+
}
41+
42+
/**
43+
* {@inheritdoc}
44+
*/
45+
public function getType()
46+
{
47+
return 'photo';
48+
}
49+
50+
/**
51+
* {@inheritdoc}
52+
*/
53+
public function getPublishedTime()
54+
{
55+
return $this->bag->get('creation_date');
56+
}
57+
58+
/**
59+
* {@inheritdoc}
60+
*/
61+
public function getWidth()
62+
{
63+
return $this->bag->get('width');
64+
}
65+
66+
/**
67+
* {@inheritdoc}
68+
*/
69+
public function getHeight()
70+
{
71+
return $this->bag->get('height');
72+
}
73+
74+
/**
75+
* {@inheritdoc}
76+
*/
77+
public function getAuthorName()
78+
{
79+
return $this->bag->get('owner[username]');
80+
}
81+
82+
/**
83+
* {@inheritdoc}
84+
*/
85+
public function getAuthorUrl()
86+
{
87+
$username = $this->getAuthorName();
88+
89+
if (!empty($username)) {
90+
return 'http://imageshack.com/user/'.$username;
91+
}
92+
}
93+
94+
/**
95+
* {@inheritdoc}
96+
*/
97+
public function getImagesUrls()
98+
{
99+
return (array) $this->bag->get('direct_link');
100+
}
101+
}

src/Url.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ protected function parseUrl($url)
448448

449449
if (empty($this->info['query'])) {
450450
$this->info['query'] = [];
451+
451452
return;
452453
}
453454

tests/YFrogTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
class YFrogTest extends TestCaseBase
44
{
5-
public function testOne()
5+
//yfrog seems shutdown
6+
public function noTestOne()
67
{
78
$this->assertEmbed(
89
'http://a.yfrog.com/img593/8436/snso.jpg',
@@ -15,4 +16,20 @@ public function testOne()
1516
]
1617
);
1718
}
19+
20+
public function testImageShack()
21+
{
22+
$this->assertEmbed(
23+
'https://imageshack.com/i/f0KQQN7Uj',
24+
[
25+
'title' => '.',
26+
'image' => 'http://imageshack.com/scaled/medium/540/KQQN7U.jpg',
27+
'imageWidth' => 236,
28+
'imageHeight' => 354,
29+
'type' => 'photo',
30+
'providerName' => 'ImageShack',
31+
'authorName' => 'ToddGilbert',
32+
]
33+
);
34+
}
1835
}

0 commit comments

Comments
 (0)