Skip to content

Commit

Permalink
Fixed string case
Browse files Browse the repository at this point in the history
“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.
  • Loading branch information
sxg committed Oct 2, 2018
1 parent 3492bdc commit b00250b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Source/RequestMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Tests/RequestMetadataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b00250b

Please sign in to comment.