From b00250b6ed096072717aaf5878bc7b603c00c454 Mon Sep 17 00:00:00 2001 From: Satyam Ghodasara Date: Tue, 2 Oct 2018 15:00:46 -0400 Subject: [PATCH] Fixed string case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit “X-Forecast-API-Calls” and “X-Response-Time” are now lowercase from DarkSky.net. Updated source and unit tests for this interface change. GitHub Issue #54. --- Source/RequestMetadata.swift | 4 ++-- Tests/RequestMetadataTests.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/RequestMetadata.swift b/Source/RequestMetadata.swift index b432599..e6929a3 100644 --- a/Source/RequestMetadata.swift +++ b/Source/RequestMetadata.swift @@ -27,12 +27,12 @@ public struct RequestMetadata { /// - returns: A new `RequestMetadata` filled with data from the given Dark Sky API response header fields `Dictionary`. public init(fromHTTPHeaderFields headerFields: [AnyHashable: Any]) { cacheControl = headerFields["Cache-Control"] as? String - if let forecastAPICallsHeader = headerFields["X-Forecast-API-Calls"] as? String { + if let forecastAPICallsHeader = headerFields["x-forecast-api-calls"] as? String { apiRequestsCount = Int(forecastAPICallsHeader) } else { apiRequestsCount = nil } - if var responseTimeHeader = headerFields["X-Response-Time"] as? String { + if var responseTimeHeader = headerFields["x-response-time"] as? String { // Remove "ms" units from the string responseTimeHeader = responseTimeHeader.trimmingCharacters(in: CharacterSet.letters) responseTime = Float(responseTimeHeader) diff --git a/Tests/RequestMetadataTests.swift b/Tests/RequestMetadataTests.swift index 4d02092..e46e987 100644 --- a/Tests/RequestMetadataTests.swift +++ b/Tests/RequestMetadataTests.swift @@ -13,7 +13,7 @@ class RequestMetadataTests: XCTestCase { func testInitFromHTTPHeaderFields() { // Given - let httpHeaderFields = ["Cache-Control": "max-age=60", "X-Forecast-API-Calls": "12", "X-Response-Time": "123.45ms"] + let httpHeaderFields = ["Cache-Control": "max-age=60", "x-forecast-api-calls": "12", "x-response-time": "123.45ms"] // When let requestMetadata = RequestMetadata(fromHTTPHeaderFields: httpHeaderFields)