mirror of
https://github.com/thrillfall/nextcloud-gpodder.git
synced 2024-12-27 08:14:42 +01:00
make subscription changes endpoint comply with gpodder.net api
This commit is contained in:
parent
edddecd027
commit
324aecd7b8
@ -15,14 +15,14 @@ class SubscriptionChangeRequestParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $urlsSubscribed
|
||||
* @param string $urlsUnsubscribed
|
||||
* @param array $urlsSubscribed
|
||||
* @param array $urlsUnsubscribed
|
||||
*
|
||||
* @return SubscriptionChange[]
|
||||
*/
|
||||
public function createSubscriptionChangeList(string $urlsSubscribed, string $urlsUnsubscribed): array {
|
||||
$urlsToSubscribe = $this->subscriptionChangeReader->fromString($urlsSubscribed, true);
|
||||
$urlsToDelete = $this->subscriptionChangeReader->fromString($urlsUnsubscribed, false);
|
||||
public function createSubscriptionChangeList(array $urlsSubscribed, array $urlsUnsubscribed): array {
|
||||
$urlsToSubscribe = $this->subscriptionChangeReader->mapToSubscriptionsChanges($urlsSubscribed, true);
|
||||
$urlsToDelete = $this->subscriptionChangeReader->mapToSubscriptionsChanges($urlsUnsubscribed, false);
|
||||
|
||||
/** @var \OCA\GPodderSync\Core\SubscriptionChange\SubscriptionChange[] $subscriptionChanges */
|
||||
return array_merge($urlsToSubscribe, $urlsToDelete);
|
||||
|
@ -37,7 +37,7 @@ class SubscriptionChangeSaver {
|
||||
$this->subscriptionChangeRequestParser = $subscriptionChangeRequestParser;
|
||||
}
|
||||
|
||||
public function saveSubscriptionChanges(string $urlsSubscribed, string $urlsUnsubscribed, string $userId): void {
|
||||
public function saveSubscriptionChanges(array $urlsSubscribed, array $urlsUnsubscribed, string $userId): void {
|
||||
$subscriptionChanges = $this->subscriptionChangeRequestParser->createSubscriptionChangeList($urlsSubscribed, $urlsUnsubscribed);
|
||||
foreach ($subscriptionChanges as $urlChangedSubscriptionStatus) {
|
||||
$subscriptionChangeEntity = new SubscriptionChangeEntity();
|
||||
|
@ -6,19 +6,14 @@ namespace OCA\GPodderSync\Core\SubscriptionChange;
|
||||
class SubscriptionChangesReader {
|
||||
|
||||
/**
|
||||
* @param string $raw
|
||||
* @param array $urls
|
||||
* @param bool $subscribed
|
||||
*
|
||||
* @return array|SubscriptionChange[]
|
||||
* @return SubscriptionChange[]
|
||||
*/
|
||||
public function fromString(string $raw, bool $subscribed):? array {
|
||||
$urls = str_replace(["[", "]", " "], "", $raw);
|
||||
$urlList = explode(",", $urls);
|
||||
|
||||
if ($urlList[0] === "") {
|
||||
return [];
|
||||
}
|
||||
public static function mapToSubscriptionsChanges(array $urls, bool $subscribed): array {
|
||||
$subscriptionChanges = [];
|
||||
foreach ($urlList as $url) {
|
||||
foreach ($urls as $url) {
|
||||
$subscriptionChanges[] = new SubscriptionChange($url, $subscribed);
|
||||
}
|
||||
|
||||
|
@ -7,17 +7,11 @@ use OCA\GPodderSync\Core\SubscriptionChange\SubscriptionChangesReader;
|
||||
use Test\TestCase;
|
||||
|
||||
class SubscriptionChangeReaderTest extends TestCase {
|
||||
public function testCreateFromString(): void {
|
||||
$reader = new SubscriptionChangesReader();
|
||||
$subscriptionChange = $reader->fromString('[https://feeds.megaphone.fm/HSW8286374095]', true);
|
||||
$this->assertCount(1, $subscriptionChange);
|
||||
public function testMapUrlsToSubscriptionChanges(): void {
|
||||
$subscriptionChange = SubscriptionChangesReader::mapToSubscriptionsChanges(["https://feeds.megaphone.fm/HSW8286374095", "https://feeds.megaphone.fm/another"], true);
|
||||
$this->assertCount(2, $subscriptionChange);
|
||||
$this->assertSame("https://feeds.megaphone.fm/HSW8286374095", $subscriptionChange[0]->getUrl());
|
||||
}
|
||||
|
||||
public function testCreateFromEmptyString(): void {
|
||||
$reader = new SubscriptionChangesReader();
|
||||
$subscriptionChange = $reader->fromString('[]', true);
|
||||
$this->assertCount(0, $subscriptionChange);
|
||||
$this->assertSame("https://feeds.megaphone.fm/another", $subscriptionChange[1]->getUrl());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,20 +13,13 @@ class SubscriptionChangeRequestParserTest extends TestCase {
|
||||
new SubscriptionChangesReader(),
|
||||
);
|
||||
|
||||
$subscriptionChanges = $subscriptionChangesParser->createSubscriptionChangeList('[https://feeds.simplecast.com/54nAGcIl]','[]');
|
||||
$this->assertCount(1, $subscriptionChanges);
|
||||
$this->assertSame('https://feeds.simplecast.com/54nAGcIl', $subscriptionChanges[0]->getUrl());
|
||||
$subscriptionChanges = $subscriptionChangesParser->createSubscriptionChangeList(["https://feeds.simplecast.com/54nAGcIl", "https://feeds.simplecast.com/another"],["https://i.am-removed/GcIl"]);
|
||||
$this->assertCount(3, $subscriptionChanges);
|
||||
$this->assertSame("https://feeds.simplecast.com/54nAGcIl", $subscriptionChanges[0]->getUrl());
|
||||
$this->assertSame("https://feeds.simplecast.com/another", $subscriptionChanges[1]->getUrl());
|
||||
$this->assertSame("https://i.am-removed/GcIl", $subscriptionChanges[2]->getUrl());
|
||||
$this->assertTrue($subscriptionChanges[0]->isSubscribed());
|
||||
$this->assertFalse($subscriptionChanges[2]->isSubscribed());
|
||||
}
|
||||
|
||||
public function testSubscriptionRequestWithMultipleChangesConvertsToSubscriptionChangeList() {
|
||||
$subscriptionChangesParser = new SubscriptionChangeRequestParser(
|
||||
new SubscriptionChangesReader(),
|
||||
);
|
||||
|
||||
$subscriptionChanges = $subscriptionChangesParser->createSubscriptionChangeList(
|
||||
'[https://podcastfeeds.nbcnews.com/dateline-nbc,https://feeds.megaphone.fm/ADL9840290619]',
|
||||
'[]');
|
||||
$this->assertCount(2, $subscriptionChanges);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user