diff --git a/Frameworks/Account/Account.xcodeproj/project.pbxproj b/Frameworks/Account/Account.xcodeproj/project.pbxproj index d895ccfdf..68d13d48c 100644 --- a/Frameworks/Account/Account.xcodeproj/project.pbxproj +++ b/Frameworks/Account/Account.xcodeproj/project.pbxproj @@ -52,6 +52,7 @@ 5133BB4F2460EC230001E3D0 /* RedditMedia.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5133BB4E2460EC230001E3D0 /* RedditMedia.swift */; }; 5133BB512460EE730001E3D0 /* RedditMediaEmbed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5133BB502460EE730001E3D0 /* RedditMediaEmbed.swift */; }; 5139A6382459822D004D960C /* CloudKitArticleStatusUpdate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5139A6372459822D004D960C /* CloudKitArticleStatusUpdate.swift */; }; + 5141000A2464DAA6001DA326 /* RedditSort.swift in Sources */ = {isa = PBXBuildFile; fileRef = 514100092464DAA6001DA326 /* RedditSort.swift */; }; 5144EA49227B497600D19003 /* FeedbinAPICaller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5144EA48227B497600D19003 /* FeedbinAPICaller.swift */; }; 5144EA4E227B829A00D19003 /* FeedbinAccountDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5144EA4D227B829A00D19003 /* FeedbinAccountDelegate.swift */; }; 514BF5202391B0DB00902FE8 /* SingleArticleFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 514BF51F2391B0DB00902FE8 /* SingleArticleFetcher.swift */; }; @@ -314,6 +315,7 @@ 5133BB4E2460EC230001E3D0 /* RedditMedia.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedditMedia.swift; sourceTree = ""; }; 5133BB502460EE730001E3D0 /* RedditMediaEmbed.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedditMediaEmbed.swift; sourceTree = ""; }; 5139A6372459822D004D960C /* CloudKitArticleStatusUpdate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CloudKitArticleStatusUpdate.swift; sourceTree = ""; }; + 514100092464DAA6001DA326 /* RedditSort.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedditSort.swift; sourceTree = ""; }; 5144EA48227B497600D19003 /* FeedbinAPICaller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbinAPICaller.swift; sourceTree = ""; }; 5144EA4D227B829A00D19003 /* FeedbinAccountDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbinAccountDelegate.swift; sourceTree = ""; }; 514BF51F2391B0DB00902FE8 /* SingleArticleFetcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleArticleFetcher.swift; sourceTree = ""; }; @@ -651,6 +653,7 @@ 5133BB4E2460EC230001E3D0 /* RedditMedia.swift */, 5133BB502460EE730001E3D0 /* RedditMediaEmbed.swift */, 5100E4CC246243990010A63D /* RedditPreview.swift */, + 514100092464DAA6001DA326 /* RedditSort.swift */, 5133BB4A2460BDF30001E3D0 /* RedditSubreddit.swift */, ); path = Reddit; @@ -1309,6 +1312,7 @@ 512DD4CD2431098700C17B1F /* CloudKitAccountZoneDelegate.swift in Sources */, 51BFDECE238B508D00216323 /* ContainerIdentifier.swift in Sources */, 9E1D1555233431A600F4944C /* FeedlyOperation.swift in Sources */, + 5141000A2464DAA6001DA326 /* RedditSort.swift in Sources */, 84F1F06E2243524700DA0616 /* AccountMetadata.swift in Sources */, 9EF1B10723590D61000A486A /* FeedlyGetStreamIdsOperation.swift in Sources */, 84245C851FDDD8CB0074AFBB /* FeedbinSubscription.swift in Sources */, diff --git a/Frameworks/Account/FeedProvider/Reddit/RedditFeedProvider.swift b/Frameworks/Account/FeedProvider/Reddit/RedditFeedProvider.swift index 5b25d0a65..07192c38c 100644 --- a/Frameworks/Account/FeedProvider/Reddit/RedditFeedProvider.swift +++ b/Frameworks/Account/FeedProvider/Reddit/RedditFeedProvider.swift @@ -31,6 +31,7 @@ public final class RedditFeedProvider: FeedProvider { var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "RedditFeedProvider") + private static let homeURL = "https://www.reddit.com" private static let server = "www.reddit.com" private static let apiBase = "https://oauth.reddit.com" private static let userAgentHeaders = UserAgent.headers() as! [String: String] @@ -109,20 +110,26 @@ public final class RedditFeedProvider: FeedProvider { let path = urlComponents.path if path == "" || path == "/" { - let name = NSLocalizedString("Reddit Timeline", comment: "Reddit Timeline") - let metaData = FeedProviderFeedMetaData(name: name, homePageURL: "https://www.reddit.com") + let name = NSLocalizedString("Reddit Best", comment: "Reddit Best") + let metaData = FeedProviderFeedMetaData(name: name, homePageURL: Self.homeURL) completion(.success(metaData)) return } let splitPath = path.split(separator: "/") + if splitPath.count == 1, let sort = RedditSort(rawValue: String(splitPath[0])) { + let name = "Reddit \(sort.displayName)" + let metaData = FeedProviderFeedMetaData(name: name, homePageURL: Self.homeURL) + completion(.success(metaData)) + return + } + guard splitPath.count > 1 else { completion(.failure(RedditFeedProviderError.unknown)) return } - let name = "\(splitPath[0])/\(splitPath[1])" - let homePageURL = "https://www.reddit.com/\(name)" + let homePageURL = "https://www.reddit.com/\(splitPath[0])/\(splitPath[1])" subreddit(urlComponents) { result in switch result { @@ -145,7 +152,12 @@ public final class RedditFeedProvider: FeedProvider { return } - let api = "\(urlComponents.path).json" + let api: String + if urlComponents.path == "" || urlComponents.path == "/" { + api = "/best.json" + } else { + api = "\(urlComponents.path).json" + } fetch(api: api, parameters: [:], resultType: RedditLinkListing.self) { result in switch result { diff --git a/Frameworks/Account/FeedProvider/Reddit/RedditSort.swift b/Frameworks/Account/FeedProvider/Reddit/RedditSort.swift new file mode 100644 index 000000000..345443323 --- /dev/null +++ b/Frameworks/Account/FeedProvider/Reddit/RedditSort.swift @@ -0,0 +1,32 @@ +// +// RedditSort.swift +// Account +// +// Created by Maurice Parker on 5/7/20. +// Copyright © 2020 Ranchero Software, LLC. All rights reserved. +// + +import Foundation + +enum RedditSort: String, CaseIterable { + case best + case rising + case hot + case new + case top + + var displayName: String { + switch self { + case .best: + return NSLocalizedString("Best", comment: "Best") + case .rising: + return NSLocalizedString("Rising", comment: "Rising") + case .hot: + return NSLocalizedString("Hot", comment: "Hot") + case .new: + return NSLocalizedString("New", comment: "New") + case .top: + return NSLocalizedString("Top", comment: "Top") + } + } +}