-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved error handling + calendar, staff info, report card list, doc…
…ument list, mail inbox count
- Loading branch information
1 parent
2edd109
commit f833a5d
Showing
21 changed files
with
830 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// EventInfo.swift | ||
// | ||
// | ||
// Created by Evan Kaneshige on 12/14/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct EventInfo: Hashable, Codable, Identifiable { | ||
public var id: UUID | ||
public var date: Date | ||
public var title: String | ||
public var dayType: String | ||
|
||
public init(id: UUID = UUID(), date: Date, title: String, dayType: String) { | ||
self.id = id | ||
self.date = date | ||
self.title = title | ||
self.dayType = dayType | ||
} | ||
|
||
internal init?(attributes: [String: String]) { | ||
guard let dateAttribute = attributes["Date"], | ||
let titleAttribute = attributes["Title"], | ||
let dayTypeAttribute = attributes["DayType"] else { | ||
return nil | ||
} | ||
|
||
let dateFormatter = DateFormatter() | ||
dateFormatter.locale = Locale(identifier: "en_US_POSIX") | ||
dateFormatter.dateFormat = "MM/dd/y" | ||
|
||
guard let date = dateFormatter.date(from: dateAttribute) else { | ||
return nil | ||
} | ||
|
||
self.init(date: date, title: titleAttribute, dayType: dayTypeAttribute) | ||
} | ||
} |
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,48 @@ | ||
// | ||
// StudentCalendar.swift | ||
// | ||
// | ||
// Created by Evan Kaneshige on 12/14/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct StudentCalendar: Hashable, Codable, Identifiable { | ||
public var id: UUID | ||
public var schoolBeginDate: Date | ||
public var schoolEndDate: Date | ||
public var monthBeginDate: Date | ||
public var monthEndDate: Date | ||
public var events: [EventInfo] | ||
|
||
public init(id: UUID = UUID(), schoolBeginDate: Date, schoolEndDate: Date, monthBeginDate: Date, monthEndDate: Date, events: [EventInfo]) { | ||
self.id = id | ||
self.schoolBeginDate = schoolBeginDate | ||
self.schoolEndDate = schoolEndDate | ||
self.monthBeginDate = monthBeginDate | ||
self.monthEndDate = monthEndDate | ||
self.events = events | ||
} | ||
|
||
internal init?(attributes: [String: String]) { | ||
guard let schoolBeginDateAttribute = attributes["SchoolBegDate"], | ||
let schoolEndDateAttribute = attributes["SchoolEndDate"], | ||
let monthBeginDateAttribute = attributes["MonthBegDate"], | ||
let monthEndDateAttribute = attributes["MonthEndDate"] else { | ||
return nil | ||
} | ||
|
||
let dateFormatter = DateFormatter() | ||
dateFormatter.locale = Locale(identifier: "en_US_POSIX") | ||
dateFormatter.dateFormat = "MM/dd/y" | ||
|
||
guard let schoolBeginDate = dateFormatter.date(from: schoolBeginDateAttribute), | ||
let schoolEndDate = dateFormatter.date(from: schoolEndDateAttribute), | ||
let monthBeginDate = dateFormatter.date(from: monthBeginDateAttribute), | ||
let monthEndDate = dateFormatter.date(from: monthEndDateAttribute) else { | ||
return nil | ||
} | ||
|
||
self.init(schoolBeginDate: schoolBeginDate, schoolEndDate: schoolEndDate, monthBeginDate: monthBeginDate, monthEndDate: monthEndDate, events: []) | ||
} | ||
} |
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,75 @@ | ||
// | ||
// StudentCalendarParser.swift | ||
// | ||
// | ||
// Created by Evan Kaneshige on 12/14/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public class StudentCalendarParser: NSObject, XMLParserDelegate { | ||
private var studentCalendar: StudentCalendar? | ||
private var eventInfos: [EventInfo] = [] | ||
|
||
private var parser: XMLParser | ||
private var error: Error? | ||
|
||
public init(string: String) { | ||
self.parser = XMLParser(data: Data(string.utf8)) | ||
super.init() | ||
self.parser.delegate = self | ||
self.parser.shouldProcessNamespaces = false | ||
self.parser.shouldReportNamespacePrefixes = false | ||
self.parser.shouldResolveExternalEntities = false | ||
} | ||
|
||
public func parser(_ parser: XMLParser, parseErrorOccurred parseError: Error) { | ||
self.parser.abortParsing() | ||
if self.error == nil { | ||
self.error = parseError | ||
} | ||
} | ||
|
||
public func parser(_ parser: XMLParser, validationErrorOccurred validationError: Error) { | ||
self.parser.abortParsing() | ||
self.error = validationError | ||
} | ||
|
||
public func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:]) { | ||
switch elementName { | ||
case "CalendarListing": | ||
guard let studentCalendar = StudentCalendar(attributes: attributeDict) else { | ||
self.parser.abortParsing() | ||
return | ||
} | ||
|
||
self.studentCalendar = studentCalendar | ||
case "EventList": | ||
guard let eventInfo = EventInfo(attributes: attributeDict) else { | ||
self.parser.abortParsing() | ||
return | ||
} | ||
|
||
self.studentCalendar?.events.append(eventInfo) | ||
case "RT_ERROR": | ||
self.parser.abortParsing() | ||
self.error = SwiftVueError.error(from: attributeDict["ERROR_MESSAGE"]) | ||
default: | ||
return | ||
} | ||
} | ||
|
||
public func parse() throws -> StudentCalendar { | ||
self.parser.parse() | ||
|
||
if let error { | ||
throw error | ||
} | ||
|
||
if let studentCalendar { | ||
return studentCalendar | ||
} else { | ||
throw SwiftVueError.couldNotParseXML | ||
} | ||
} | ||
} |
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
Oops, something went wrong.