Skip to content

Commit

Permalink
fixing issue #64
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Dec 21, 2023
1 parent e33d5b7 commit 9000336
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
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 @@ public extension WordPressPost {
guard let modifiedDate = item.wpModifiedDate else {
throw WordPressError.missingField(.modifiedDate)
}
guard let link = item.link else {
throw WordPressError.missingField(.link)
}

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

0 comments on commit 9000336

Please sign in to comment.