use add_feed_and_wait endpoint

The add_feed endpoint does not return feed info. The _and_wait endpoint can be slower (up to 10 seconds) but will make sure we gett the right URL if available.
This commit is contained in:
Jonathan Bennett 2019-11-20 17:26:27 -05:00
parent 85d54c17cc
commit d3c168a12e
4 changed files with 40 additions and 10 deletions

View File

@ -16,6 +16,7 @@
3B826DAD2385C81C00FC1ADB /* FeedWranglerFeedItemsRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B826DA42385C81C00FC1ADB /* FeedWranglerFeedItemsRequest.swift */; }; 3B826DAD2385C81C00FC1ADB /* FeedWranglerFeedItemsRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B826DA42385C81C00FC1ADB /* FeedWranglerFeedItemsRequest.swift */; };
3B826DAE2385C81C00FC1ADB /* FeedWranglerSubscriptionsRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B826DA52385C81C00FC1ADB /* FeedWranglerSubscriptionsRequest.swift */; }; 3B826DAE2385C81C00FC1ADB /* FeedWranglerSubscriptionsRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B826DA52385C81C00FC1ADB /* FeedWranglerSubscriptionsRequest.swift */; };
3B826DAF2385C81C00FC1ADB /* FeedWranglerGenericResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B826DA62385C81C00FC1ADB /* FeedWranglerGenericResult.swift */; }; 3B826DAF2385C81C00FC1ADB /* FeedWranglerGenericResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B826DA62385C81C00FC1ADB /* FeedWranglerGenericResult.swift */; };
3BC23AB92385ECB100371CBA /* FeedWranglerSubscriptionResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BC23AB82385ECB100371CBA /* FeedWranglerSubscriptionResult.swift */; };
5107A099227DE42E00C7C3C5 /* AccountCredentialsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5107A098227DE42E00C7C3C5 /* AccountCredentialsTest.swift */; }; 5107A099227DE42E00C7C3C5 /* AccountCredentialsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5107A098227DE42E00C7C3C5 /* AccountCredentialsTest.swift */; };
5107A09B227DE49500C7C3C5 /* TestAccountManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5107A09A227DE49500C7C3C5 /* TestAccountManager.swift */; }; 5107A09B227DE49500C7C3C5 /* TestAccountManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5107A09A227DE49500C7C3C5 /* TestAccountManager.swift */; };
5107A09D227DE77700C7C3C5 /* TestTransport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5107A09C227DE77700C7C3C5 /* TestTransport.swift */; }; 5107A09D227DE77700C7C3C5 /* TestTransport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5107A09C227DE77700C7C3C5 /* TestTransport.swift */; };
@ -226,6 +227,7 @@
3B826DA42385C81C00FC1ADB /* FeedWranglerFeedItemsRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedWranglerFeedItemsRequest.swift; sourceTree = "<group>"; }; 3B826DA42385C81C00FC1ADB /* FeedWranglerFeedItemsRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedWranglerFeedItemsRequest.swift; sourceTree = "<group>"; };
3B826DA52385C81C00FC1ADB /* FeedWranglerSubscriptionsRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedWranglerSubscriptionsRequest.swift; sourceTree = "<group>"; }; 3B826DA52385C81C00FC1ADB /* FeedWranglerSubscriptionsRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedWranglerSubscriptionsRequest.swift; sourceTree = "<group>"; };
3B826DA62385C81C00FC1ADB /* FeedWranglerGenericResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedWranglerGenericResult.swift; sourceTree = "<group>"; }; 3B826DA62385C81C00FC1ADB /* FeedWranglerGenericResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedWranglerGenericResult.swift; sourceTree = "<group>"; };
3BC23AB82385ECB100371CBA /* FeedWranglerSubscriptionResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedWranglerSubscriptionResult.swift; sourceTree = "<group>"; };
5107A098227DE42E00C7C3C5 /* AccountCredentialsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountCredentialsTest.swift; sourceTree = "<group>"; }; 5107A098227DE42E00C7C3C5 /* AccountCredentialsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountCredentialsTest.swift; sourceTree = "<group>"; };
5107A09A227DE49500C7C3C5 /* TestAccountManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestAccountManager.swift; sourceTree = "<group>"; }; 5107A09A227DE49500C7C3C5 /* TestAccountManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestAccountManager.swift; sourceTree = "<group>"; };
5107A09C227DE77700C7C3C5 /* TestTransport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestTransport.swift; sourceTree = "<group>"; }; 5107A09C227DE77700C7C3C5 /* TestTransport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestTransport.swift; sourceTree = "<group>"; };
@ -428,6 +430,7 @@
3B826DA42385C81C00FC1ADB /* FeedWranglerFeedItemsRequest.swift */, 3B826DA42385C81C00FC1ADB /* FeedWranglerFeedItemsRequest.swift */,
3B826DA52385C81C00FC1ADB /* FeedWranglerSubscriptionsRequest.swift */, 3B826DA52385C81C00FC1ADB /* FeedWranglerSubscriptionsRequest.swift */,
3B826DA62385C81C00FC1ADB /* FeedWranglerGenericResult.swift */, 3B826DA62385C81C00FC1ADB /* FeedWranglerGenericResult.swift */,
3BC23AB82385ECB100371CBA /* FeedWranglerSubscriptionResult.swift */,
); );
path = FeedWrangler; path = FeedWrangler;
sourceTree = "<group>"; sourceTree = "<group>";
@ -1079,6 +1082,7 @@
9EAEC624233315F60085D7C9 /* FeedlyEntry.swift in Sources */, 9EAEC624233315F60085D7C9 /* FeedlyEntry.swift in Sources */,
9EEAE073235D01AE00E3FEE4 /* FeedlyGetStreamIdsService.swift in Sources */, 9EEAE073235D01AE00E3FEE4 /* FeedlyGetStreamIdsService.swift in Sources */,
9EEEF7212355277F009E9D80 /* FeedlySyncStarredArticlesOperation.swift in Sources */, 9EEEF7212355277F009E9D80 /* FeedlySyncStarredArticlesOperation.swift in Sources */,
3BC23AB92385ECB100371CBA /* FeedWranglerSubscriptionResult.swift in Sources */,
5144EA49227B497600D19003 /* FeedbinAPICaller.swift in Sources */, 5144EA49227B497600D19003 /* FeedbinAPICaller.swift in Sources */,
84B99C9F1FAE8D3200ECDEDB /* ContainerPath.swift in Sources */, 84B99C9F1FAE8D3200ECDEDB /* ContainerPath.swift in Sources */,
9E510D6E234F16A8002E6F1A /* FeedlyAddFeedRequest.swift in Sources */, 9E510D6E234F16A8002E6F1A /* FeedlyAddFeedRequest.swift in Sources */,

