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

Commit c71dcc4

Browse files
authored
Merge pull request #125 from wordpress-mobile/feature/initializers
Provide memberwise initializers for Stats Insights objects.
2 parents 83483a8 + b5d26f5 commit c71dcc4

10 files changed

+163
-12
lines changed

WordPressKit/Insights/StatsAllTimesInsight.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ public struct StatsAllTimesInsight {
44
public let bestViewsDay: Date
55
public let visitorsCount: Int
66
public let bestViewsPerDayCount: Int
7+
8+
public init(postsCount: Int,
9+
viewsCount: Int,
10+
bestViewsDay: Date,
11+
visitorsCount: Int,
12+
bestViewsPerDayCount: Int) {
13+
self.postsCount = postsCount
14+
self.viewsCount = viewsCount
15+
self.bestViewsDay = bestViewsDay
16+
self.visitorsCount = visitorsCount
17+
self.bestViewsPerDayCount = bestViewsPerDayCount
18+
}
719
}
820

921

WordPressKit/Insights/StatsAnnualAndMostPopularTimeInsight.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,42 @@ public struct StatsAnnualAndMostPopularTimeInsight {
2222

2323
public let annualInsightsTotalImagesCount: Int
2424
public let annualInsightsAverageImagesCount: Double
25+
26+
public init(mostPopularDayOfWeek: DateComponents,
27+
mostPopularDayOfWeekPercentage: Int,
28+
mostPopularHour: DateComponents,
29+
mostPopularHourPercentage: Int,
30+
annualInsightsYear: Int,
31+
annualInsightsTotalPostsCount: Int,
32+
annualInsightsTotalWordsCount: Int,
33+
annualInsightsAverageWordsCount: Double,
34+
annualInsightsTotalLikesCount: Int,
35+
annualInsightsAverageLikesCount: Double,
36+
annualInsightsTotalCommentsCount: Int,
37+
annualInsightsAverageCommentsCount: Double,
38+
annualInsightsTotalImagesCount: Int,
39+
annualInsightsAverageImagesCount: Double) {
40+
self.mostPopularDayOfWeek = mostPopularDayOfWeek
41+
self.mostPopularDayOfWeekPercentage = mostPopularDayOfWeekPercentage
42+
43+
self.mostPopularHour = mostPopularHour
44+
self.mostPopularHourPercentage = mostPopularHourPercentage
45+
46+
self.annualInsightsYear = annualInsightsYear
47+
48+
self.annualInsightsTotalPostsCount = annualInsightsTotalPostsCount
49+
self.annualInsightsTotalWordsCount = annualInsightsTotalWordsCount
50+
self.annualInsightsAverageWordsCount = annualInsightsAverageWordsCount
51+
52+
self.annualInsightsTotalLikesCount = annualInsightsTotalLikesCount
53+
self.annualInsightsAverageLikesCount = annualInsightsAverageLikesCount
54+
55+
self.annualInsightsTotalCommentsCount = annualInsightsTotalCommentsCount
56+
self.annualInsightsAverageCommentsCount = annualInsightsAverageCommentsCount
57+
58+
self.annualInsightsTotalImagesCount = annualInsightsTotalImagesCount
59+
self.annualInsightsAverageImagesCount = annualInsightsAverageImagesCount
60+
}
2561
}
2662

