This repository was archived by the owner on Sep 15, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +12
-12
lines changed
Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Original file line number Diff line number Diff line change 1- public struct StatsEmailFollowersInsight {
1+ public struct StatsEmailFollowersInsight : Codable {
22 public let emailFollowersCount : Int
33 public let topEmailFollowers : [ StatsFollower ]
44
@@ -7,6 +7,11 @@ public struct StatsEmailFollowersInsight {
77 self . emailFollowersCount = emailFollowersCount
88 self . topEmailFollowers = topEmailFollowers
99 }
10+
11+ private enum CodingKeys : String , CodingKey {
12+ case emailFollowersCount = " total_email "
13+ case topEmailFollowers = " subscribers "
14+ }
1015}
1116
1217extension StatsEmailFollowersInsight : StatsInsightData {
@@ -22,17 +27,12 @@ extension StatsEmailFollowersInsight: StatsInsightData {
2227 }
2328
2429 public init ? ( jsonDictionary: [ String : AnyObject ] ) {
25- guard
26- let subscribersCount = jsonDictionary [ " total_email " ] as? Int ,
27- let subscribers = jsonDictionary [ " subscribers " ] as? [ [ String : AnyObject ] ]
28- else {
29- return nil
30+ do {
31+ let jsonData = try JSONSerialization . data ( withJSONObject: jsonDictionary, options: [ ] )
32+ let decoder = JSONDecoder ( )
33+ self = try decoder. decode ( StatsEmailFollowersInsight . self, from: jsonData)
34+ } catch {
35+ return nil
3036 }
31-
32- let followers = subscribers. compactMap { StatsFollower ( jsonDictionary: $0) }
33-
34- self . emailFollowersCount = subscribersCount
35- self . topEmailFollowers = followers
3637 }
37-
3838}
You can’t perform that action at this time.
0 commit comments