Skip to content

Commit

Permalink
Merge pull request #69 from brightdigit/v0.4.0-STRICT-changes
Browse files Browse the repository at this point in the history
V0.4.0 strict changes
  • Loading branch information
leogdion committed Jan 25, 2024
2 parents 50dd741 + e260197 commit 586eb34
Show file tree
Hide file tree
Showing 15 changed files with 340 additions and 375 deletions.
2 changes: 1 addition & 1 deletion Sources/SyndiKit/Common/Author.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public struct Author: Codable, Equatable {
/// Contains a home page for the person.
public let uri: URL?

internal init(name: String) {
public init(name: String) {
self.name = name
email = nil
uri = nil
Expand Down
4 changes: 0 additions & 4 deletions Sources/SyndiKit/Decoding/DateFormatterDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ internal struct DateFormatterDecoder {

private let formatters: [DateFormatter]

internal init(formatters: [DateFormatter]) {
self.formatters = formatters
}

internal init(basedOnFormats formats: [String]) {
formatters = formats.map(Self.isoPOSIX(withFormat:))
}
Expand Down
12 changes: 12 additions & 0 deletions Sources/SyndiKit/Decoding/DecodingError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,16 @@ extension DecodingError {
)
return DecodingError.dataCorrupted(context)
}

internal static func dataCorrupted(
codingKey: CodingKey,
debugDescription: String
) -> Self {
DecodingError.dataCorrupted(
.init(
codingPath: [codingKey],
debugDescription: debugDescription
)
)
}
}
1 change: 1 addition & 0 deletions Sources/SyndiKit/Decoding/SynDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class SynDecoder {
return decoder
}()

// swiftlint:disable:next closure_body_length
private lazy var decodings: [DecoderSource: [String: AnyDecoding]] = {
let decodings = types.map { type -> (DecoderSource, AnyDecoding) in
let source = type.source
Expand Down
1 change: 1 addition & 0 deletions Sources/SyndiKit/Formats/Blogs/SiteDirectory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public struct SiteCollectionDirectory: SiteDirectory {
internal let languageIndicies: [SiteLanguageType: Set<Int>]
internal let categoryIndicies: [SiteCategoryType: Set<Int>]

// swiftlint:disable:next function_body_length
internal func sites(
withLanguage language: SiteLanguageType?,
withCategory category: SiteCategoryType?
Expand Down
14 changes: 10 additions & 4 deletions Sources/SyndiKit/Formats/Feeds/RSS/Enclosure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,27 @@ public struct Enclosure: Codable {
let container = try decoder.container(keyedBy: Self.CodingKeys.self)
url = try container.decode(UTF8EncodedURL.self, forKey: .url).value
type = try container.decode(String.self, forKey: .type)
length = try Self.decodeLength(from: container)
}

private static func decodeLength(
from container: KeyedDecodingContainer<CodingKeys>
) throws -> Int? {
if container.contains(.length) {
do {
length = try container.decode(Int.self, forKey: .length)
return try container.decode(Int.self, forKey: .length)
} catch {
let lengthString = try container.decode(String.self, forKey: .length)
if lengthString.isEmpty {
length = nil
return nil
} else if let length = Int(lengthString) {
self.length = length
return length

Check warning on line 32 in Sources/SyndiKit/Formats/Feeds/RSS/Enclosure.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SyndiKit/Formats/Feeds/RSS/Enclosure.swift#L32

Added line #L32 was not covered by tests
} else {
throw error
}
}
} else {
length = nil
return nil

Check warning on line 38 in Sources/SyndiKit/Formats/Feeds/RSS/Enclosure.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SyndiKit/Formats/Feeds/RSS/Enclosure.swift#L38

Added line #L38 was not covered by tests
}
}
}
117 changes: 117 additions & 0 deletions Sources/SyndiKit/Formats/Feeds/RSS/RSSItem+decodings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import Foundation
import XMLCoder

extension RSSItem {
// swiftlint:disable:next function_body_length
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.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)
contentEncoded = try container.decodeIfPresent(CData.self, forKey: .contentEncoded)
categoryTerms = try container.decode([RSSItemCategory].self, forKey: .categoryTerms)
content = try container.decodeIfPresent(String.self, forKey: .content)
itunesTitle = try container.decodeIfPresent(String.self, forKey: .itunesTitle)
itunesEpisode = try container.decodeIfPresent(
iTunesEpisode.self, forKey: .itunesEpisode
)
itunesAuthor = try container.decodeIfPresent(String.self, forKey: .itunesAuthor)
itunesSubtitle = try container.decodeIfPresent(String.self, forKey: .itunesSubtitle)
itunesSummary = try container.decodeIfPresent(CData.self, forKey: .itunesSummary)
itunesExplicit = try container.decodeIfPresent(String.self, forKey: .itunesExplicit)
itunesDuration = try container.decodeIfPresent(
iTunesDuration.self, forKey: .itunesDuration
)
itunesImage = try container.decodeIfPresent(iTunesImage.self, forKey: .itunesImage)

podcastPeople = try container.decodeIfPresent(
[PodcastPerson].self,
forKey: .podcastPeople
) ?? []
podcastTranscripts = try container.decodeIfPresent(
[PodcastTranscript].self,
forKey: .podcastTranscripts
) ?? []
podcastChapters = try container.decodeIfPresent(
PodcastChapters.self,
forKey: .podcastChapters
)
podcastSoundbites = try container.decodeIfPresent(
[PodcastSoundbite].self,
forKey: .podcastSoundbites
) ?? []

podcastSeason = try container.decodeIfPresent(
PodcastSeason.self,
forKey: .podcastSeason
)

enclosure = try container.decodeIfPresent(Enclosure.self, forKey: .enclosure)
creators = try container.decode([String].self, forKey: .creators)

mediaContent =
try container.decodeIfPresent(AtomMedia.self, forKey: .mediaContent)
mediaThumbnail =
try container.decodeIfPresent(AtomMedia.self, forKey: .mediaThumbnail)

wpPostID = try container.decodeIfPresent(Int.self, forKey: .wpPostID)
wpPostDate = try container.decodeIfPresent(Date.self, forKey: .wpPostDate)
let wpPostDateGMT = try container.decodeIfPresent(
String.self, forKey: .wpPostDateGMT
)
if let wpPostDateGMT = wpPostDateGMT {
if wpPostDateGMT == "0000-00-00 00:00:00" {
self.wpPostDateGMT = nil
} else {
self.wpPostDateGMT = try container.decode(
Date.self, forKey: .wpPostDateGMT
)
}
} else {
self.wpPostDateGMT = nil
}

wpModifiedDate = try container.decodeIfPresent(
Date.self, forKey: .wpModifiedDate
)

let wpModifiedDateGMT = try container.decodeIfPresent(
String.self, forKey: .wpModifiedDateGMT
)
if let wpModifiedDateGMT = wpModifiedDateGMT {
if wpModifiedDateGMT == "0000-00-00 00:00:00" {
self.wpModifiedDateGMT = nil
} else {
self.wpModifiedDateGMT = try container.decode(
Date.self, forKey: .wpModifiedDateGMT
)
}
} else {
self.wpModifiedDateGMT = nil
}

let wpAttachmentURLCDData = try container.decodeIfPresent(
CData.self,
forKey: .wpAttachmentURL
)
wpAttachmentURL = wpAttachmentURLCDData.map { $0.value }.flatMap(URL.init(string:))

wpPostName = try container.decodeIfPresent(CData.self, forKey: .wpPostName)
wpPostType = try container.decodeIfPresent(CData.self, forKey: .wpPostType)
wpPostMeta = try container.decodeIfPresent(
[WordPressElements.PostMeta].self,
forKey: .wpPostMeta
) ?? []
wpCommentStatus = try container.decodeIfPresent(CData.self, forKey: .wpCommentStatus)
wpPingStatus = try container.decodeIfPresent(CData.self, forKey: .wpPingStatus)
wpStatus = try container.decodeIfPresent(CData.self, forKey: .wpStatus)
wpPostParent = try container.decodeIfPresent(Int.self, forKey: .wpPostParent)
wpMenuOrder = try container.decodeIfPresent(Int.self, forKey: .wpMenuOrder)
wpIsSticky = try container.decodeIfPresent(Int.self, forKey: .wpIsSticky)
wpPostPassword = try container.decodeIfPresent(
CData.self, forKey: .wpPostPassword
)
}
}
91 changes: 91 additions & 0 deletions Sources/SyndiKit/Formats/Feeds/RSS/RSSItem+inits.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import Foundation
import XMLCoder

extension RSSItem {
// swiftlint:disable:next function_body_length
public init(
title: String,
link: URL,
description: String?,
guid: EntryID,
pubDate: Date? = nil,
contentEncoded: String? = nil,
categoryTerms: [RSSItemCategory] = [],
content: String? = nil,
itunesTitle: String? = nil,
itunesEpisode: Int? = nil,
itunesAuthor: String? = nil,
itunesSubtitle: String? = nil,
itunesSummary: CData? = nil,
itunesExplicit: String? = nil,
itunesDuration: TimeInterval? = nil,
itunesImage: iTunesImage? = nil,
podcastPeople: [PodcastPerson] = [],
podcastTranscripts: [PodcastTranscript] = [],
podcastChapters: PodcastChapters? = nil,
podcastSoundbites: [PodcastSoundbite] = [],
podcastSeason: PodcastSeason? = nil,
enclosure: Enclosure? = nil,
creators: [String] = [],
wpCommentStatus: String? = nil,
wpPingStatus: String? = nil,
wpStatus: String? = nil,
wpPostParent: Int? = nil,
wpMenuOrder: Int? = nil,
wpIsSticky: Int? = nil,
wpPostPassword: String? = nil,
wpPostID: Int? = nil,
wpPostDate: Date? = nil,
wpPostDateGMT: Date? = nil,
wpModifiedDate: Date? = nil,
wpModifiedDateGMT: Date? = nil,
wpPostName: String? = nil,
wpPostType: String? = nil,
wpPostMeta: [WordPressElements.PostMeta] = [],
wpAttachmentURL: URL? = nil,
mediaContent: AtomMedia? = nil,
mediaThumbnail: AtomMedia? = nil
) {
self.title = title
self.link = link
self.description = description.map(CData.init)
self.guid = guid
self.pubDate = pubDate
self.contentEncoded = contentEncoded.map(CData.init)
self.categoryTerms = categoryTerms
self.content = content
self.itunesTitle = itunesTitle
self.itunesEpisode = itunesEpisode.map(iTunesEpisode.init)
self.itunesAuthor = itunesAuthor
self.itunesSubtitle = itunesSubtitle
self.itunesSummary = itunesSummary
self.itunesExplicit = itunesExplicit
self.itunesDuration = itunesDuration.map(iTunesDuration.init)
self.itunesImage = itunesImage
self.podcastPeople = podcastPeople
self.podcastTranscripts = podcastTranscripts
self.podcastChapters = podcastChapters
self.podcastSoundbites = podcastSoundbites
self.podcastSeason = podcastSeason
self.enclosure = enclosure
self.creators = creators
self.wpCommentStatus = wpCommentStatus.map(CData.init)
self.wpPingStatus = wpPingStatus.map(CData.init)
self.wpStatus = wpStatus.map(CData.init)
self.wpPostParent = wpPostParent
self.wpMenuOrder = wpMenuOrder
self.wpIsSticky = wpIsSticky
self.wpPostPassword = wpPostPassword.map(CData.init)
self.wpPostID = wpPostID
self.wpPostDate = wpPostDate
self.wpPostDateGMT = wpPostDateGMT
self.wpModifiedDate = wpModifiedDate
self.wpModifiedDateGMT = wpModifiedDateGMT
self.wpPostName = wpPostName.map(CData.init)
self.wpPostType = wpPostType.map(CData.init)
self.wpPostMeta = wpPostMeta
self.wpAttachmentURL = wpAttachmentURL
self.mediaContent = mediaContent
self.mediaThumbnail = mediaThumbnail
}
}
Loading

0 comments on commit 586eb34

Please sign in to comment.