|
1 | 1 | import Foundation |
2 | 2 |
|
3 | | -public class StudentVue { |
4 | | - var dataProvider: DataProvider |
| 3 | +public class StudentVue<Provider: DataProvider> { |
| 4 | + var provider: Provider |
5 | 5 |
|
6 | | - public init(provider: DataProvider) { |
7 | | - self.dataProvider = provider |
| 6 | + public init(credentials: Credentials) { |
| 7 | + self.provider = Provider(credentials: credentials) |
8 | 8 | } |
9 | 9 |
|
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) |
24 | 13 | } |
25 | 14 | } |
26 | 15 |
|
27 | 16 | extension StudentVue { |
28 | 17 | public func getMessages() async throws -> String { |
29 | | - return try await dataProvider.getMessages() |
| 18 | + return try await provider.getMessages() |
30 | 19 | } |
31 | 20 |
|
32 | 21 | public func getCalendar() async throws -> String { |
33 | | - return try await dataProvider.getCalendar() |
| 22 | + return try await provider.getCalendar() |
34 | 23 | } |
35 | 24 |
|
36 | 25 | public func getAttendance() async throws -> Attendance { |
37 | | - return try await dataProvider.getAttendance() |
| 26 | + return try await provider.getAttendance() |
38 | 27 | } |
39 | 28 |
|
40 | 29 | 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) |
42 | 31 | } |
43 | 32 |
|
44 | 33 | public func getClassNotes() async throws -> String { |
45 | | - return try await dataProvider.getClassNotes() |
| 34 | + return try await provider.getClassNotes() |
46 | 35 | } |
47 | 36 |
|
48 | 37 | public func getStudentInfo() async throws -> StudentInfo { |
49 | | - return try await dataProvider.getStudentInfo() |
| 38 | + return try await provider.getStudentInfo() |
50 | 39 | } |
51 | 40 |
|
52 | 41 | 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) |
54 | 43 | } |
55 | 44 |
|
56 | 45 | public func getSchoolInfo() async throws -> String { |
57 | | - return try await dataProvider.getSchoolInfo() |
| 46 | + return try await provider.getSchoolInfo() |
58 | 47 | } |
59 | 48 |
|
60 | 49 | public func listReportCards() async throws -> String { |
61 | | - return try await dataProvider.listReportCards() |
| 50 | + return try await provider.listReportCards() |
62 | 51 | } |
63 | 52 |
|
64 | 53 | public func getReportCard(documentGUID: String) async throws -> String { |
65 | | - return try await dataProvider.getReportCard(documentGUID: documentGUID) |
| 54 | + return try await provider.getReportCard(documentGUID: documentGUID) |
66 | 55 | } |
67 | 56 |
|
68 | 57 | public func listDocuments() async throws -> String { |
69 | | - return try await dataProvider.listDocuments() |
| 58 | + return try await provider.listDocuments() |
70 | 59 | } |
71 | 60 |
|
72 | 61 | public func getDocument(documentGUID: String) async throws -> String { |
73 | | - return try await dataProvider.getDocument(documentGUID: documentGUID) |
| 62 | + return try await provider.getDocument(documentGUID: documentGUID) |
74 | 63 | } |
75 | 64 |
|
76 | 65 | 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) |
78 | 67 | } |
79 | 68 |
|
80 | 69 | public func getMailInboxCount() async throws -> String { |
81 | | - return try await dataProvider.getMailInboxCount() |
| 70 | + return try await provider.getMailInboxCount() |
82 | 71 | } |
83 | 72 |
|
84 | 73 | public func verifyCredentials() async throws -> Bool { |
85 | | - return try await dataProvider.verifyCredentials() |
| 74 | + return try await provider.verifyCredentials() |
86 | 75 | } |
87 | 76 | } |
0 commit comments