From 6d92430a203139cadb3c0e41159dc3fc3c0ca80b Mon Sep 17 00:00:00 2001 From: Lou Zell Date: Fri, 2 Aug 2024 08:38:47 -0700 Subject: [PATCH] feat: Open public method for passing in URLRequest (#120) --- swift/Sources/OpenMeteoSdk/OpenMeteoSdk.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/swift/Sources/OpenMeteoSdk/OpenMeteoSdk.swift b/swift/Sources/OpenMeteoSdk/OpenMeteoSdk.swift index cd347cf..cff4e95 100644 --- a/swift/Sources/OpenMeteoSdk/OpenMeteoSdk.swift +++ b/swift/Sources/OpenMeteoSdk/OpenMeteoSdk.swift @@ -14,7 +14,15 @@ extension WeatherApiResponse { @available(iOS 13.0.0, *) @available(macOS 12.0, *) public static func fetch(url: URL, session: URLSession = URLSession.shared) async throws -> [WeatherApiResponse] { - let (data, response) = try await session.data(from: url) + var request = URLRequest(url: url) + return try await fetch(request: request, session: session) + } + + @available(iOS 13.0.0, *) + @available(macOS 12.0, *) + /// Fetch data using a given URLRequest and decode the Open-Meteo Weather API Flatbuffers structure + public static func fetch(request: URLRequest, session: URLSession = URLSession.shared) async throws -> [WeatherApiResponse] { + let (data, response) = try await session.data(for: request) guard let res = (response as? HTTPURLResponse) else { throw OpenMeteoSdkError.error(message: "response is not type HTTPURLResponse") }