From 390675d35dfcf54fcb5e309e322f878983baa9c9 Mon Sep 17 00:00:00 2001 From: Jan Klausa Date: Thu, 28 Mar 2019 01:23:59 +0100 Subject: [PATCH 1/2] fix parsing stats data for empty data sets --- WordPressKit.podspec | 2 +- .../Time Interval/StatsTopClicksTimeIntervalData.swift | 5 ++--- .../Time Interval/StatsTopCountryTimeIntervalData.swift | 7 ++++--- .../Time Interval/StatsTopPostsTimeIntervalData.swift | 7 ++++--- .../Time Interval/StatsTopReferrersTimeIntervalData.swift | 5 +++-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/WordPressKit.podspec b/WordPressKit.podspec index c68cd9f1..9debc476 100644 --- a/WordPressKit.podspec +++ b/WordPressKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "WordPressKit" - s.version = "3.2.1" + s.version = "3.2.2.beta-2" s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API." s.description = <<-DESC diff --git a/WordPressKit/Time Interval/StatsTopClicksTimeIntervalData.swift b/WordPressKit/Time Interval/StatsTopClicksTimeIntervalData.swift index 72ef8fa9..fffa71af 100644 --- a/WordPressKit/Time Interval/StatsTopClicksTimeIntervalData.swift +++ b/WordPressKit/Time Interval/StatsTopClicksTimeIntervalData.swift @@ -49,14 +49,13 @@ extension StatsTopClicksTimeIntervalData: StatsTimeIntervalData { public init?(date: Date, period: StatsPeriodUnit, jsonDictionary: [String : AnyObject]) { guard let unwrappedDays = type(of: self).unwrapDaysDictionary(jsonDictionary: jsonDictionary), - let totalClicks = unwrappedDays["total_clicks"] as? Int, - let otherClicks = unwrappedDays["other_clicks"] as? Int, let clicks = unwrappedDays["clicks"] as? [[String: AnyObject]] else { return nil } - + let totalClicks = unwrappedDays["total_clicks"] as? Int ?? 0 + let otherClicks = unwrappedDays["other_clicks"] as? Int ?? 0 self.period = period self.periodEndDate = date diff --git a/WordPressKit/Time Interval/StatsTopCountryTimeIntervalData.swift b/WordPressKit/Time Interval/StatsTopCountryTimeIntervalData.swift index 1e1c0c71..1865169c 100644 --- a/WordPressKit/Time Interval/StatsTopCountryTimeIntervalData.swift +++ b/WordPressKit/Time Interval/StatsTopCountryTimeIntervalData.swift @@ -41,15 +41,16 @@ extension StatsTopCountryTimeIntervalData: StatsTimeIntervalData { public init?(date: Date, period: StatsPeriodUnit, jsonDictionary: [String : AnyObject]) { guard - let countryInfo = jsonDictionary["country-info"] as? [String: AnyObject], let unwrappedDays = type(of: self).unwrapDaysDictionary(jsonDictionary: jsonDictionary), - let totalViews = unwrappedDays["total_views"] as? Int, - let otherViews = unwrappedDays["other_views"] as? Int, let countriesViews = unwrappedDays["views"] as? [[String: AnyObject]] else { return nil } + let countryInfo = jsonDictionary["country-info"] as? [String: AnyObject] ?? [:] + let totalViews = unwrappedDays["total_views"] as? Int ?? 0 + let otherViews = unwrappedDays["other_views"] as? Int ?? 0 + self.periodEndDate = date self.period = period diff --git a/WordPressKit/Time Interval/StatsTopPostsTimeIntervalData.swift b/WordPressKit/Time Interval/StatsTopPostsTimeIntervalData.swift index d3e8eab8..0443c8e0 100644 --- a/WordPressKit/Time Interval/StatsTopPostsTimeIntervalData.swift +++ b/WordPressKit/Time Interval/StatsTopPostsTimeIntervalData.swift @@ -27,13 +27,14 @@ extension StatsTopPostsTimeIntervalData: StatsTimeIntervalData { public init?(date: Date, period: StatsPeriodUnit, jsonDictionary: [String : AnyObject]) { guard let unwrappedDays = type(of: self).unwrapDaysDictionary(jsonDictionary: jsonDictionary), - let posts = unwrappedDays["postviews"] as? [[String: AnyObject]], - let totalViews = unwrappedDays["total_views"] as? Int, - let otherViews = unwrappedDays["other_views"] as? Int + let posts = unwrappedDays["postviews"] as? [[String: AnyObject]] else { return nil } + let totalViews = unwrappedDays["total_views"] as? Int ?? 0 + let otherViews = unwrappedDays["other_views"] as? Int ?? 0 + self.periodEndDate = date self.period = period self.totalViewsCount = totalViews diff --git a/WordPressKit/Time Interval/StatsTopReferrersTimeIntervalData.swift b/WordPressKit/Time Interval/StatsTopReferrersTimeIntervalData.swift index aa358051..46e168ef 100644 --- a/WordPressKit/Time Interval/StatsTopReferrersTimeIntervalData.swift +++ b/WordPressKit/Time Interval/StatsTopReferrersTimeIntervalData.swift @@ -49,13 +49,14 @@ extension StatsTopReferrersTimeIntervalData: StatsTimeIntervalData { public init?(date: Date, period: StatsPeriodUnit, jsonDictionary: [String : AnyObject]) { guard let unwrappedDays = type(of: self).unwrapDaysDictionary(jsonDictionary: jsonDictionary), - let totalClicks = unwrappedDays["total_views"] as? Int, - let otherClicks = unwrappedDays["other_views"] as? Int, let referrers = unwrappedDays["groups"] as? [[String: AnyObject]] else { return nil } + let totalClicks = unwrappedDays["total_views"] as? Int ?? 0 + let otherClicks = unwrappedDays["other_views"] as? Int ?? 0 + self.period = period self.periodEndDate = date self.totalReferrerViewsCount = totalClicks From 7fbf3e95bb169656e9f9c5c0762c6f76df1b9f86 Mon Sep 17 00:00:00 2001 From: Jan Klausa Date: Thu, 28 Mar 2019 21:57:46 +0100 Subject: [PATCH 2/2] Update WordPressKit.podspec --- WordPressKit.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPressKit.podspec b/WordPressKit.podspec index 9debc476..ab83aa36 100644 --- a/WordPressKit.podspec +++ b/WordPressKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "WordPressKit" - s.version = "3.2.2.beta-2" + s.version = "3.2.2.beta-1" s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API." s.description = <<-DESC