Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit ccccd88

Browse files
authored
Improve Insight entities parsing (#772)
2 parents e8b69e3 + 062f526 commit ccccd88

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Sources/WordPressKit/Models/Stats/Insights/StatsAllTimesInsight.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ extension StatsAllTimesInsight: StatsInsightData {
3535
let rootContainer = try decoder.container(keyedBy: RootKeys.self)
3636
let container = try rootContainer.nestedContainer(keyedBy: CodingKeys.self, forKey: .stats)
3737

38-
self.postsCount = try container.decodeIfPresent(Int.self, forKey: .postsCount) ?? 0
39-
self.bestViewsPerDayCount = try container.decode(Int.self, forKey: .bestViewsPerDayCount)
40-
self.visitorsCount = try container.decodeIfPresent(Int.self, forKey: .visitorsCount) ?? 0
38+
self.postsCount = (try? container.decodeIfPresent(Int.self, forKey: .postsCount)) ?? 0
39+
self.bestViewsPerDayCount = (try? container.decodeIfPresent(Int.self, forKey: .bestViewsPerDayCount)) ?? 0
40+
self.visitorsCount = (try? container.decodeIfPresent(Int.self, forKey: .visitorsCount)) ?? 0
4141

42-
self.viewsCount = try container.decodeIfPresent(Int.self, forKey: .viewsCount) ?? 0
42+
self.viewsCount = (try? container.decodeIfPresent(Int.self, forKey: .viewsCount)) ?? 0
4343
let bestViewsDayString = try container.decodeIfPresent(String.self, forKey: .bestViewsDay) ?? ""
4444
self.bestViewsDay = StatsAllTimesInsight.dateFormatter.date(from: bestViewsDayString) ?? Date()
4545
}

Sources/WordPressKit/Models/Stats/Insights/StatsTagsAndCategoriesInsight.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extension StatsTagAndCategory {
4747
let container = try decoder.container(keyedBy: CodingKeys.self)
4848

4949
let innerTags = try container.decodeIfPresent([StatsTagAndCategory].self, forKey: .children) ?? []
50-
let viewsCount = try container.decodeIfPresent(Int.self, forKey: .viewsCount)
50+
let viewsCount = (try? container.decodeIfPresent(Int.self, forKey: .viewsCount)) ?? 0
5151

5252
// This gets kinda complicated. The API collects some tags/categories
5353
// into groups, and we have to handle that.

0 commit comments

Comments
 (0)