Skip to content

Commit

Permalink
feat: Open public method for passing in URLRequest (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzell authored Aug 2, 2024
1 parent a06b92e commit 6d92430
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion swift/Sources/OpenMeteoSdk/OpenMeteoSdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 6d92430

Please sign in to comment.