Skip to content

Commit

Permalink
Make values and value-types optional when parsing Insight entity counts
Browse files Browse the repository at this point in the history
  • Loading branch information
staskus committed Apr 1, 2024
1 parent 6a3b5c8 commit 062f526
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ extension StatsAllTimesInsight: StatsInsightData {
let rootContainer = try decoder.container(keyedBy: RootKeys.self)
let container = try rootContainer.nestedContainer(keyedBy: CodingKeys.self, forKey: .stats)

self.postsCount = try container.decodeIfPresent(Int.self, forKey: .postsCount) ?? 0
self.bestViewsPerDayCount = try container.decode(Int.self, forKey: .bestViewsPerDayCount)
self.visitorsCount = try container.decodeIfPresent(Int.self, forKey: .visitorsCount) ?? 0
self.postsCount = (try? container.decodeIfPresent(Int.self, forKey: .postsCount)) ?? 0
self.bestViewsPerDayCount = (try? container.decodeIfPresent(Int.self, forKey: .bestViewsPerDayCount)) ?? 0
self.visitorsCount = (try? container.decodeIfPresent(Int.self, forKey: .visitorsCount)) ?? 0

self.viewsCount = try container.decodeIfPresent(Int.self, forKey: .viewsCount) ?? 0
self.viewsCount = (try? container.decodeIfPresent(Int.self, forKey: .viewsCount)) ?? 0
let bestViewsDayString = try container.decodeIfPresent(String.self, forKey: .bestViewsDay) ?? ""
self.bestViewsDay = StatsAllTimesInsight.dateFormatter.date(from: bestViewsDayString) ?? Date()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension StatsTagAndCategory {
let container = try decoder.container(keyedBy: CodingKeys.self)

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

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

0 comments on commit 062f526

Please sign in to comment.