Skip to content

Commit

Permalink
Merge pull request #138 from wordpress-mobile/feature/fix-parsing-for…
Browse files Browse the repository at this point in the history
…-empty-data-sets

fix parsing stats data for empty data sets
  • Loading branch information
jklausa authored Mar 28, 2019
2 parents 30c743c + 7fbf3e9 commit 0fce69e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion WordPressKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "WordPressKit"
s.version = "3.2.1"
s.version = "3.2.2.beta-1"
s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API."

s.description = <<-DESC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0fce69e

Please sign in to comment.