Skip to content

Commit

Permalink
Merge pull request #93 from alexplusde/field-thumbnailws
Browse files Browse the repository at this point in the history
Neues Feld: `thumbnailws`
  • Loading branch information
alxndr-w authored Jan 6, 2025
2 parents 4cf931f + 1b25f43 commit 37f4ee4
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions lib/yform/value/thumbnailws.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

class rex_yform_value_thumbnailws extends rex_yform_action_abstract
{
public function postFormAction(): void
{
$sourceField = $this->getElement(1);
$sourceUrl = $this->params['value_pool']['email'][$sourceField];
$targetField = $this->getElement(2);
$apiKey = $this->getElement(3);
$query['url'] = $sourceUrl;
$apiUrl = "https://api.thumbnail.ws/api/$apiKey/thumbnail/get?" . http_build_query($query);

dump($sourceField, $targetField, $apiKey, $apiUrl);

try {
$socket = rex_socket::factoryUrl($apiUrl);
$response = $socket->doGet();

if (!$response->isOk()) {
dump($response, 'Fehler bei der API-Anfrage.');
}

$result = $response->getBody();
$response = json_decode($result, true);

dump($response);
$this->params['value_pool']['email'][$targetField] = json_encode($response);
} catch (rex_socket_exception $e) {
dump('Fehler bei der API-Anfrage: ' . $e->getMessage());
}
}

public function getDescription(): string
{
return 'action|thumbnailws|source_url_field|target_field|api_key';
}
}

0 comments on commit 37f4ee4

Please sign in to comment.