From 5449a64ccc29f56618412d746f785a395d6d15a7 Mon Sep 17 00:00:00 2001 From: "RobLabs.com" Date: Mon, 11 Apr 2022 15:13:15 -0700 Subject: [PATCH 1/2] Allow API customers to set the UnitTemperature to get either US or SI (metric) results from the API --- .../services/calls/NWS+Forecast.swift | 8 +++- .../GetForecastIntegrationTests.swift | 38 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Sources/NationalWeatherService/services/calls/NWS+Forecast.swift b/Sources/NationalWeatherService/services/calls/NWS+Forecast.swift index 72a878b..bd517df 100644 --- a/Sources/NationalWeatherService/services/calls/NWS+Forecast.swift +++ b/Sources/NationalWeatherService/services/calls/NWS+Forecast.swift @@ -10,10 +10,16 @@ import Foundation extension NationalWeatherService { public typealias ForecastHandler = (Result) -> Void + /// Allow API customers to set the [UnitTemperature](https://developer.apple.com/documentation/foundation/unittemperature) + /// to get ["*US customary or SI (metric) units in textual output*"](https://www.weather.gov/documentation/services-web-api#/default/gridpoint_forecast) + public static var units: UnitTemperature = .celsius + fileprivate func loadForecast(at url: URL, then handler: @escaping ForecastHandler) { var components = URLComponents(url: url, resolvingAgainstBaseURL: false)! + + let units: String = NationalWeatherService.units == .celsius ? "si" : "us" components.queryItems = [ - URLQueryItem(name: "units", value: "si") + URLQueryItem(name: "units", value: units) ] self.load(at: components.url!, as: Forecast.self, then: handler) diff --git a/Tests/NationalWeatherServiceTests/integration/GetForecastIntegrationTests.swift b/Tests/NationalWeatherServiceTests/integration/GetForecastIntegrationTests.swift index b82cc6b..a85910d 100644 --- a/Tests/NationalWeatherServiceTests/integration/GetForecastIntegrationTests.swift +++ b/Tests/NationalWeatherServiceTests/integration/GetForecastIntegrationTests.swift @@ -2,6 +2,7 @@ import XCTest @testable import NationalWeatherService final class GetForecastIntegrationTests: XCTestCase { + /// Get forecast without setting `NationalWeatherService.units` func testGetForecastForLocation() throws { let forecastExpectation = self.expectation(description: "get forecast expectation") nws.forecast(latitude: 47.6174, longitude: -122.2017) { result in @@ -15,7 +16,44 @@ final class GetForecastIntegrationTests: XCTestCase { wait(for: [forecastExpectation], timeout: 5) } + + /// Get forecast by setting `NationalWeatherService.units` to `.fahrenheit` + func testGetForecastFahrenheit() throws { + let forecastExpectation = self.expectation(description: "get forecast expectation") + + NationalWeatherService.units = .fahrenheit + nws.forecast(latitude: 47.6174, longitude: -122.2017) { result in + XCTAssertSuccess(result) + + let forecast = try! result.get() + print(forecast) + XCTAssertFalse(forecast.periods.isEmpty) + forecastExpectation.fulfill() + } + + wait(for: [forecastExpectation], timeout: 5) + } + + /// Get forecast by setting `NationalWeatherService.units` to `.celsius` + func testGetForecastCelsius() throws { + let forecastExpectation = self.expectation(description: "get forecast expectation") + + NationalWeatherService.units = .celsius + nws.forecast(latitude: 47.6174, longitude: -122.2017) { result in + XCTAssertSuccess(result) + + let forecast = try! result.get() + + print(forecast) + XCTAssertFalse(forecast.periods.isEmpty) + + forecastExpectation.fulfill() + } + + wait(for: [forecastExpectation], timeout: 5) + } + func testGetHourlyForecast() throws { let hourlyForecastExpectation = self.expectation(description: "get hourly forecast expectation") nws.hourlyForecast(latitude: 47.6174, longitude: -122.2017) { result in From 683e15b7fe556f57711ae3efb2b68e497315c6bb Mon Sep 17 00:00:00 2001 From: "RobLabs.com" Date: Tue, 24 Jan 2023 16:26:25 -0800 Subject: [PATCH 2/2] Update GitHub Workflows to Xcode 14 --- .github/workflows/apple.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/apple.yml b/.github/workflows/apple.yml index 22b5018..fbc1029 100644 --- a/.github/workflows/apple.yml +++ b/.github/workflows/apple.yml @@ -13,7 +13,7 @@ jobs: steps: - uses: maxim-lobanov/setup-xcode@v1.1 with: - xcode-version: 12 + xcode-version: 14.2 - uses: actions/checkout@v2 - uses: actions/cache@v2 with: @@ -31,7 +31,7 @@ jobs: steps: - uses: maxim-lobanov/setup-xcode@v1.1 with: - xcode-version: 12 + xcode-version: 14.2 - uses: actions/checkout@v2 - uses: actions/cache@v2 with: @@ -42,10 +42,10 @@ jobs: - name: Build run: xcodebuild clean build-for-testing -scheme 'NationalWeatherService' - -destination 'name=iPhone 11 Pro' + -destination 'name=iPhone 14 Pro' -quiet - name: Unit Test run: xcodebuild test-without-building -scheme 'NationalWeatherService' - -destination 'name=iPhone 11 Pro' + -destination 'name=iPhone 14 Pro' -quiet