Skip to content

Commit d3ab18c

Browse files
committed
Use measurements
1 parent 8001029 commit d3ab18c

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

Sources/StormGlassKit/API/StormGlassKit+API.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@ import CoreLocation
1010
import Combine
1111

1212
public extension StormGlassKit {
13-
static func fetchWeather(coordinate: CLLocationCoordinate2D, parameters: Set<WeatherQueryParameter>,
13+
static func fetchWeather(coordinate: CLLocationCoordinate2D, measurements: Set<WeatherMeasurementName>,
1414
start: Date?, end: Date?, sources: Set<WeatherDataSource>?,
1515
session: URLSession = .shared) -> AnyPublisher<Weather, Error> {
16-
fetchWeather(coordinate: coordinate, parameters: parameters,
16+
fetchWeather(coordinate: coordinate, measurements: measurements,
1717
start: start, end: end, sources: sources,
1818
session: session, decoder: JSONDecoder())
1919
}
2020

21-
static func fetchWeather<Coder>(coordinate: CLLocationCoordinate2D, parameters: Set<WeatherQueryParameter>,
21+
static func fetchWeather<Coder>(coordinate: CLLocationCoordinate2D, measurements: Set<WeatherMeasurementName>,
2222
start: Date?, end: Date?, sources: Set<WeatherDataSource>?,
2323
session: URLSession = .shared, decoder: Coder) -> AnyPublisher<Weather, Error> where Coder: TopLevelDecoder, Coder.Input == Data {
2424
do {
25-
let request = try weatherURLRequest(coordinate: coordinate, parameters: parameters, start: start, end: end, sources: sources)
25+
let request = try weatherURLRequest(coordinate: coordinate, parameters: Set(measurements.map(\.queryParameter)),
26+
start: start, end: end, sources: sources)
2627
return session.dataTaskPublisher(for: request)
2728
.tryExtractData(decoder: decoder, request: request)
2829
.decode(type: Weather.self, decoder: decoder)
@@ -35,18 +36,19 @@ public extension StormGlassKit {
3536

3637
@available(iOS 15.0, *)
3738
public extension StormGlassKit {
38-
static func fetchWeather(coordinate: CLLocationCoordinate2D, parameters: Set<WeatherQueryParameter>,
39+
static func fetchWeather(coordinate: CLLocationCoordinate2D, measurements: Set<WeatherMeasurementName>,
3940
start: Date?, end: Date?, sources: Set<WeatherDataSource>?,
4041
session: URLSession = .shared) async throws -> Weather {
41-
try await fetchWeather(coordinate: coordinate, parameters: parameters,
42+
try await fetchWeather(coordinate: coordinate, measurements: measurements,
4243
start: start, end: end, sources: sources,
4344
session: session, decoder: JSONDecoder())
4445
}
4546

46-
static func fetchWeather<Coder>(coordinate: CLLocationCoordinate2D, parameters: Set<WeatherQueryParameter>,
47+
static func fetchWeather<Coder>(coordinate: CLLocationCoordinate2D, measurements: Set<WeatherMeasurementName>,
4748
start: Date?, end: Date?, sources: Set<WeatherDataSource>?,
4849
session: URLSession = .shared, decoder: Coder) async throws -> Weather where Coder: TopLevelDecoder, Coder.Input == Data {
49-
let request = try weatherURLRequest(coordinate: coordinate, parameters: parameters, start: start, end: end, sources: sources)
50+
let request = try weatherURLRequest(coordinate: coordinate, parameters: Set(measurements.map(\.queryParameter)),
51+
start: start, end: end, sources: sources)
5052
let dataResponse = try await session.data(for: request)
5153
let data = try handleDataResponse(decoder: decoder, data: dataResponse.0, response: dataResponse.1, request: request)
5254
return try decoder.decode(Weather.self, from: data)
@@ -108,7 +110,7 @@ internal extension StormGlassKit {
108110
}
109111

110112
static func weatherURLRequest(coordinate: CLLocationCoordinate2D, parameters: Set<WeatherQueryParameter>,
111-
start: Date?, end: Date?, sources: Set<WeatherDataSource>?) throws -> URLRequest {
113+
start: Date?, end: Date?, sources: Set<WeatherDataSource>?) throws -> URLRequest {
112114
assert(!parameters.isEmpty, "API expects at least one parameter")
113115
var queryItems: [URLQueryItem] = [
114116
URLQueryItem(name: "lat", value: coordinate.latitude),

0 commit comments

Comments
 (0)