Skip to content

Commit b94aefb

Browse files
committed
Use JSON instead of JS for gists #24
1 parent 63de94b commit b94aefb

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Embed/Adapters/Github.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Embed\Adapters;
66

77
use Embed\Request;
8+
use Embed\Providers\Provider;
89

910
class Github extends Webpage implements AdapterInterface
1011
{
@@ -22,24 +23,27 @@ public static function check(Request $request)
2223
/**
2324
* {@inheritDoc}
2425
*/
25-
public function getCode()
26+
protected function initProviders(Request $request)
2627
{
27-
$url = $this->getUrl();
28+
parent::initProviders($request);
2829

29-
if (substr($url, -1) === '/') {
30-
$url = substr($url, 0, -1);
31-
}
30+
$this->api = new Provider();
31+
$api = new Request($request->getUrl().'.json');
3232

33-
return '<script src="'.$url.'.js"></script>';
33+
if (($json = $api->getJsonContent())) {
34+
$this->api->set($json);
35+
}
3436
}
3537

3638

3739
/**
3840
* {@inheritDoc}
3941
*/
40-
public function getUrl()
42+
public function getCode()
4143
{
42-
return $this->request->getUrl();
44+
if (($code = $this->api->get('div')) && ($stylesheet = $this->api->get('stylesheet'))) {
45+
return '<link href="'.$stylesheet.'" rel="stylesheet">'.$code;
46+
}
4347
}
4448

4549

0 commit comments

Comments
 (0)