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 array $urlsSubscribed
|
||||||
* @param string $urlsUnsubscribed
|
* @param array $urlsUnsubscribed
|
||||||
*
|
*
|
||||||
* @return SubscriptionChange[]
|
* @return SubscriptionChange[]
|
||||||
*/
|
*/
|
||||||
public function createSubscriptionChangeList(string $urlsSubscribed, string $urlsUnsubscribed): array {
|
public function createSubscriptionChangeList(array $urlsSubscribed, array $urlsUnsubscribed): array {
|
||||||
$urlsToSubscribe = $this->subscriptionChangeReader->fromString($urlsSubscribed, true);
|
$urlsToSubscribe = $this->subscriptionChangeReader->mapToSubscriptionsChanges($urlsSubscribed, true);
|
||||||
$urlsToDelete = $this->subscriptionChangeReader->fromString($urlsUnsubscribed, false);
|
$urlsToDelete = $this->subscriptionChangeReader->mapToSubscriptionsChanges($urlsUnsubscribed, false);
|
||||||
|
|
||||||
/** @var \OCA\GPodderSync\Core\SubscriptionChange\SubscriptionChange[] $subscriptionChanges */
|
/** @var \OCA\GPodderSync\Core\SubscriptionChange\SubscriptionChange[] $subscriptionChanges */
|
||||||
return array_merge($urlsToSubscribe, $urlsToDelete);
|
return array_merge($urlsToSubscribe, $urlsToDelete);
|
||||||
|
@ -37,7 +37,7 @@ class SubscriptionChangeSaver {
|
|||||||
$this->subscriptionChangeRequestParser = $subscriptionChangeRequestParser;
|
$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);
|
$subscriptionChanges = $this->subscriptionChangeRequestParser->createSubscriptionChangeList($urlsSubscribed, $urlsUnsubscribed);
|
||||||
foreach ($subscriptionChanges as $urlChangedSubscriptionStatus) {
|
foreach ($subscriptionChanges as $urlChangedSubscriptionStatus) {
|
||||||
$subscriptionChangeEntity = new SubscriptionChangeEntity();
|
$subscriptionChangeEntity = new SubscriptionChangeEntity();
|
||||||
|
@ -6,19 +6,14 @@ namespace OCA\GPodderSync\Core\SubscriptionChange;
|
|||||||
class SubscriptionChangesReader {
|
class SubscriptionChangesReader {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $raw
|
* @param array $urls
|
||||||
|
* @param bool $subscribed
|
||||||
*
|
*
|
||||||
* @return array|SubscriptionChange[]
|
* @return SubscriptionChange[]
|
||||||
*/
|
*/
|
||||||
public function fromString(string $raw, bool $subscribed):? array {
|
public static function mapToSubscriptionsChanges(array $urls, bool $subscribed): array {
|
||||||
$urls = str_replace(["[", "]", " "], "", $raw);
|
|
||||||
$urlList = explode(",", $urls);
|
|
||||||
|
|
||||||
if ($urlList[0] === "") {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
$subscriptionChanges = [];
|
$subscriptionChanges = [];
|
||||||
foreach ($urlList as $url) {
|
foreach ($urls as $url) {
|
||||||
$subscriptionChanges[] = new SubscriptionChange($url, $subscribed);
|
$subscriptionChanges[] = new SubscriptionChange($url, $subscribed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,17 +7,11 @@ use OCA\GPodderSync\Core\SubscriptionChange\SubscriptionChangesReader;
|
|||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class SubscriptionChangeReaderTest extends TestCase {
|
class SubscriptionChangeReaderTest extends TestCase {
|
||||||
public function testCreateFromString(): void {
|
public function testMapUrlsToSubscriptionChanges(): void {
|
||||||
$reader = new SubscriptionChangesReader();
|
$subscriptionChange = SubscriptionChangesReader::mapToSubscriptionsChanges(["https://feeds.megaphone.fm/HSW8286374095", "https://feeds.megaphone.fm/another"], true);
|
||||||
$subscriptionChange = $reader->fromString('[https://feeds.megaphone.fm/HSW8286374095]', true);
|
$this->assertCount(2, $subscriptionChange);
|
||||||
$this->assertCount(1, $subscriptionChange);
|
|
||||||
$this->assertSame("https://feeds.megaphone.fm/HSW8286374095", $subscriptionChange[0]->getUrl());
|
$this->assertSame("https://feeds.megaphone.fm/HSW8286374095", $subscriptionChange[0]->getUrl());
|
||||||
}
|
$this->assertSame("https://feeds.megaphone.fm/another", $subscriptionChange[1]->getUrl());
|
||||||
|
|
||||||
public function testCreateFromEmptyString(): void {
|
|
||||||
$reader = new SubscriptionChangesReader();
|
|
||||||
$subscriptionChange = $reader->fromString('[]', true);
|
|
||||||
$this->assertCount(0, $subscriptionChange);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,20 +13,13 @@ class SubscriptionChangeRequestParserTest extends TestCase {
|
|||||||
new SubscriptionChangesReader(),
|
new SubscriptionChangesReader(),
|
||||||
);
|
);
|
||||||
|
|
||||||
$subscriptionChanges = $subscriptionChangesParser->createSubscriptionChangeList('[https://feeds.simplecast.com/54nAGcIl]','[]');
|
$subscriptionChanges = $subscriptionChangesParser->createSubscriptionChangeList(["https://feeds.simplecast.com/54nAGcIl", "https://feeds.simplecast.com/another"],["https://i.am-removed/GcIl"]);
|
||||||
$this->assertCount(1, $subscriptionChanges);
|
$this->assertCount(3, $subscriptionChanges);
|
||||||
$this->assertSame('https://feeds.simplecast.com/54nAGcIl', $subscriptionChanges[0]->getUrl());
|
$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->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