2763
extension StatsAnnualAndMostPopularTimeInsight: StatsInsightData {

WordPressKit/Insights/StatsCommentsInsight.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
public struct StatsCommentsInsight {
22
public let topPosts: [StatsTopCommentsPost]
33
public let topAuthors: [StatsTopCommentsAuthor]
4+
5+
public init(topPosts: [StatsTopCommentsPost],
6+
topAuthors: [StatsTopCommentsAuthor]) {
7+
self.topPosts = topPosts
8+
self.topAuthors = topAuthors
9+
}
410
}
511

612
extension StatsCommentsInsight: StatsInsightData {
@@ -31,13 +37,31 @@ public struct StatsTopCommentsAuthor {
3137
public let name: String
3238
public let commentCount: Int
3339
public let iconURL: URL?
40+
41+
public init(name: String,
42+
commentCount: Int,
43+
iconURL: URL?) {
44+
self.name = name
45+
self.commentCount = commentCount
46+
self.iconURL = iconURL
47+
}
3448
}
3549

3650
public struct StatsTopCommentsPost {
3751
public let name: String
3852
public let postID: String
3953
public let commentCount: Int
4054
public let postURL: URL?
55+
56+
public init(name: String,
57+
postID: String,
58+
commentCount: Int,
59+
postURL: URL?) {
60+
self.name = name
61+
self.postID = postID
62+
self.commentCount = commentCount
63+
self.postURL = postURL
64+
}
4165
}
4266

4367
private extension StatsTopCommentsAuthor {

WordPressKit/Insights/StatsDotComFollowersInsight.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
public struct StatsDotComFollowersInsight {
22
public let dotComFollowersCount: Int
33
public let topDotComFollowers: [StatsFollower]
4+
5+
public init (dotComFollowersCount: Int,
6+
topDotComFollowers: [StatsFollower]) {
7+
self.dotComFollowersCount = dotComFollowersCount
8+
self.topDotComFollowers = topDotComFollowers
9+
}
410
}
511

612
extension StatsDotComFollowersInsight: StatsInsightData {
@@ -37,6 +43,14 @@ public struct StatsFollower {
3743
public let name: String
3844
public let subscribedDate: Date
3945
public let avatarURL: URL?
46+
47+
public init(name: String,
48+
subscribedDate: Date,
49+
avatarURL: URL?) {
50+
self.name = name
51+
self.subscribedDate = subscribedDate
52+
self.avatarURL = avatarURL
53+
}
4054
}
4155

4256
extension StatsFollower {

WordPressKit/Insights/StatsEmailFollowersInsight.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
public struct StatsEmailFollowersInsight {
22
public let emailFollowersCount: Int
33
public let topEmailFollowers: [StatsFollower]
4+
5+
public init(emailFollowersCount: Int,
6+
topEmailFollowers: [StatsFollower]) {
7+
self.emailFollowersCount = emailFollowersCount
8+
self.topEmailFollowers = topEmailFollowers
9+
}
410
}
511

612
extension StatsEmailFollowersInsight: StatsInsightData {

WordPressKit/Insights/StatsLastPostInsight.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ public struct StatsLastPostInsight {
66
public let commentsCount: Int
77
public let viewsCount: Int
88
public let postID: Int
9+
10+
public init(title: String,
11+
url: URL,
12+
publishedDate: Date,
13+
likesCount: Int,
14+
commentsCount: Int,
15+
viewsCount: Int,
16+
postID: Int) {
17+
self.title = title
18+
self.url = url
19+
self.publishedDate = publishedDate
20+
self.likesCount = likesCount
21+
self.commentsCount = commentsCount
22+
self.viewsCount = viewsCount
23+
self.postID = postID
24+
}
925
}
1026

1127
extension StatsLastPostInsight: StatsInsightData {

WordPressKit/Insights/StatsPostingStreakInsight.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ public struct StatsPostingStreakInsight {
77
public let longestStreakLength: Int
88

99
public let postingEvents: [PostingStreakEvent]
10+
11+
public init(currentStreakStart: Date,
12+
currentStreakEnd: Date,
13+
currentStreakLength: Int,
14+
longestStreakStart: Date,
15+
longestStreakEnd: Date,
16+
longestStreakLength: Int,
17+
postingEvents: [PostingStreakEvent]) {
18+
self.currentStreakStart = currentStreakStart
19+
self.currentStreakEnd = currentStreakEnd
20+
self.currentStreakLength = currentStreakLength
21+
22+
self.longestStreakStart = longestStreakStart
23+
self.longestStreakEnd = longestStreakEnd
24+
self.longestStreakLength = longestStreakLength
25+
26+
self.postingEvents = postingEvents
27+
}
1028
}
1129

1230
public struct PostingStreakEvent {

WordPressKit/Insights/StatsPublicizeInsight.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
public struct StatsPublicizeInsight {
22
public let publicizeServices: [StatsPublicizeService]
3+
4+
public init(publicizeServices: [StatsPublicizeService]) {
5+
self.publicizeServices = publicizeServices
6+
}
37
}
48

59
extension StatsPublicizeInsight: StatsInsightData {
@@ -27,6 +31,14 @@ public struct StatsPublicizeService {
2731
public let name: String
2832
public let followers: Int
2933
public let iconURL: URL?
34+
35+
public init(name: String,
36+
followers: Int,
37+
iconURL: URL?) {
38+
self.name = name
39+
self.followers = followers
40+
self.iconURL = iconURL
41+
}
3042
}
3143

3244
private extension StatsPublicizeService {

WordPressKit/Insights/StatsTagsAndCategoriesInsight.swift

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
public struct StatsTagsAndCategoriesInsight {
22
public let topTagsAndCategories: [StatsTagAndCategory]
3+
4+
public init(topTagsAndCategories: [StatsTagAndCategory]) {
5+
self.topTagsAndCategories = topTagsAndCategories
6+
}
37
}
48

59
extension StatsTagsAndCategoriesInsight: StatsInsightData {
@@ -34,6 +38,15 @@ public struct StatsTagAndCategory {
3438
public let url: URL?
3539
public let viewsCount: Int?
3640
public let children: [StatsTagAndCategory]
41+
42+
public init(name: String, kind: Kind, url: URL?, viewsCount: Int?, children: [StatsTagAndCategory]) {
43+
self.name = name
44+
self.kind = kind
45+
self.url = url
46+
self.viewsCount = viewsCount
47+
self.children = children
48+
}
49+
3750
}
3851

3952
extension StatsTagAndCategory {
@@ -61,7 +74,7 @@ extension StatsTagAndCategory {
6174
let mappedChildren = innerTags.compactMap { StatsTagAndCategory(singleTag: $0) }
6275
let label = mappedChildren.map { $0.name }.joined(separator: ", ")
6376

64-
self.init(name: label, kind: .folder, url: "", viewsCount: views, children: mappedChildren)
77+
self.init(name: label, kind: .folder, url: nil, viewsCount: views, children: mappedChildren)
6578
}
6679

6780
init?(singleTag tag: [String: AnyObject], viewsCount: Int? = 0) {
@@ -84,16 +97,6 @@ extension StatsTagAndCategory {
8497
kind = .category
8598
}
8699

87-
self.init(name: name, kind: kind, url: url, viewsCount: viewsCount, children: [])
100+
self.init(name: name, kind: kind, url: URL(string: url), viewsCount: viewsCount, children: [])
88101
}
89-
90-
91-
init(name: String, kind: Kind, url: String, viewsCount: Int?, children: [StatsTagAndCategory]) {
92-
self.name = name
93-
self.kind = kind
94-
self.url = URL(string: url)
95-
self.viewsCount = viewsCount
96-
self.children = children
97-
}
98-
99102
}

WordPressKit/Insights/StatsTodayInsight.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ public struct StatsTodayInsight {
33
public let visitorsCount: Int
44
public let likesCount: Int
55
public let commentsCount: Int
6+
7+
public init(viewsCount: Int,
8+
visitorsCount: Int,
9+
likesCount: Int,
10+
commentsCount: Int) {
11+
self.viewsCount = viewsCount
12+
self.visitorsCount = visitorsCount
13+
self.likesCount = likesCount
14+
self.commentsCount = commentsCount
15+
}
616
}
717

818
extension StatsTodayInsight: StatsInsightData {

0 commit comments

Comments
 (0)