Skip to content

Commit 2edd109

Browse files
committed
Remade the initialization flow for the StudentVue class to be more concise
1 parent fdc4108 commit 2edd109

File tree

6 files changed

+36
-45
lines changed

6 files changed

+36
-45
lines changed

.swiftpm/xcode/xcuserdata/evankaneshige.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
<dict>
55
<key>SchemeUserState</key>
66
<dict>
7-
<key>SwiftVue.xcscheme_^#shared#^_</key>
7+
<key>SwiftVue-Package.xcscheme_^#shared#^_</key>
88
<dict>
99
<key>orderHint</key>
1010
<integer>0</integer>
1111
</dict>
12+
<key>SwiftVue.xcscheme_^#shared#^_</key>
13+
<dict>
14+
<key>orderHint</key>
15+
<integer>1</integer>
16+
</dict>
1217
</dict>
1318
<key>SuppressBuildableAutocreation</key>
1419
<dict>

Package.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ let package = Package(
66
name: "SwiftVue",
77
platforms: [
88
.macOS(.v12),
9-
.iOS(.v15)
9+
.iOS(.v15),
10+
.macCatalyst(.v15),
11+
.tvOS(.v15),
12+
.watchOS(.v8)
1013
],
1114
products: [
1215
.library(

Sources/SwiftVue/DataProvider/DataProvider.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ public protocol DataProvider {
2323
func getMailInboxCount() async throws -> String
2424
func verifyCredentials() async throws -> Bool
2525

26+
init(credentials: Credentials)
27+
2628
static func getDistrictList(zip: String) async throws -> [DistrictInfo]
2729
}

Sources/SwiftVue/DataProvider/PreviewDataProvider.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,10 @@ public class PreviewDataProvider: DataProvider {
1111
public static var delayNanoseconds = UInt64(2e9)
1212
private let validCredentials: Bool
1313

14-
public init(credentials: Credentials = Credentials.preview) {
14+
required public init(credentials: Credentials) {
1515
self.validCredentials = credentials == Credentials.preview
1616
}
1717

18-
public init(username: String, password: String, districtURL: String) {
19-
self.validCredentials = Credentials(username: username, password: password, districtURL: districtURL) == Credentials.preview
20-
}
21-
2218
public func getMessages() async throws -> String {
2319
guard validCredentials else { throw SwiftVueError.invalidCredentials }
2420
throw SwiftVueError.notImplemented("PreviewDataProvider.getMessages")

Sources/SwiftVue/DataProvider/RealDataProvider.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@ public class RealDataProvider: DataProvider {
1212

1313
static private let edupointCredentials: Credentials = Credentials(username: "EdupointDistrictInfo", password: "Edup01nt", districtURL: "https://support.edupoint.com")
1414

15-
public init(credentials: Credentials) {
15+
required public init(credentials: Credentials) {
1616
self.credentials = credentials
1717
}
1818

19-
public init(username: String, password: String, districtURL: String) {
20-
self.credentials = Credentials(username: username, password: password, districtURL: districtURL)
21-
}
22-
2319
private func processRequest(method: String, paramString: String) async throws -> String {
2420
let body: String =
2521
"""
Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,76 @@
11
import Foundation
22

3-
public class StudentVue {
4-
var dataProvider: DataProvider
3+
public class StudentVue<Provider: DataProvider> {
4+
var provider: Provider
55

6-
public init(provider: DataProvider) {
7-
self.dataProvider = provider
6+
public init(credentials: Credentials) {
7+
self.provider = Provider(credentials: credentials)
88
}
99

10-
public init(credentials: Credentials, isPreview: Bool) {
11-
if isPreview {
12-
self.dataProvider = PreviewDataProvider(credentials: credentials)
13-
} else {
14-
self.dataProvider = RealDataProvider(credentials: credentials)
15-
}
16-
}
17-
18-
public init(username: String, password: String, districtURL: String, isPreview: Bool) {
19-
if isPreview {
20-
self.dataProvider = PreviewDataProvider(username: username, password: password, districtURL: districtURL)
21-
} else {
22-
self.dataProvider = RealDataProvider(username: username, password: password, districtURL: districtURL)
23-
}
10+
public convenience init(username: String, password: String, districtURL: String) {
11+
let credentials = Credentials(username: username, password: password, districtURL: districtURL)
12+
self.init(credentials: credentials)
2413
}
2514
}
2615

2716
extension StudentVue {
2817
public func getMessages() async throws -> String {
29-
return try await dataProvider.getMessages()
18+
return try await provider.getMessages()
3019
}
3120

3221
public func getCalendar() async throws -> String {
33-
return try await dataProvider.getCalendar()
22+
return try await provider.getCalendar()
3423
}
3524

3625
public func getAttendance() async throws -> Attendance {
37-
return try await dataProvider.getAttendance()
26+
return try await provider.getAttendance()
3827
}
3928

4029
public func getGradebook(reportPeriod: Int? = nil) async throws -> Gradebook {
41-
return try await dataProvider.getGradebook(reportPeriod: reportPeriod)
30+
return try await provider.getGradebook(reportPeriod: reportPeriod)
4231
}
4332

4433
public func getClassNotes() async throws -> String {
45-
return try await dataProvider.getClassNotes()
34+
return try await provider.getClassNotes()
4635
}
4736

4837
public func getStudentInfo() async throws -> StudentInfo {
49-
return try await dataProvider.getStudentInfo()
38+
return try await provider.getStudentInfo()
5039
}
5140

5241
public func getSchedule(termIndex: Int? = nil) async throws -> Schedule {
53-
return try await dataProvider.getSchedule(termIndex: termIndex)
42+
return try await provider.getSchedule(termIndex: termIndex)
5443
}
5544

5645
public func getSchoolInfo() async throws -> String {
57-
return try await dataProvider.getSchoolInfo()
46+
return try await provider.getSchoolInfo()
5847
}
5948

6049
public func listReportCards() async throws -> String {
61-
return try await dataProvider.listReportCards()
50+
return try await provider.listReportCards()
6251
}
6352

6453
public func getReportCard(documentGUID: String) async throws -> String {
65-
return try await dataProvider.getReportCard(documentGUID: documentGUID)
54+
return try await provider.getReportCard(documentGUID: documentGUID)
6655
}
6756

6857
public func listDocuments() async throws -> String {
69-
return try await dataProvider.listDocuments()
58+
return try await provider.listDocuments()
7059
}
7160

7261
public func getDocument(documentGUID: String) async throws -> String {
73-
return try await dataProvider.getDocument(documentGUID: documentGUID)
62+
return try await provider.getDocument(documentGUID: documentGUID)
7463
}
7564

7665
public static func getDistrictList(zip: String) async throws -> [DistrictInfo] {
77-
return try await RealDataProvider.getDistrictList(zip: zip)
66+
return try await Provider.getDistrictList(zip: zip)
7867
}
7968

8069
public func getMailInboxCount() async throws -> String {
81-
return try await dataProvider.getMailInboxCount()
70+
return try await provider.getMailInboxCount()
8271
}
8372

8473
public func verifyCredentials() async throws -> Bool {
85-
return try await dataProvider.verifyCredentials()
74+
return try await provider.verifyCredentials()
8675
}
8776
}

0 commit comments

Comments
 (0)