Skip to content
Snippets Groups Projects
Commit 66882532 authored by Kevin von Spiczak's avatar Kevin von Spiczak
Browse files

[TASK] optimization, remove unnecessary code

parent c1815b4f
No related branches found
No related tags found
No related merge requests found
......@@ -44,7 +44,6 @@ class VimeoController extends ActionController {
$clientId = $this->settings['clientId'];
$clientSecret = $this->settings['clientSecret'];
$personalAccessToken = $this->settings['personalAccessToken'];
$isPrivate = (bool) $this->settings['isPrivate'];
if (trim($clientId) === '' || trim($clientSecret) === '') {
$this->view->assign('error', 'Please configure a client id and a client secret for sg_vimeo.');
......@@ -54,7 +53,7 @@ class VimeoController extends ActionController {
$vimeoService = GeneralUtility::makeInstance(
VimeoService::class, $clientId, $clientSecret, $personalAccessToken
);
$response = $vimeoService->getVimeoData($id, $maxResults, $isPrivate);
$response = $vimeoService->getVimeoData($id, $maxResults);
$response = $this->mapVimeoApiResponseWithPossibleCustomThumbnails($response);
if ($response === NULL) {
return;
......
......@@ -67,7 +67,6 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
$templateData = [
'vimeoId' => $pluginConfiguration['settings.id']['vDEF'],
'isPrivate' => (int) ($pluginConfiguration['settings.isPrivate']['vDEF'] ?? 1),
'maxResults' => $pluginConfiguration['settings.maxResults']['vDEF'],
'showTitle' => (int) ($pluginConfiguration['settings.showTitle']['vDEF'] ?? 1),
'showDescription' => (int) ($pluginConfiguration['settings.showDescription']['vDEF'] ?? 1),
......
......@@ -80,6 +80,11 @@ class VimeoService implements LoggerAwareInterface {
*/
public function __construct(string $clientId, string $clientSecret, string $personalAccessToken) {
$this->vimeoApiClient = new Vimeo($clientId, $clientSecret, $personalAccessToken);
// We only need to request an unauthenticated token, if there is no personal access token provided already.
// An authenticated access token with the public scope is identical to an unauthenticated access token,
// except that you can use the /me endpoint to refer to the currently logged-in user.
// Accessing /me with an unauthenticated access token generates an error.
// See also: https://developer.vimeo.com/api/authentication
if ($personalAccessToken === '') {
$this->requestAccessToken();
}
......@@ -88,10 +93,9 @@ class VimeoService implements LoggerAwareInterface {
/**
* @param string $vimeoId can be a video id, showcase id or a channel name
* @param int $maxResults
* @param bool $isPrivate
* @return array|null
*/
public function getVimeoData(string $vimeoId, int $maxResults, bool $isPrivate): ?array {
public function getVimeoData(string $vimeoId, int $maxResults): ?array {
$this->maxResultsPerPage = $maxResults;
/** @var Registry $registry */
$registry = GeneralUtility::makeInstance(Registry::class);
......@@ -119,7 +123,7 @@ class VimeoService implements LoggerAwareInterface {
$response['items'] = $this->addVideoIdsToResponse($this->getChannelVideos($channelId));
$response['kind'] = 'channel';
} else {
$response['items'] = $this->addVideoIdsToResponse($this->getVideo((int) $vimeoId, $isPrivate));
$response['items'] = $this->addVideoIdsToResponse($this->getVideo((int) $vimeoId));
$response['kind'] = 'video';
}
......@@ -224,18 +228,13 @@ class VimeoService implements LoggerAwareInterface {
*
* @see https://developer.vimeo.com/api/reference/videos#get_video
* @param int $videoId
* @param bool $isPrivate
* @return array|null
*/
public function getVideo(int $videoId, bool $isPrivate): ?array {
public function getVideo(int $videoId): ?array {
// use field filtering, to save on quota, see: https://developer.vimeo.com/guidelines/rate-limiting
$fieldsToSelect = 'uri,name,description,link,embed,pictures';
$requestUri = self::API_VIDEO . $videoId . '?fields=' . $fieldsToSelect;
if ($isPrivate) {
$requestUri = '/me' . $requestUri;
}
try {
$response = $this->vimeoApiClient->request($requestUri);
$response = $this->vimeoApiClient->request(self::API_VIDEO . $videoId . '?fields=' . $fieldsToSelect);
} catch (VimeoRequestException $e) {
$response = NULL;
}
......@@ -251,9 +250,9 @@ class VimeoService implements LoggerAwareInterface {
* @return array|null
*/
public function getChannelVideos(string $channelIdentifier): ?array {
// use field filtering, to save on quota, see: https://developer.vimeo.com/guidelines/rate-limiting
$fieldsToSelect = 'uri,name,description,link,embed,pictures';
try {
// use field filtering, to save on quota, see: https://developer.vimeo.com/guidelines/rate-limiting
$fieldsToSelect = 'uri,name,description,link,embed,pictures';
$response = $this->vimeoApiClient->request(
self::API_CHANNEL . $channelIdentifier . self::API_VIDEO . '?fields=' . $fieldsToSelect . '&per_page=' . $this->maxResultsPerPage
);
......@@ -272,9 +271,9 @@ class VimeoService implements LoggerAwareInterface {
* @return array|null
*/
public function getShowcaseVideos(string $showcaseId): ?array {
// use field filtering, to save on quota, see: https://developer.vimeo.com/guidelines/rate-limiting
$fieldsToSelect = 'uri,name,description,link,embed,pictures';
try {
// use field filtering, to save on quota, see: https://developer.vimeo.com/guidelines/rate-limiting
$fieldsToSelect = 'uri,name,description,link,embed,pictures';
$response = $this->vimeoApiClient->request(
self::API_SHOWCASE . $showcaseId . self::API_VIDEO . '?fields=' . $fieldsToSelect . '&per_page=' . $this->maxResultsPerPage
);
......
......@@ -13,17 +13,6 @@
</TCEforms>
<type>array</type>
<el>
<settings.isPrivate>
<TCEforms>
<exclude>0</exclude>
<label>LLL:EXT:sg_vimeo/Resources/Private/Language/locallang.xlf:flexform.isPrivate</label>
<description>LLL:EXT:sg_vimeo/Resources/Private/Language/locallang.xlf:flexform.isPrivate.description</description>
<config>
<type>check</type>
<default>0</default>
</config>
</TCEforms>
</settings.isPrivate>
<settings.id>
<TCEforms>
<exclude>0</exclude>
......
......@@ -46,9 +46,8 @@ authenticated personal access token. You can find a guide, on how to generate su
https://vimeo.zendesk.com/hc/en-us/articles/360042445032-How-do-I-generate-a-personal-access-token- .
The following requirements have to be met, for the private video to show up:
* mark the video as "is private" in the content element, containing the vimeo plugin
* the video has to be hosted on the same vimeo account, that was used to configure the clientSecret & clientId (vimeo app)
* a personal access token with access to private videos has to be configured in the typoscript settings (personalAccessToken)
* a personal access token with access scope "private" has to be configured in the typoscript settings (personalAccessToken)
### Working with Rate Limits
......
......@@ -49,14 +49,6 @@
<source><![CDATA[Show Video Descriptions]]></source>
<target><![CDATA[Videobeschreibungen anzeigen]]></target>
</trans-unit>
<trans-unit id="flexform.isPrivate">
<source><![CDATA[Is private]]></source>
<target><![CDATA[Ist privat]]></target>
</trans-unit>
<trans-unit id="flexform.isPrivate.description">
<source><![CDATA[Check this, if your video on vimeo is not visible to the public.]]></source>
<target><![CDATA[Haken Sie dieses Feld an, wenn Ihr Video auf Vimeo nicht öffentlich sichtbar ist.]]></target>
</trans-unit>
<trans-unit id="flexform.showTitle" approved="yes">
<source><![CDATA[Show Video Titles]]></source>
<target><![CDATA[Video-Titel anzeigen]]></target>
......
......@@ -23,12 +23,6 @@
<trans-unit id="flexform.aspectRatio">
<source><![CDATA[Aspect Ratio (only used if thumbnail type is set to check that)]]></source>
</trans-unit>
<trans-unit id="flexform.isPrivate">
<source><![CDATA[Is private]]></source>
</trans-unit>
<trans-unit id="flexform.isPrivate.description">
<source><![CDATA[Check this, if your video on vimeo is not visible to the public.]]></source>
</trans-unit>
<trans-unit id="flexform.disableLightbox">
<source><![CDATA[Replace the thumbnail with the video and disable the lightbox (Desktop)]]></source>
</trans-unit>
......
......@@ -31,14 +31,6 @@
</thead>
<tbody>
<tr>
<th scope="row">
<f:translate key="flexform.isPrivate" extensionName="SgVimeo"/>
</th>
<td>
<f:render partial="BooleanIcon" arguments="{boolValue: '{data.isPrivate}'}"/>
</td>
</tr>
<tr>
<th scope="row">
<f:translate key="flexform.id" extensionName="SgVimeo"/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment