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

Commit c31ddf1

Browse files
committed
Add all data to StatsPostDetails
1 parent 6588ca8 commit c31ddf1

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ let package = Package(
1111
targets: [
1212
.binaryTarget(
1313
name: "WordPressKit",
14-
url: "https://github.com/user-attachments/files/21373882/WordPressKit.zip",
15-
checksum: "57a23a1340f2a9d24f1848b337da89c3556f1440767d91cc2a5ee8a6fe16b79b"
14+
url: "https://github.com/user-attachments/files/21388771/WordPressKit.zip",
15+
checksum: "543f8dd4ee1bef8912c640aca0bfbb74db95e4577cc19fa82461edeeac45a02b"
1616
),
1717
]
1818
)

Sources/WordPressKit/Models/Stats/StatsPostDetails.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@ import Foundation
33
public struct StatsPostDetails: Equatable {
44
public let fetchedDate: Date
55
public let totalViewsCount: Int
6-
6+
77
public let recentWeeks: [StatsWeeklyBreakdown]
88
public let dailyAveragesPerMonth: [StatsPostViews]
99
public let monthlyBreakdown: [StatsPostViews]
1010
public let lastTwoWeeks: [StatsPostViews]
11-
11+
public let data: [StatsPostViews]
12+
1213
public let highestMonth: Int?
1314
public let highestDayAverage: Int?
1415
public let highestWeekAverage: Int?
15-
16+
1617
public let yearlyTotals: [Int: Int]
1718
public let overallAverages: [Int: Int]
18-
19+
1920
public let fields: [String]?
20-
21+
2122
public let post: Post?
22-
23+
2324
public struct Post: Equatable {
2425
public let postID: Int
2526
public let title: String
@@ -39,29 +40,29 @@ public struct StatsPostDetails: Equatable {
3940
public let mimeType: String?
4041
public let commentCount: String?
4142
public let permalink: String?
42-
43+
4344
init?(jsonDictionary: [String: AnyObject]) {
4445
guard
4546
let postID = jsonDictionary["ID"] as? Int,
4647
let title = jsonDictionary["post_title"] as? String
4748
else {
4849
return nil
4950
}
50-
51+
5152
let dateFormatter = DateFormatter()
5253
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
5354
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
54-
55+
5556
var dateGMT: Date?
5657
var modifiedGMT: Date?
57-
58+
5859
if let postDateGMTString = jsonDictionary["post_date_gmt"] as? String {
5960
dateGMT = dateFormatter.date(from: postDateGMTString)
6061
}
6162
if let postModifiedGMTString = jsonDictionary["post_modified_gmt"] as? String {
6263
modifiedGMT = dateFormatter.date(from: postModifiedGMTString)
6364
}
64-
65+
6566
self.postID = postID
6667
self.title = title
6768
self.authorID = jsonDictionary["post_author"] as? String
@@ -119,6 +120,8 @@ extension StatsPostDetails {
119120
self.fetchedDate = date
120121
self.totalViewsCount = totalViewsCount
121122

123+
self.data = StatsPostViews.mapDailyData(data: data)
124+
122125
// It's very hard to describe the format of this response. I tried to make the parsing
123126
// as nice and readable as possible, but in all honestly it's still pretty nasty.
124127
// If you want to see an example response to see how weird this response is, check out

0 commit comments

Comments
 (0)