Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = "4.2.0"
s.version = "4.2.1-beta.1"
s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API."

s.description = <<-DESC
Expand Down
12 changes: 4 additions & 8 deletions WordPressKit/Insights/StatsAllTimesInsight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,16 @@ extension StatsAllTimesInsight: StatsInsightData {
public init?(jsonDictionary: [String: AnyObject]) {
guard
let statsDict = jsonDictionary["stats"] as? [String: AnyObject],
let postsCount = statsDict["posts"] as? Int,
let viewsCount = statsDict["views"] as? Int,
let visitorsCount = statsDict["visitors"] as? Int,
let bestViewsPerDayCount = statsDict["views_best_day_total"] as? Int,
let bestViewsDayString = statsDict["views_best_day"] as? String,
let bestViewsDay = StatsAllTimesInsight.dateFormatter.date(from: bestViewsDayString)
else {
return nil
}

self.postsCount = postsCount
self.bestViewsPerDayCount = bestViewsPerDayCount
self.visitorsCount = visitorsCount
self.viewsCount = viewsCount
self.postsCount = statsDict["posts"] as? Int ?? 0
self.bestViewsPerDayCount = statsDict["views_best_day_total"] as? Int ?? 0
self.visitorsCount = statsDict["visitors"] as? Int ?? 0
self.viewsCount = statsDict["views"] as? Int ?? 0
self.bestViewsDay = bestViewsDay
}

Expand Down
29 changes: 10 additions & 19 deletions WordPressKit/Insights/StatsAnnualAndMostPopularTimeInsight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,7 @@ extension StatsAnnualAndMostPopularTimeInsight: StatsInsightData {
let yearlyInsights = jsonDictionary["years"] as? [[String: AnyObject]],
let latestYearlyInsight = yearlyInsights.last,
let yearString = latestYearlyInsight["year"] as? String,
let currentYear = Int(yearString),
let postCount = latestYearlyInsight["total_posts"] as? Int,
let wordsCount = latestYearlyInsight["total_words"] as? Int,
let wordsAverage = latestYearlyInsight["avg_words"] as? Double,
let likesCount = latestYearlyInsight["total_likes"] as? Int,
let likesAverage = latestYearlyInsight["avg_likes"] as? Double,
let commentsCount = latestYearlyInsight["total_comments"] as? Int,
let commentsAverage = latestYearlyInsight["avg_comments"] as? Double,
let imagesCount = latestYearlyInsight["total_images"] as? Int,
let imagesAverage = latestYearlyInsight["avg_images"] as? Double
let currentYear = Int(yearString)
else {
return nil
}
Expand All @@ -105,17 +96,17 @@ extension StatsAnnualAndMostPopularTimeInsight: StatsInsightData {

self.annualInsightsYear = currentYear

self.annualInsightsTotalPostsCount = postCount
self.annualInsightsTotalWordsCount = wordsCount
self.annualInsightsAverageWordsCount = wordsAverage
self.annualInsightsTotalPostsCount = latestYearlyInsight["total_posts"] as? Int ?? 0
self.annualInsightsTotalWordsCount = latestYearlyInsight["total_words"] as? Int ?? 0
self.annualInsightsAverageWordsCount = latestYearlyInsight["avg_words"] as? Double ?? 0

self.annualInsightsTotalLikesCount = likesCount
self.annualInsightsAverageLikesCount = likesAverage
self.annualInsightsTotalLikesCount = latestYearlyInsight["total_likes"] as? Int ?? 0
self.annualInsightsAverageLikesCount = latestYearlyInsight["avg_likes"] as? Double ?? 0

self.annualInsightsTotalCommentsCount = commentsCount
self.annualInsightsAverageCommentsCount = commentsAverage
self.annualInsightsTotalCommentsCount = latestYearlyInsight["total_comments"] as? Int ?? 0
self.annualInsightsAverageCommentsCount = latestYearlyInsight["avg_comments"] as? Double ?? 0

self.annualInsightsTotalImagesCount = imagesCount
self.annualInsightsAverageImagesCount = imagesAverage
self.annualInsightsTotalImagesCount = latestYearlyInsight["total_images"] as? Int ?? 0
self.annualInsightsAverageImagesCount = latestYearlyInsight["avg_images"] as? Double ?? 0
}
}
9 changes: 2 additions & 7 deletions WordPressKit/Insights/StatsLastPostInsight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ extension StatsLastPostInsight: StatsInsightData {
guard
let title = jsonDictionary["title"] as? String,
let dateString = jsonDictionary["date"] as? String,
let date = StatsLastPostInsight.dateFormatter.date(from: dateString),
let urlString = jsonDictionary["URL"] as? String,
let url = URL(string: urlString),
let likesCount = jsonDictionary["like_count"] as? Int,
let postID = jsonDictionary["ID"] as? Int,
let discussionDict = jsonDictionary["discussion"] as? [String: Any],
Expand All @@ -60,13 +62,6 @@ extension StatsLastPostInsight: StatsInsightData {
return nil
}

guard
let url = URL(string: urlString),
let date = StatsLastPostInsight.dateFormatter.date(from: dateString)
else {
return nil
}

self.title = title.trimmingCharacters(in: CharacterSet.whitespaces).stringByDecodingXMLCharacters()
self.url = url
self.publishedDate = date
Expand Down
27 changes: 16 additions & 11 deletions WordPressKit/Insights/StatsPostingStreakInsight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ extension StatsPostingStreakInsight: StatsInsightData {
let streaks = jsonDictionary["streak"] as? [String: AnyObject],
let longestData = streaks["long"] as? [String: AnyObject],
let currentData = streaks["current"] as? [String: AnyObject],
let longestStart = longestData["start"] as? String,
let longestStartDate = StatsPostingStreakInsight.dateFormatter.date(from: longestStart),
let longestEnd = longestData["end"] as? String,
let longestEndDate = StatsPostingStreakInsight.dateFormatter.date(from: longestEnd),
let longestLength = longestData["length"] as? Int,
let currentStart = currentData["start"] as? String,
let currentStartDate = StatsPostingStreakInsight.dateFormatter.date(from: currentStart),
let currentEnd = currentData["end"] as? String,
Expand All @@ -101,13 +96,25 @@ extension StatsPostingStreakInsight: StatsInsightData {
PostingStreakEvent(date: $0 as! Date, postCount: countedPosts.count(for: $0))
}

self.postingEvents = postingEvents
self.currentStreakStart = currentStartDate
self.currentStreakEnd = currentEndDate
self.currentStreakLength = currentLength
self.longestStreakStart = longestStartDate
self.longestStreakEnd = longestEndDate
self.longestStreakLength = longestLength
self.postingEvents = postingEvents

// If there is no longest streak, use the current.
if let longestStart = longestData["start"] as? String,
let longestStartDate = StatsPostingStreakInsight.dateFormatter.date(from: longestStart),
let longestEnd = longestData["end"] as? String,
let longestEndDate = StatsPostingStreakInsight.dateFormatter.date(from: longestEnd),
let longestLength = longestData["length"] as? Int {
self.longestStreakStart = longestStartDate
self.longestStreakEnd = longestEndDate
self.longestStreakLength = longestLength
} else {
self.longestStreakStart = currentStartDate
self.longestStreakEnd = currentEndDate
self.longestStreakLength = currentLength
}
}

private static var dateFormatter: DateFormatter {
Expand All @@ -116,6 +123,4 @@ extension StatsPostingStreakInsight: StatsInsightData {
return formatter
}



}
17 changes: 4 additions & 13 deletions WordPressKit/Insights/StatsTodayInsight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,9 @@ extension StatsTodayInsight: StatsInsightData {
}

public init?(jsonDictionary: [String: AnyObject]) {
guard
let viewsCount = jsonDictionary["views"] as? Int,
let visitorsCount = jsonDictionary["visitors"] as? Int,
let likesCount = jsonDictionary["likes"] as? Int,
let commentsCount = jsonDictionary["comments"] as? Int
else {
return nil
}

self.visitorsCount = visitorsCount
self.viewsCount = viewsCount
self.likesCount = likesCount
self.commentsCount = commentsCount
self.visitorsCount = jsonDictionary["visitors"] as? Int ?? 0
self.viewsCount = jsonDictionary["views"] as? Int ?? 0
self.likesCount = jsonDictionary["likes"] as? Int ?? 0
self.commentsCount = jsonDictionary["comments"] as? Int ?? 0
}
}