Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Option Link for RSS #65

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,410 changes: 4,410 additions & 0 deletions Data/XML/wait-wait-dont-tell-me.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Sources/SyndiKit/Common/Entryable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public protocol Entryable {
/// Unique Identifier of the Item.
var id: EntryID { get }
/// The URL of the item.
var url: URL { get }
var url: URL? { get }
/// The title of the item.
var title: String { get }
/// HTML content of the item.
Expand Down
6 changes: 2 additions & 4 deletions Sources/SyndiKit/Formats/Feeds/Atom/AtomEntry.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Foundation

public struct AtomEntry: Codable {
public static let defaultURL = URL(string: "/")!

/// A permanent, universally unique identifier for an entry.
public let id: EntryID

Expand Down Expand Up @@ -61,8 +59,8 @@ extension AtomEntry: Entryable {
atomCategories
}

public var url: URL {
links.first?.href ?? Self.defaultURL
public var url: URL? {
links.first?.href
}

public var contentHtml: String? {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SyndiKit/Formats/Feeds/JSONFeed/JSONItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

public struct JSONItem: Codable {
public let guid: EntryID
public let url: URL
public let url: URL?
public let title: String
public let contentHtml: String?
public let summary: String?
Expand Down
6 changes: 3 additions & 3 deletions Sources/SyndiKit/Formats/Feeds/RSS/RSSItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import XMLCoder

public struct RSSItem: Codable {
public let title: String
public let link: URL
public let link: URL?
public let description: CData?
public let guid: EntryID
public let pubDate: Date?
Expand Down Expand Up @@ -135,7 +135,7 @@ public struct RSSItem: Codable {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
title = try container.decode(String.self, forKey: .title)
link = try container.decode(URL.self, forKey: .link)
link = try container.decodeIfPresent(URL.self, forKey: .link)
description = try container.decodeIfPresent(CData.self, forKey: .description)
guid = try container.decode(EntryID.self, forKey: .guid)
pubDate = try container.decodeDateIfPresentAndValid(forKey: .pubDate)
Expand Down Expand Up @@ -297,7 +297,7 @@ extension RSSItem: Entryable {
categoryTerms
}

public var url: URL {
public var url: URL? {
link
}

Expand Down
4 changes: 3 additions & 1 deletion Sources/SyndiKit/Formats/Media/Wordpress/WordPressPost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@
guard let modifiedDate = item.wpModifiedDate else {
throw WordPressError.missingField(.modifiedDate)
}
guard let link = item.link else {
throw WordPressError.missingField(.link)

Check warning on line 153 in Sources/SyndiKit/Formats/Media/Wordpress/WordPressPost.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SyndiKit/Formats/Media/Wordpress/WordPressPost.swift#L153

Added line #L153 was not covered by tests
}

let title = item.title
let link = item.link
let categoryTerms = item.categoryTerms
let meta = item.wpPostMeta
let pubDate = item.pubDate
Expand Down
21 changes: 21 additions & 0 deletions Tests/SyndiKitTests/RSSCodedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,27 @@ public final class SyndiKitTests: XCTestCase {
try assertInvalidGeoData(from: invalidCoords)
}

func testPodcastMissingLink() throws {
guard let feed = try? Content.xmlFeeds["wait-wait-dont-tell-me"]?.get() else {
XCTFail("Missing Podcast \(name)")
return
}

guard let rss = feed as? RSSFeed else {
XCTFail("Wrong Type \(name)")
return
}

guard rss.channel.items.count > 193 else {
XCTFail("Missing Item \(name)")
return
}

let item = rss.channel.items[193]

XCTAssertNil(item.link)
}

private func assertInvalidGeoData(from xmlStr: String) throws {
guard let data = xmlStr.data(using: .utf8) else {
XCTFail("Expected data out of \(xmlStr)")
Expand Down
Loading