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

Commit 0fce69e

Browse files
authored
Merge pull request #138 from wordpress-mobile/feature/fix-parsing-for-empty-data-sets
fix parsing stats data for empty data sets
2 parents 30c743c + 7fbf3e9 commit 0fce69e

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

WordPressKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "WordPressKit"
3-
s.version = "3.2.1"
3+
s.version = "3.2.2.beta-1"
44
s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API."
55

66
s.description = <<-DESC

WordPressKit/Time Interval/StatsTopClicksTimeIntervalData.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,13 @@ extension StatsTopClicksTimeIntervalData: StatsTimeIntervalData {
4949
public init?(date: Date, period: StatsPeriodUnit, jsonDictionary: [String : AnyObject]) {
5050
guard
5151
let unwrappedDays = type(of: self).unwrapDaysDictionary(jsonDictionary: jsonDictionary),
52-
let totalClicks = unwrappedDays["total_clicks"] as? Int,
53-
let otherClicks = unwrappedDays["other_clicks"] as? Int,
5452
let clicks = unwrappedDays["clicks"] as? [[String: AnyObject]]
5553
else {
5654
return nil
5755
}
5856

59-
57+
let totalClicks = unwrappedDays["total_clicks"] as? Int ?? 0
58+
let otherClicks = unwrappedDays["other_clicks"] as? Int ?? 0
6059

6160
self.period = period
6261
self.periodEndDate = date

WordPressKit/Time Interval/StatsTopCountryTimeIntervalData.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ extension StatsTopCountryTimeIntervalData: StatsTimeIntervalData {
4141

4242
public init?(date: Date, period: StatsPeriodUnit, jsonDictionary: [String : AnyObject]) {
4343
guard
44-
let countryInfo = jsonDictionary["country-info"] as? [String: AnyObject],
4544
let unwrappedDays = type(of: self).unwrapDaysDictionary(jsonDictionary: jsonDictionary),
46-
let totalViews = unwrappedDays["total_views"] as? Int,
47-
let otherViews = unwrappedDays["other_views"] as? Int,
4845
let countriesViews = unwrappedDays["views"] as? [[String: AnyObject]]
4946
else {
5047
return nil
5148
}
5249

50+
let countryInfo = jsonDictionary["country-info"] as? [String: AnyObject] ?? [:]
51+
let totalViews = unwrappedDays["total_views"] as? Int ?? 0
52+
let otherViews = unwrappedDays["other_views"] as? Int ?? 0
53+
5354
self.periodEndDate = date
5455
self.period = period
5556

WordPressKit/Time Interval/StatsTopPostsTimeIntervalData.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ extension StatsTopPostsTimeIntervalData: StatsTimeIntervalData {
2727
public init?(date: Date, period: StatsPeriodUnit, jsonDictionary: [String : AnyObject]) {
2828
guard
2929
let unwrappedDays = type(of: self).unwrapDaysDictionary(jsonDictionary: jsonDictionary),
30-
let posts = unwrappedDays["postviews"] as? [[String: AnyObject]],
31-
let totalViews = unwrappedDays["total_views"] as? Int,
32-
let otherViews = unwrappedDays["other_views"] as? Int
30+
let posts = unwrappedDays["postviews"] as? [[String: AnyObject]]
3331
else {
3432
return nil
3533
}
3634

35+
let totalViews = unwrappedDays["total_views"] as? Int ?? 0
36+
let otherViews = unwrappedDays["other_views"] as? Int ?? 0
37+
3738
self.periodEndDate = date
3839
self.period = period
3940
self.totalViewsCount = totalViews

WordPressKit/Time Interval/StatsTopReferrersTimeIntervalData.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ extension StatsTopReferrersTimeIntervalData: StatsTimeIntervalData {
4949
public init?(date: Date, period: StatsPeriodUnit, jsonDictionary: [String : AnyObject]) {
5050
guard
5151
let unwrappedDays = type(of: self).unwrapDaysDictionary(jsonDictionary: jsonDictionary),
52-
let totalClicks = unwrappedDays["total_views"] as? Int,
53-
let otherClicks = unwrappedDays["other_views"] as? Int,
5452
let referrers = unwrappedDays["groups"] as? [[String: AnyObject]]
5553
else {
5654
return nil
5755
}
5856

57+
let totalClicks = unwrappedDays["total_views"] as? Int ?? 0
58+
let otherClicks = unwrappedDays["other_views"] as? Int ?? 0
59+
5960
self.period = period
6061
self.periodEndDate = date
6162
self.totalReferrerViewsCount = totalClicks

0 commit comments

Comments
 (0)