@@ -3,23 +3,24 @@ import Foundation
33public 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