@@ -20,28 +20,77 @@ public class RealDataProvider: DataProvider {
2020 self . credentials = Credentials ( username: username, password: password, districtURL: districtURL)
2121 }
2222
23- private func processRequest( method: String , paramString: String , handle: String , user: Bool ) async throws -> String {
24- let username : String = if user { credentials. username } else { Self . edupointCredentials. username }
25- let password : String = if user { credentials. password } else { Self . edupointCredentials. password }
23+ private func processRequest( method: String , paramString: String ) async throws -> String {
24+ let body : String =
25+ """
26+ <soap:Envelope xmlns:xsi= " http://www.w3.org/2001/XMLSchema-instance " xmlns:xsd= " http://www.w3.org/2001/XMLSchema " xmlns:soap= " http://schemas.xmlsoap.org/soap/envelope/ " >
27+ <soap:Body>
28+ <ProcessWebServiceRequest xmlns= " http://edupoint.com/webservices/ " >
29+ <userID> \( credentials. username) </userID>
30+ <password> \( credentials. password) </password>
31+ <skipLoginLog>1</skipLoginLog>
32+ <parent>0</parent>
33+ <webServiceHandleName>PXPWebServices</webServiceHandleName>
34+ <methodName> \( method) </methodName>
35+ <paramStr> \( paramString) </paramStr>
36+ </ProcessWebServiceRequest>
37+ </soap:Body>
38+ </soap:Envelope>
39+ """
40+
41+ guard let url = URL ( string: credentials. districtURL + " /Service/PXPCommunication.asmx " ) else {
42+ throw SwiftVueError . invalidURL
43+ }
44+
45+ var request : URLRequest = URLRequest ( url: url, cachePolicy: . reloadIgnoringLocalAndRemoteCacheData)
46+ request. addValue ( " text/xml " , forHTTPHeaderField: " Content-Type " )
47+ request. addValue ( " http://edupoint.com/webservices/ProcessWebServiceRequest " , forHTTPHeaderField: " SOAPAction " )
48+ request. httpMethod = " POST "
49+ request. httpBody = body. data ( using: . utf8)
50+
51+ let session = URLSession ( configuration: URLSessionConfiguration . ephemeral)
52+ session. configuration. requestCachePolicy = . reloadIgnoringLocalAndRemoteCacheData
53+
54+ let ( data, response) = try await session. data ( for: request)
55+
56+ guard let httpResponse = response as? HTTPURLResponse , httpResponse. statusCode == 200 else {
57+ throw SwiftVueError . invalidResponse
58+ }
59+
60+ guard let result = String ( data: data, encoding: . utf8) else {
61+ throw SwiftVueError . couldNotDecodeResponse
62+ }
2663
64+ return result
65+ }
66+
67+ public func makeRequest( method: String , params: [ String : String ] = [ : ] ) async throws -> String {
68+ let paramStr = " <Parms> " + params. reduce ( " " ) { accumulation, pair in
69+ accumulation + " < \( pair. key) > \( pair. value) </ \( pair. key) > "
70+ } + " </Parms> "
71+ let processedRequest = try await processRequest ( method: method, paramString: paramStr)
72+ return processedRequest. replacingEscapements ( )
73+ }
74+
75+ private static func processRequest( method: String , paramString: String ) async throws -> String {
2776 let body : String =
2877 """
2978 <soap:Envelope xmlns:xsi= " http://www.w3.org/2001/XMLSchema-instance " xmlns:xsd= " http://www.w3.org/2001/XMLSchema " xmlns:soap= " http://schemas.xmlsoap.org/soap/envelope/ " >
3079 <soap:Body>
3180 <ProcessWebServiceRequest xmlns= " http://edupoint.com/webservices/ " >
32- <userID> \( username) </userID>
33- <password> \( password) </password>
81+ <userID> \( edupointCredentials . username) </userID>
82+ <password> \( edupointCredentials . password) </password>
3483 <skipLoginLog>1</skipLoginLog>
3584 <parent>0</parent>
36- <webServiceHandleName> \( handle ) </webServiceHandleName>
85+ <webServiceHandleName>HDInfoServices </webServiceHandleName>
3786 <methodName> \( method) </methodName>
3887 <paramStr> \( paramString) </paramStr>
3988 </ProcessWebServiceRequest>
4089 </soap:Body>
4190 </soap:Envelope>
4291 """
4392
44- guard let url = URL ( string: ( user ? credentials . districtURL : Self . edupointCredentials. districtURL) + ( user ? " /Service/PXPCommunication.asmx " : " /Service/ HDInfoCommunication.asmx" ) ) else {
93+ guard let url = URL ( string: edupointCredentials. districtURL + " /Service/HDInfoCommunication.asmx " ) else {
4594 throw SwiftVueError . invalidURL
4695 }
4796
@@ -67,24 +116,24 @@ public class RealDataProvider: DataProvider {
67116 return result
68117 }
69118
70- public func makeRequest( method: String , params: [ String : String ] = [ : ] , handle : String , user : Bool = true ) async throws -> String {
119+ public static func makeRequest( method: String , params: [ String : String ] = [ : ] ) async throws -> String {
71120 let paramStr = " <Parms> " + params. reduce ( " " ) { accumulation, pair in
72121 accumulation + " < \( pair. key) > \( pair. value) </ \( pair. key) > "
73122 } + " </Parms> "
74- let processedRequest = try await processRequest ( method: method, paramString: paramStr, handle : handle , user : user )
123+ let processedRequest = try await processRequest ( method: method, paramString: paramStr)
75124 return processedRequest. replacingEscapements ( )
76125 }
77126
78127 public func getMessages( ) async throws -> String {
79- return try await makeRequest ( method: " GetPXPMessages " , handle : " PXPWebServices " )
128+ return try await makeRequest ( method: " GetPXPMessages " )
80129 }
81130
82131 public func getCalendar( ) async throws -> String {
83- return try await makeRequest ( method: " StudentCalendar " , handle : " PXPWebServices " )
132+ return try await makeRequest ( method: " StudentCalendar " )
84133 }
85134
86135 public func getAttendance( ) async throws -> Attendance {
87- let result = try await makeRequest ( method: " Attendance " , handle : " PXPWebServices " )
136+ let result = try await makeRequest ( method: " Attendance " )
88137
89138 if !result. contains ( " Attendance " ) {
90139 throw SwiftVueError . invalidCredentials
@@ -98,7 +147,7 @@ public class RealDataProvider: DataProvider {
98147 if let period = reportPeriod {
99148 params = [ " ReportPeriod " : " \( period) " ]
100149 }
101- let result = try await makeRequest ( method: " Gradebook " , params: params, handle : " PXPWebServices " )
150+ let result = try await makeRequest ( method: " Gradebook " , params: params)
102151
103152 if !result. contains ( " Gradebook " ) {
104153 throw SwiftVueError . invalidCredentials
@@ -108,11 +157,11 @@ public class RealDataProvider: DataProvider {
108157 }
109158
110159 public func getClassNotes( ) async throws -> String {
111- return try await makeRequest ( method: " StudentHWNotes " , handle : " PXPWebServices " )
160+ return try await makeRequest ( method: " StudentHWNotes " )
112161 }
113162
114163 public func getStudentInfo( ) async throws -> StudentInfo {
115- let string = try await makeRequest ( method: " StudentInfo " , handle : " PXPWebServices " )
164+ let string = try await makeRequest ( method: " StudentInfo " )
116165 if !string. contains ( " StudentInfo " ) {
117166 throw SwiftVueError . invalidCredentials
118167 }
@@ -124,47 +173,47 @@ public class RealDataProvider: DataProvider {
124173 if let term = termIndex {
125174 params = [ " TermIndex " : " \( term) " ]
126175 }
127- let string = try await makeRequest ( method: " StudentClassList " , params: params, handle : " PXPWebServices " )
176+ let string = try await makeRequest ( method: " StudentClassList " , params: params)
128177 if !string. contains ( " StudentClassSchedule " ) {
129178 throw SwiftVueError . invalidCredentials
130179 }
131180 return try ScheduleParser ( string: string) . parse ( )
132181 }
133182
134183 public func getSchoolInfo( ) async throws -> String {
135- return try await makeRequest ( method: " StudentSchoolInfo " , handle : " PXPWebServices " )
184+ return try await makeRequest ( method: " StudentSchoolInfo " )
136185 }
137186
138187 public func listReportCards( ) async throws -> String {
139- return try await makeRequest ( method: " GetReportCardInitialData " , handle : " PXPWebServices " )
188+ return try await makeRequest ( method: " GetReportCardInitialData " )
140189 }
141190
142191 public func getReportCard( documentGUID: String ) async throws -> String {
143- return try await makeRequest ( method: " GetReportCardDocumentData " , params: [ " DocumentGU " : documentGUID] , handle : " PXPWebServices " )
192+ return try await makeRequest ( method: " GetReportCardDocumentData " , params: [ " DocumentGU " : documentGUID] )
144193 }
145194
146195 public func listDocuments( ) async throws -> String {
147- return try await makeRequest ( method: " GetStudentDocumentInitialData " , handle : " PXPWebServices " )
196+ return try await makeRequest ( method: " GetStudentDocumentInitialData " )
148197 }
149198
150199 public func getDocument( documentGUID: String ) async throws -> String {
151- return try await makeRequest ( method: " GetContentOfAttachedDoc " , params: [ " DocumentGU " : documentGUID] , handle: " PXPWebServices " )
152- }
153-
154- public func getDistrictList( zip: String ) async throws -> [ DistrictInfo ] {
155- let string = try await makeRequest ( method: " GetMatchingDistrictList " , params: [ " Key " : " 5E4B7859-B805-474B-A833-FDB15D205D40 " , " MatchToDistrictZipCode " : " \( zip) " ] , handle: " HDInfoServices " , user: false )
156- if !string. contains ( " DistrictList " ) {
157- throw SwiftVueError . invalidCredentials
158- }
159- return try DistrictInfoParser ( string: string) . parse ( )
200+ return try await makeRequest ( method: " GetContentOfAttachedDoc " , params: [ " DocumentGU " : documentGUID] )
160201 }
161202
162203 public func getMailInboxCount( ) async throws -> String {
163- return try await makeRequest ( method: " SynergyMailGetInboxCount " , handle : " PXPWebServices " )
204+ return try await makeRequest ( method: " SynergyMailGetInboxCount " )
164205 }
165206
166207 public func verifyCredentials( ) async throws -> Bool {
167208 let string = try await getMailInboxCount ( )
168209 return string. contains ( " SynergyMailInboxCountXML " )
169210 }
211+
212+ public static func getDistrictList( zip: String ) async throws -> [ DistrictInfo ] {
213+ let string = try await makeRequest ( method: " GetMatchingDistrictList " , params: [ " Key " : " 5E4B7859-B805-474B-A833-FDB15D205D40 " , " MatchToDistrictZipCode " : " \( zip) " ] )
214+ if !string. contains ( " DistrictList " ) {
215+ throw SwiftVueError . invalidCredentials
216+ }
217+ return try DistrictInfoParser ( string: string) . parse ( )
218+ }
170219}
0 commit comments