View File

@ -65,20 +65,28 @@ final class FeedWranglerAPICaller: NSObject {
} }
} }
func addSubscription(url: String, completion: @escaping (Result<Void, Error>) -> Void) { func addSubscription(url: String, completion: @escaping (Result<FeedWranglerSubscription, Error>) -> Void) {
let url = FeedWranglerConfig let url = FeedWranglerConfig
.clientURL .clientURL
.appendingPathComponent("subscriptions/add_feed") .appendingPathComponent("subscriptions/add_feed_and_wait")
.appendingQueryItem(URLQueryItem(name: "feed_url", value: url)) .appendingQueryItems([
URLQueryItem(name: "feed_url", value: url),
URLQueryItem(name: "choose_first", value: "true")
])
standardSend(url: url, resultType: FeedWranglerGenericResult.self) { result in standardSend(url: url, resultType: FeedWranglerSubscriptionResult.self) { result in
switch result { switch result {
case .success(let (_, results)): case .success(let (_, results)):
if let error = results?.error { if let results = results {
if let error = results.error {
completion(.failure(FeedWranglerError.general(message: error))) completion(.failure(FeedWranglerError.general(message: error)))
} else { } else {
completion(.success(())) completion(.success(results.feed))
} }
} else {
completion(.failure(FeedWranglerError.general(message: "No feed found")))
}
case .failure(let error): case .failure(let error):
completion(.failure(error)) completion(.failure(error))

View File

@ -284,8 +284,8 @@ final class FeedWranglerAccountDelegate: AccountDelegate {
self.refreshProgress.completeTask() self.refreshProgress.completeTask()
switch result { switch result {
case .success: case .success(let subscription):
let feed = account.createWebFeed(with: name, url: url, webFeedID: url, homePageURL: url) let feed = account.createWebFeed(with: subscription.title, url: subscription.feedURL, webFeedID: String(subscription.feedID), homePageURL: subscription.siteURL)
completion(.success(feed)) completion(.success(feed))
case .failure(let error): case .failure(let error):

View File

@ -0,0 +1,18 @@
//
// FeedWranglerSubscriptionResult.swift
// Account
//
// Created by Jonathan Bennett on 2019-11-20.
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
//
import Foundation
struct FeedWranglerSubscriptionResult: Hashable, Codable {
let feed: FeedWranglerSubscription
let error: String?
let result: String
}