From 21cda13ed611c4723ae975cc8a6fcc3f0c0ae1e2 Mon Sep 17 00:00:00 2001 From: TheMoonThatRises <58153205+TheMoonThatRises@users.noreply.github.com> Date: Mon, 19 Aug 2024 14:01:02 -0600 Subject: [PATCH] add xml service request --- .../StudentVue/SOAPApi/StudentVueApi.swift | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Sources/StudentVue/SOAPApi/StudentVueApi.swift b/Sources/StudentVue/SOAPApi/StudentVueApi.swift index 5f1d7bf..36c529a 100644 --- a/Sources/StudentVue/SOAPApi/StudentVueApi.swift +++ b/Sources/StudentVue/SOAPApi/StudentVueApi.swift @@ -154,6 +154,29 @@ public class StudentVueApi { } } + /// Higher level function to access StudentVue's API. Automatically throws custom errors + /// + /// - Parameters: + /// - endpoint: The endpoint to access + /// - methodName: The method to use, determing what data is being requested or sent + /// - serviceHandle: The service handle to use + /// - params: Parameters to be sent. Uses a nested dictionary where the outer key is the tag name. The inner dictionary are the attributes, where the key "Value" is the tag content + /// + /// - Throws: `Error` or `StudentVueErrors`. An error thrown by URLSession or no response returned + /// + /// - Returns: The XMLIndexer parsed from the response from the StudentVue API + public func xmlServiceRequest(endpoint: Endpoints = .pxpCommunication, + methodName: Methods, + serviceHandle: WebServices = .pxpWebServices, + params: [String: [String: String]] = [:]) async throws -> XMLIndexer { + let result = try await makeServiceRequest(endpoint: endpoint, + methodName: methodName, + serviceHandle: serviceHandle, + params: params) + + return try XMLHash.parse(soapString: result) + } + /// Gets districts near the given zip code /// /// - Parameter zip: The zip code to search for near-by districts that use StudentVue