allow renaming of feeds
This commit is contained in:
parent
d1b4c20494
commit
36861f2eb3
|
@ -71,4 +71,31 @@ final class FeedWranglerAPICaller: NSObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func renameSubscription(feedID: String, newName: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||||
|
guard var components = URLComponents(url: FeedWranglerConfig.clientURL.appendingPathComponent("subscriptions/rename_feed"), resolvingAgainstBaseURL: false) else {
|
||||||
|
completion(.failure(TransportError.noURL))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
components.queryItems = [
|
||||||
|
URLQueryItem(name: "feed_id", value: feedID),
|
||||||
|
URLQueryItem(name: "feed_name", value: newName),
|
||||||
|
]
|
||||||
|
|
||||||
|
guard let url = components.url else {
|
||||||
|
completion(.failure(TransportError.noURL))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let request = URLRequest(url: url, credentials: credentials)
|
||||||
|
|
||||||
|
transport.send(request: request, resultType: FeedWranglerSubscriptionsRequest.self) { result in
|
||||||
|
switch result {
|
||||||
|
case .success:
|
||||||
|
completion(.success(()))
|
||||||
|
|
||||||
|
case .failure(let error):
|
||||||
|
completion(.failure(error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,28 @@ final class FeedWranglerAccountDelegate: AccountDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||||
fatalError()
|
refreshProgress.addToNumberOfTasksAndRemaining(2)
|
||||||
|
|
||||||
|
self.refreshCredentials(for: account) {
|
||||||
|
self.refreshProgress.completeTask()
|
||||||
|
self.caller.renameSubscription(feedID: feed.feedID, newName: name) { result in
|
||||||
|
self.refreshProgress.completeTask()
|
||||||
|
|
||||||
|
switch result {
|
||||||
|
case .success:
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
feed.editedName = name
|
||||||
|
completion(.success(()))
|
||||||
|
}
|
||||||
|
|
||||||
|
case .failure(let error):
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
let wrappedError = AccountError.wrappedError(error: error, account: account)
|
||||||
|
completion(.failure(wrappedError))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func addFeed(for account: Account, with: Feed, to container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
func addFeed(for account: Account, with: Feed, to container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||||
|
@ -199,6 +220,7 @@ private extension FeedWranglerAccountDelegate {
|
||||||
|
|
||||||
if let feed = account.existingFeed(withFeedID: subscriptionId) {
|
if let feed = account.existingFeed(withFeedID: subscriptionId) {
|
||||||
feed.name = subscription.title
|
feed.name = subscription.title
|
||||||
|
feed.editedName = nil
|
||||||
feed.homePageURL = subscription.siteURL
|
feed.homePageURL = subscription.siteURL
|
||||||
feed.subscriptionID = nil // MARK: TODO What should this be?
|
feed.subscriptionID = nil // MARK: TODO What should this be?
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue