Skip to content

Commit 26cab81

Browse files
author
Ricardo Fiorani
committed
added oembed on vimeo adapter
1 parent 7904e78 commit 26cab81

File tree

2 files changed

+14
-33
lines changed

2 files changed

+14
-33
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
}
1414
],
1515
"require": {
16-
"php": ">=5.3"
16+
"php": ">=5.3",
17+
"ext-json": "*"
1718
},
1819
"autoload": {
1920
"psr-4": {

src/Adapter/Vimeo/VimeoServiceAdapter.php

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<?php
2-
/**
3-
* Created by PhpStorm.
4-
* User: Ricardo Fiorani
5-
* Date: 29/08/2015
6-
* Time: 14:56.
7-
*/
2+
83
namespace RicardoFiorani\Adapter\Vimeo;
94

105
use RicardoFiorani\Adapter\AbstractServiceAdapter;
@@ -42,18 +37,19 @@ class VimeoServiceAdapter extends AbstractServiceAdapter
4237
*/
4338
public function __construct($url, $pattern, EmbedRendererInterface $renderer)
4439
{
45-
$videoId = $this->getVideoIdByPattern($url, $pattern);
40+
$videoData = $this->getVideoDataFromServiceApi($url);
41+
$videoId = $videoData->video_id;
4642
$this->setVideoId($videoId);
47-
$videoData = $this->getVideoDataFromServiceApi();
4843

44+
//oEmbed only provides one size now :(
4945
$this->setThumbnails(array(
50-
self::THUMBNAIL_SMALL => $videoData[self::THUMBNAIL_SMALL],
51-
self::THUMBNAIL_MEDIUM => $videoData[self::THUMBNAIL_MEDIUM],
52-
self::THUMBNAIL_LARGE => $videoData[self::THUMBNAIL_LARGE],
46+
self::THUMBNAIL_SMALL => $videoData->thumbnail_url,
47+
self::THUMBNAIL_MEDIUM => $videoData->thumbnail_url,
48+
self::THUMBNAIL_LARGE => $videoData->thumbnail_url,
5349
));
5450

55-
$this->setTitle($videoData['title']);
56-
$this->setDescription($videoData['description']);
51+
$this->setTitle($videoData->title);
52+
$this->setDescription($videoData->description);
5753

5854
return parent::__construct($url, $pattern, $renderer);
5955
}
@@ -227,21 +223,6 @@ public function isEmbeddable()
227223
return true;
228224
}
229225

230-
/**
231-
* @param string $url
232-
* @param string $pattern
233-
*
234-
* @return int
235-
*/
236-
private function getVideoIdByPattern($url, $pattern)
237-
{
238-
$match = array();
239-
preg_match($pattern, $url, $match);
240-
$videoId = $match[2];
241-
242-
return $videoId;
243-
}
244-
245226
/**
246227
* Uses the Vimeo video API to get video info.
247228
*
@@ -251,17 +232,16 @@ private function getVideoIdByPattern($url, $pattern)
251232
*
252233
* @throws ServiceApiNotAvailable
253234
*/
254-
private function getVideoDataFromServiceApi()
235+
private function getVideoDataFromServiceApi($url)
255236
{
256-
$contents = file_get_contents('http://vimeo.com/api/v2/video/' . $this->getVideoId() . '.php');
237+
$contents = file_get_contents('https://vimeo.com/api/oembed.json?url=' . urlencode($url));
257238
if (false === $contents) {
258239
throw new ServiceApiNotAvailable(
259240
'Service "%s" could not reach it\'s API. Check if file_get_contents() function is available.',
260241
$this->getServiceName()
261242
);
262243
}
263-
$hash = unserialize($contents);
264244

265-
return reset($hash);
245+
return json_decode($contents);
266246
}
267247
}

0 commit comments

Comments
 (0)