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

Commit 807ea5d

Browse files
authored
Merge pull request #162 from wordpress-mobile/feature/stats_get_all_annual_insights
[Stats Refresh] Get all years for Annual insights
2 parents f74c7e2 + 8633177 commit 807ea5d

File tree

4 files changed

+83
-3
lines changed

4 files changed

+83
-3
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.1.3"
3+
s.version = "4.2.0-beta.1"
44
s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API."
55

66
s.description = <<-DESC

WordPressKit.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@
420420
93F50A441F227CFB00B5BEBA /* UsersServiceRemoteXMLRPCTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93F50A431F227CFB00B5BEBA /* UsersServiceRemoteXMLRPCTests.swift */; };
421421
93F50A471F227F3600B5BEBA /* xmlrpc-response-getprofile.xml in Resources */ = {isa = PBXBuildFile; fileRef = 93F50A451F227F3600B5BEBA /* xmlrpc-response-getprofile.xml */; };
422422
93F50A481F227F3600B5BEBA /* xmlrpc-response-valid-but-unexpected-dictionary.xml in Resources */ = {isa = PBXBuildFile; fileRef = 93F50A461F227F3600B5BEBA /* xmlrpc-response-valid-but-unexpected-dictionary.xml */; };
423+
98DC787522BAEBF200267279 /* StatsAllAnnualInsight.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98DC787422BAEBF100267279 /* StatsAllAnnualInsight.swift */; };
423424
9A2D0B28225E0119009E585F /* JetpackServiceRemote.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A2D0B27225E0119009E585F /* JetpackServiceRemote.swift */; };
424425
9A2D0B2B225E0E22009E585F /* JetpackServiceRemoteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A2D0B2A225E0E22009E585F /* JetpackServiceRemoteTests.swift */; };
425426
9A2D0B2F225E1245009E585F /* jetpack-service-check-site-success.json in Resources */ = {isa = PBXBuildFile; fileRef = 9A2D0B2C225E1038009E585F /* jetpack-service-check-site-success.json */; };
@@ -938,6 +939,7 @@
938939
93F50A431F227CFB00B5BEBA /* UsersServiceRemoteXMLRPCTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UsersServiceRemoteXMLRPCTests.swift; sourceTree = "<group>"; };
939940
93F50A451F227F3600B5BEBA /* xmlrpc-response-getprofile.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "xmlrpc-response-getprofile.xml"; sourceTree = "<group>"; };
940941
93F50A461F227F3600B5BEBA /* xmlrpc-response-valid-but-unexpected-dictionary.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "xmlrpc-response-valid-but-unexpected-dictionary.xml"; sourceTree = "<group>"; };
942+
98DC787422BAEBF100267279 /* StatsAllAnnualInsight.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatsAllAnnualInsight.swift; sourceTree = "<group>"; };
941943
9A2D0B27225E0119009E585F /* JetpackServiceRemote.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackServiceRemote.swift; sourceTree = "<group>"; };
942944
9A2D0B2A225E0E22009E585F /* JetpackServiceRemoteTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackServiceRemoteTests.swift; sourceTree = "<group>"; };
943945
9A2D0B2C225E1038009E585F /* jetpack-service-check-site-success.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "jetpack-service-check-site-success.json"; sourceTree = "<group>"; };
@@ -1092,6 +1094,7 @@
10921094
4041405F220F9F1F00CF7C5B /* StatsAllTimesInsight.swift */,
10931095
40E7FEAD220FAEA10032834E /* StatsPublicizeInsight.swift */,
10941096
40E7FEB0220FB3B60032834E /* StatsAnnualAndMostPopularTimeInsight.swift */,
1097+
98DC787422BAEBF100267279 /* StatsAllAnnualInsight.swift */,
10951098
40E7FEB3221063480032834E /* StatsTodayInsight.swift */,
10961099
40E7FEB622106A8D0032834E /* StatsCommentsInsight.swift */,
10971100
40E7FEB92210894B0032834E /* StatsTagsAndCategoriesInsight.swift */,
@@ -2459,6 +2462,7 @@
24592462
17CE77F120C6EB41001DEA5A /* ReaderFeed.swift in Sources */,
24602463
93C674F21EE8351E00BFAF05 /* NSMutableDictionary+Helpers.m in Sources */,
24612464
74D67F061F1528470010C5ED /* PeopleServiceRemote.swift in Sources */,
2465+
98DC787522BAEBF200267279 /* StatsAllAnnualInsight.swift in Sources */,
24622466
740B23C31F17EE8000067A2A /* RemotePostCategory.m in Sources */,
24632467
74B5F0E71EF8699C00B411E7 /* RemotePostType.m in Sources */,
24642468
93188D1F1F2262BF0028ED4D /* RemotePostTag.m in Sources */,
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
public struct StatsAllAnnualInsight {
2+
public let allAnnualInsights: [StatsAnnualInsight]
3+
4+
public init(allAnnualInsights: [StatsAnnualInsight]) {
5+
self.allAnnualInsights = allAnnualInsights
6+
}
7+
}
8+
9+
public struct StatsAnnualInsight {
10+
public let year: Int
11+
public let totalPostsCount: Int
12+
public let totalWordsCount: Int
13+
public let averageWordsCount: Double
14+
public let totalLikesCount: Int
15+
public let averageLikesCount: Double
16+
public let totalCommentsCount: Int
17+
public let averageCommentsCount: Double
18+
public let totalImagesCount: Int
19+
public let averageImagesCount: Double
20+
21+
public init(year: Int,
22+
totalPostsCount: Int,
23+
totalWordsCount: Int,
24+
averageWordsCount: Double,
25+
totalLikesCount: Int,
26+
averageLikesCount: Double,
27+
totalCommentsCount: Int,
28+
averageCommentsCount: Double,
29+
totalImagesCount: Int,
30+
averageImagesCount: Double) {
31+
self.year = year
32+
self.totalPostsCount = totalPostsCount
33+
self.totalWordsCount = totalWordsCount
34+
self.averageWordsCount = averageWordsCount
35+
self.totalLikesCount = totalLikesCount
36+
self.averageLikesCount = averageLikesCount
37+
self.totalCommentsCount = totalCommentsCount
38+
self.averageCommentsCount = averageCommentsCount
39+
self.totalImagesCount = totalImagesCount
40+
self.averageImagesCount = averageImagesCount
41+
}
42+
}
43+
44+
extension StatsAllAnnualInsight: StatsInsightData {
45+
public static var pathComponent: String {
46+
return "stats/insights"
47+
}
48+
49+
public init?(jsonDictionary: [String : AnyObject]) {
50+
guard let yearlyInsights = jsonDictionary["years"] as? [[String: AnyObject]] else {
51+
return nil
52+
}
53+
54+
let allAnnualInsights: [StatsAnnualInsight] = yearlyInsights.compactMap {
55+
guard let yearString = $0["year"] as? String,
56+
let year = Int(yearString) else {
57+
return nil
58+
}
59+
60+
return StatsAnnualInsight(year: year,
61+
totalPostsCount: $0["total_posts"] as? Int ?? 0,
62+
totalWordsCount: $0["total_words"] as? Int ?? 0,
63+
averageWordsCount: $0["avg_words"] as? Double ?? 0,
64+
totalLikesCount: $0["total_likes"] as? Int ?? 0,
65+
averageLikesCount: $0["avg_likes"] as? Double ?? 0,
66+
totalCommentsCount: $0["total_comments"] as? Int ?? 0,
67+
averageCommentsCount: $0["avg_comments"] as? Double ?? 0,
68+
totalImagesCount: $0["total_images"] as? Int ?? 0,
69+
averageImagesCount: $0["avg_images"] as? Double ?? 0)
70+
}
71+
72+
self.allAnnualInsights = allAnnualInsights
73+
}
74+
}

WordPressKit/StatsServiceRemoteV2.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ public class StatsServiceRemoteV2: ServiceRemoteWordPressComREST {
125125
}
126126
}
127127

128-
// MARK: - StatsLastPostInsight-specific hack
128+
// MARK: - StatsLastPostInsight Handling
129+
129130
extension StatsServiceRemoteV2 {
130131
// "Last Post" Insights are "fun" in the way that they require multiple requests to actually create them,
131132
// so we do this "fun" dance in a separate method.
@@ -187,7 +188,8 @@ extension StatsServiceRemoteV2 {
187188
}
188189
}
189190

190-
// MARK - StatsPublishedPostsTimeIntervalData-specific hack
191+
// MARK - StatsPublishedPostsTimeIntervalData Handling
192+
191193
extension StatsServiceRemoteV2 {
192194

193195
// StatsPublishedPostsTimeIntervalData hit a different endpoint and with different parameters

0 commit comments

Comments
 (0)