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

Commit 743f8d7

Browse files
committed
Merge branch 'develop' into feature/filter-tldrs-in-domain-suggestions
2 parents 218c869 + 30b720c commit 743f8d7

File tree

7 files changed

+40
-61
lines changed

7 files changed

+40
-61
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 = "4.2.1"
3+
s.version = "4.2.1-beta.2"
44
s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API."
55

66
s.description = <<-DESC

WordPressKit/Insights/StatsAllTimesInsight.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,16 @@ extension StatsAllTimesInsight: StatsInsightData {
2525
public init?(jsonDictionary: [String: AnyObject]) {
2626
guard
2727
let statsDict = jsonDictionary["stats"] as? [String: AnyObject],
28-
let postsCount = statsDict["posts"] as? Int,
29-
let viewsCount = statsDict["views"] as? Int,
30-
let visitorsCount = statsDict["visitors"] as? Int,
31-
let bestViewsPerDayCount = statsDict["views_best_day_total"] as? Int,
3228
let bestViewsDayString = statsDict["views_best_day"] as? String,
3329
let bestViewsDay = StatsAllTimesInsight.dateFormatter.date(from: bestViewsDayString)
3430
else {
3531
return nil
3632
}
3733

38-
self.postsCount = postsCount
39-
self.bestViewsPerDayCount = bestViewsPerDayCount
40-
self.visitorsCount = visitorsCount
41-
self.viewsCount = viewsCount
34+
self.postsCount = statsDict["posts"] as? Int ?? 0
35+
self.bestViewsPerDayCount = statsDict["views_best_day_total"] as? Int ?? 0
36+
self.visitorsCount = statsDict["visitors"] as? Int ?? 0
37+
self.viewsCount = statsDict["views"] as? Int ?? 0
4238
self.bestViewsDay = bestViewsDay
4339
}
4440

WordPressKit/Insights/StatsAnnualAndMostPopularTimeInsight.swift

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,7 @@ extension StatsAnnualAndMostPopularTimeInsight: StatsInsightData {
7474
let yearlyInsights = jsonDictionary["years"] as? [[String: AnyObject]],
7575
let latestYearlyInsight = yearlyInsights.last,
7676
let yearString = latestYearlyInsight["year"] as? String,
77-
let currentYear = Int(yearString),
78-
let postCount = latestYearlyInsight["total_posts"] as? Int,
79-
let wordsCount = latestYearlyInsight["total_words"] as? Int,
80-
let wordsAverage = latestYearlyInsight["avg_words"] as? Double,
81-
let likesCount = latestYearlyInsight["total_likes"] as? Int,
82-
let likesAverage = latestYearlyInsight["avg_likes"] as? Double,
83-
let commentsCount = latestYearlyInsight["total_comments"] as? Int,
84-
let commentsAverage = latestYearlyInsight["avg_comments"] as? Double,
85-
let imagesCount = latestYearlyInsight["total_images"] as? Int,
86-
let imagesAverage = latestYearlyInsight["avg_images"] as? Double
77+
let currentYear = Int(yearString)
8778
else {
8879
return nil
8980
}
@@ -105,17 +96,17 @@ extension StatsAnnualAndMostPopularTimeInsight: StatsInsightData {
10596

10697
self.annualInsightsYear = currentYear
10798

108-
self.annualInsightsTotalPostsCount = postCount
109-
self.annualInsightsTotalWordsCount = wordsCount
110-
self.annualInsightsAverageWordsCount = wordsAverage
99+
self.annualInsightsTotalPostsCount = latestYearlyInsight["total_posts"] as? Int ?? 0
100+
self.annualInsightsTotalWordsCount = latestYearlyInsight["total_words"] as? Int ?? 0
101+
self.annualInsightsAverageWordsCount = latestYearlyInsight["avg_words"] as? Double ?? 0
111102

112-
self.annualInsightsTotalLikesCount = likesCount
113-
self.annualInsightsAverageLikesCount = likesAverage
103+
self.annualInsightsTotalLikesCount = latestYearlyInsight["total_likes"] as? Int ?? 0
104+
self.annualInsightsAverageLikesCount = latestYearlyInsight["avg_likes"] as? Double ?? 0
114105

115-
self.annualInsightsTotalCommentsCount = commentsCount
116-
self.annualInsightsAverageCommentsCount = commentsAverage
106+
self.annualInsightsTotalCommentsCount = latestYearlyInsight["total_comments"] as? Int ?? 0
107+
self.annualInsightsAverageCommentsCount = latestYearlyInsight["avg_comments"] as? Double ?? 0
117108

118-
self.annualInsightsTotalImagesCount = imagesCount
119-
self.annualInsightsAverageImagesCount = imagesAverage
109+
self.annualInsightsTotalImagesCount = latestYearlyInsight["total_images"] as? Int ?? 0
110+
self.annualInsightsAverageImagesCount = latestYearlyInsight["avg_images"] as? Double ?? 0
120111
}
121112
}

WordPressKit/Insights/StatsLastPostInsight.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ extension StatsLastPostInsight: StatsInsightData {
5151
guard
5252
let title = jsonDictionary["title"] as? String,
5353
let dateString = jsonDictionary["date"] as? String,
54+
let date = StatsLastPostInsight.dateFormatter.date(from: dateString),
5455
let urlString = jsonDictionary["URL"] as? String,
56+
let url = URL(string: urlString),
5557
let likesCount = jsonDictionary["like_count"] as? Int,
5658
let postID = jsonDictionary["ID"] as? Int,
5759
let discussionDict = jsonDictionary["discussion"] as? [String: Any],
@@ -60,13 +62,6 @@ extension StatsLastPostInsight: StatsInsightData {
6062
return nil
6163
}
6264

63-
guard
64-
let url = URL(string: urlString),
65-
let date = StatsLastPostInsight.dateFormatter.date(from: dateString)
66-
else {
67-
return nil
68-
}
69-
7065
self.title = title.trimmingCharacters(in: CharacterSet.whitespaces).stringByDecodingXMLCharacters()
7166
self.url = url
7267
self.publishedDate = date

WordPressKit/Insights/StatsPostingStreakInsight.swift

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ extension StatsPostingStreakInsight: StatsInsightData {
7676
let streaks = jsonDictionary["streak"] as? [String: AnyObject],
7777
let longestData = streaks["long"] as? [String: AnyObject],
7878
let currentData = streaks["current"] as? [String: AnyObject],
79-
let longestStart = longestData["start"] as? String,
80-
let longestStartDate = StatsPostingStreakInsight.dateFormatter.date(from: longestStart),
81-
let longestEnd = longestData["end"] as? String,
82-
let longestEndDate = StatsPostingStreakInsight.dateFormatter.date(from: longestEnd),
83-
let longestLength = longestData["length"] as? Int,
8479
let currentStart = currentData["start"] as? String,
8580
let currentStartDate = StatsPostingStreakInsight.dateFormatter.date(from: currentStart),
8681
let currentEnd = currentData["end"] as? String,
@@ -101,13 +96,25 @@ extension StatsPostingStreakInsight: StatsInsightData {
10196
PostingStreakEvent(date: $0 as! Date, postCount: countedPosts.count(for: $0))
10297
}
10398

99+
self.postingEvents = postingEvents
104100
self.currentStreakStart = currentStartDate
105101
self.currentStreakEnd = currentEndDate
106102
self.currentStreakLength = currentLength
107-
self.longestStreakStart = longestStartDate
108-
self.longestStreakEnd = longestEndDate
109-
self.longestStreakLength = longestLength
110-
self.postingEvents = postingEvents
103+
104+
// If there is no longest streak, use the current.
105+
if let longestStart = longestData["start"] as? String,
106+
let longestStartDate = StatsPostingStreakInsight.dateFormatter.date(from: longestStart),
107+
let longestEnd = longestData["end"] as? String,
108+
let longestEndDate = StatsPostingStreakInsight.dateFormatter.date(from: longestEnd),
109+
let longestLength = longestData["length"] as? Int {
110+
self.longestStreakStart = longestStartDate
111+
self.longestStreakEnd = longestEndDate
112+
self.longestStreakLength = longestLength
113+
} else {
114+
self.longestStreakStart = currentStartDate
115+
self.longestStreakEnd = currentEndDate
116+
self.longestStreakLength = currentLength
117+
}
111118
}
112119

113120
private static var dateFormatter: DateFormatter {
@@ -116,6 +123,4 @@ extension StatsPostingStreakInsight: StatsInsightData {
116123
return formatter
117124
}
118125

119-
120-
121126
}

WordPressKit/Insights/StatsTodayInsight.swift

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,9 @@ extension StatsTodayInsight: StatsInsightData {
2323
}
2424

2525
public init?(jsonDictionary: [String: AnyObject]) {
26-
guard
27-
let viewsCount = jsonDictionary["views"] as? Int,
28-
let visitorsCount = jsonDictionary["visitors"] as? Int,
29-
let likesCount = jsonDictionary["likes"] as? Int,
30-
let commentsCount = jsonDictionary["comments"] as? Int
31-
else {
32-
return nil
33-
}
34-
35-
self.visitorsCount = visitorsCount
36-
self.viewsCount = viewsCount
37-
self.likesCount = likesCount
38-
self.commentsCount = commentsCount
26+
self.visitorsCount = jsonDictionary["visitors"] as? Int ?? 0
27+
self.viewsCount = jsonDictionary["views"] as? Int ?? 0
28+
self.likesCount = jsonDictionary["likes"] as? Int ?? 0
29+
self.commentsCount = jsonDictionary["comments"] as? Int ?? 0
3930
}
4031
}

WordPressKit/PostServiceRemoteREST.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,9 @@ - (RemotePost *)remotePostFromJSONDictionary:(NSDictionary *)jsonPost {
438438
post.pathForDisplayImage = post.postThumbnailPath;
439439
} else {
440440
// parse contents for a suitable image
441-
if (!post.pathForDisplayImage) {
442-
post.pathForDisplayImage = [DisplayableImageHelper searchPostContentForImageToDisplay:post.content];
441+
post.pathForDisplayImage = [DisplayableImageHelper searchPostContentForImageToDisplay:post.content];
442+
if ([post.pathForDisplayImage length] == 0) {
443+
post.pathForDisplayImage = [DisplayableImageHelper searchPostAttachmentsForImageToDisplay:[jsonPost dictionaryForKey:@"attachments"] existingInContent:post.content];
443444
}
444445
}
445446

0 commit comments

Comments
 (0)