-
-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
380 additions
and
364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
WMFData/Sources/WMFData/Data Controllers/YearInReview/WMFYearInReviewDataController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Foundation | ||
|
||
final public class WMFYearInReviewDataController { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
WMFData/Sources/WMFData/Models/Developer Settings/WMFFeatureConfigResponse.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import Foundation | ||
|
||
public struct WMFFeatureConfigResponse: Codable { | ||
public struct FeatureConfigIOS: Codable { | ||
|
||
public struct YearInReview: Codable { | ||
|
||
public struct PersonalizedSlides: Codable { | ||
let readCount: SlideSettings | ||
let editCount: SlideSettings | ||
} | ||
|
||
public struct SlideSettings: Codable { | ||
public let isEnabled: Bool | ||
} | ||
|
||
public let isEnabled: Bool | ||
public let countryCodes: [String] | ||
public let primaryAppLanguageCodes: [String] | ||
public let dataPopulationStartDateString: String | ||
public let dataPopulationEndDateString: String | ||
public let personalizedSlides: PersonalizedSlides | ||
} | ||
|
||
let version: Int | ||
public let yir: YearInReview | ||
} | ||
|
||
public let ios: [FeatureConfigIOS] | ||
var cachedDate: Date? | ||
|
||
private let currentFeatureConfigVersion = 1 | ||
|
||
public init(from decoder: Decoder) throws { | ||
|
||
// Custom decoding to filter out invalid versions | ||
|
||
let overallContainer = try decoder.container(keyedBy: CodingKeys.self) | ||
|
||
var versionContainer = try overallContainer.nestedUnkeyedContainer(forKey: .ios) | ||
var iosContainer = try overallContainer.nestedUnkeyedContainer(forKey: .ios) | ||
|
||
var validConfigs: [FeatureConfigIOS] = [] | ||
while !versionContainer.isAtEnd { | ||
|
||
let wmfVersion: WMFConfigVersion | ||
let config: FeatureConfigIOS | ||
do { | ||
wmfVersion = try versionContainer.decode(WMFConfigVersion.self) | ||
} catch { | ||
// Skip | ||
_ = try? versionContainer.decode(WMFDiscardedElement.self) | ||
_ = try? iosContainer.decode(WMFDiscardedElement.self) | ||
continue | ||
} | ||
|
||
guard wmfVersion.version == currentFeatureConfigVersion else { | ||
// Skip | ||
_ = try? iosContainer.decode(WMFDiscardedElement.self) | ||
continue | ||
} | ||
|
||
do { | ||
config = try iosContainer.decode(FeatureConfigIOS.self) | ||
} catch { | ||
// Skip | ||
_ = try? iosContainer.decode(WMFDiscardedElement.self) | ||
continue | ||
} | ||
|
||
validConfigs.append(config) | ||
} | ||
|
||
self.ios = validConfigs | ||
self.cachedDate = try? overallContainer.decode(Date.self, forKey: .cachedDate) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
WMFData/Sources/WMFData/Models/Shared/WMFDiscardedElement.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
struct WMFDiscardedElement: Codable {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
WMFData/Sources/WMFDataMocks/Resources/feature-get-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"common": {}, | ||
"ios": [ | ||
{ | ||
"version": 1, | ||
"yir": { | ||
"isEnabled": true, | ||
"countryCodes": [ | ||
"FR", | ||
"IT" | ||
], | ||
"primaryAppLanguageCodes": [ | ||
"fr", | ||
"it" | ||
], | ||
"dataPopulationStartDateString": "2024-01-01T00:00:00Z", | ||
"dataPopulationEndDateString": "2024-11-01T00:00:00Z", | ||
"personalizedSlides": { | ||
"readCount": { | ||
"isEnabled": true | ||
}, | ||
"editCount": { | ||
"isEnabled": true | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"android": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.