Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit e4c05f7
Author: Satyam Ghodasara <[email protected]>
Date:   Fri Mar 15 10:07:09 2019 -0400

    Update version number to 6.0.0

commit 3f0aa80
Author: Satyam Ghodasara <[email protected]>
Date:   Fri Mar 15 10:02:00 2019 -0400

    Update CHANGELOG.md

commit 7aa156f
Author: Satyam Ghodasara <[email protected]>
Date:   Fri Mar 15 10:01:51 2019 -0400

    Update Swift version compatibility

commit f763e8d
Author: Satyam Ghodasara <[email protected]>
Date:   Thu Mar 14 22:25:59 2019 -0400

    Update unit tests for new properties

commit b98e323
Author: Satyam Ghodasara <[email protected]>
Date:   Thu Mar 14 22:22:50 2019 -0400

    Update all unit test JSON

commit 4fe3f5b
Author: Satyam Ghodasara <[email protected]>
Date:   Thu Mar 14 21:56:47 2019 -0400

    Update flag.json and Flag unit tests

commit 1616678
Author: Satyam Ghodasara <[email protected]>
Date:   Thu Mar 14 21:48:49 2019 -0400

    Update Flag properties

commit 45cd8cb
Author: Satyam Ghodasara <[email protected]>
Date:   Thu Mar 14 21:45:07 2019 -0400

    Add new properties to DataPoint

commit 31cd00f
Author: Satyam Ghodasara <[email protected]>
Date:   Fri Mar 15 09:44:56 2019 -0400

    Changed missingResponse error to missingHeaders

commit d6ecadd
Author: Satyam Ghodasara <[email protected]>
Date:   Thu Mar 14 22:36:28 2019 -0400

    Update documentation

commit 8a0f650
Author: Satyam Ghodasara <[email protected]>
Date:   Thu Mar 14 21:28:07 2019 -0400

    Fixed documentation spacing

commit 47b1297
Author: Satyam Ghodasara <[email protected]>
Date:   Thu Mar 14 21:20:58 2019 -0400

    Add trailing newline

commit 96eb5ff
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 22:51:48 2019 -0400

    Updated Results unit testing with new errors

commit aedd785
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 22:47:25 2019 -0400

    Update error handling

commit 53f0474
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 17:20:01 2019 -0400

    Make Forecast conform to Decodable

commit f90a74c
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 17:06:29 2019 -0400

    Make DataBlock conform to Decodable

commit 02958dd
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 17:06:10 2019 -0400

    Add dedicated JSON for DataBlock testing

commit 6b97eee
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 16:55:29 2019 -0400

    Remove unused code from DataPoint and unit tests

commit 33288c2
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 16:53:01 2019 -0400

    Make Datapoint conform to Decodable

commit 906e6c6
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 16:52:47 2019 -0400

    Add dedicated JSON for DataPoint testing

commit 81d0da0
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 16:46:52 2019 -0400

    Update unit test name

commit ed12834
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 16:40:20 2019 -0400

    Make supporting classes conform to Decodable

commit a180acc
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 16:38:08 2019 -0400

    Add more rigorous testing of Flag properties

commit 3b6ff9d
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 16:37:54 2019 -0400

    Add custom keys for Flag properties

commit 4bc1d40
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 16:19:57 2019 -0400

    Update unit tests for Decodable Flag

commit b03c87f
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 16:19:39 2019 -0400

    Make Flag conform to Decodable

commit e8737ac
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 16:19:15 2019 -0400

    Add dedicated JSON for flag testing

commit 944a032
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 16:18:47 2019 -0400

    Add explicit reference to decoder

commit 354fa09
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 16:10:25 2019 -0400

    Make Units conform to Decodable

commit f7e59c4
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 16:09:20 2019 -0400

    Make Alert conform to Decoable

commit b523c87
Author: Satyam Ghodasara <[email protected]>
Date:   Wed Mar 13 16:08:58 2019 -0400

    Added dedicated JSON for alerts testing

commit 69e190b
Author: Satyam Ghodasara <[email protected]>
Date:   Tue Oct 2 15:31:39 2018 -0400

    Updated Swift 4.2 badge in README.md

commit 13b81a6
Author: Satyam Ghodasara <[email protected]>
Date:   Tue Oct 2 15:27:59 2018 -0400

    Bumped version to 5.1.0

commit 38239ca
Author: Satyam Ghodasara <[email protected]>
Date:   Tue Oct 2 15:27:50 2018 -0400

    Updated CHANGELOG.md

commit 1147c12
Author: Satyam Ghodasara <[email protected]>
Date:   Tue Oct 2 15:22:30 2018 -0400

    Updated CocoaPod dependencies

commit 6b52efa
Author: Satyam Ghodasara <[email protected]>
Date:   Tue Oct 2 15:22:15 2018 -0400

    Fixed NSDictionary downcasting

commit 88b536f
Author: Satyam Ghodasara <[email protected]>
Date:   Tue Oct 2 15:14:29 2018 -0400

    Added more languages

    Hebrew and Latvian are now supported

commit b00250b
Author: Satyam Ghodasara <[email protected]>
Date:   Tue Oct 2 15:00:46 2018 -0400

    Fixed string case

    “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.

commit 3492bdc
Author: Satyam Ghodasara <[email protected]>
Date:   Sat Mar 31 19:33:25 2018 -0400

    Updated .travis.yml

commit 726ae60
Author: Satyam Ghodasara <[email protected]>
Date:   Sat Mar 31 19:23:44 2018 -0400

    Rebase

commit 77420c3
Author: Satyam Ghodasara <[email protected]>
Date:   Sat Mar 31 12:43:14 2018 -0400

    Removed reference to recovered Language.swift

commit 7d76b54
Author: Satyam Ghodasara <[email protected]>
Date:   Fri Mar 30 17:13:28 2018 -0400

    Updated project
  • Loading branch information
sxg committed Mar 15, 2019
1 parent ea4ee7f commit 919b3ea
Show file tree
Hide file tree
Showing 40 changed files with 2,762 additions and 3,781 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

ForecastIO adheres to [Semantic Versioning](http://semver.org/).

## 6.0.0

Release on March 15, 2019.

### Added
- Most structs now conform to `Decodable`
- `temperatureMax`, `temperatureMaxTime`, `temperatureMin`, `temperatureMinTime`, `apparentTemperatureMax`, `apparentTemperatureMaxTime`, `apparentTemperatureMin`, `apparentTemperatureMinTime`, `windGustTime` on `DataPoint`
- New errors to `ForecastIOError`: `.missingData`, `.missingHeaders`, and `.unexpectedError`
- `nearestStation` on `Flag`

### Updated
- Unit test example JSON data
- Unit tests to conform to new and removed properties and `Decodable`

### Removed
- Custom `init` methods on structs that now conform to `Decodable`
- `ForecastIOError.invalidJSON` error
- `darkSkyStations`, `dataPointStations`, `isdStations`, `lampStations`, `metarStations`, and `metnoLicense` from `Flag`

## 5.1.0

Release on October 2, 2018.
Expand Down
8 changes: 3 additions & 5 deletions Example/iOS Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
D4B85D7D1C53324600BD2FCD = {
CreatedOnToolsVersion = 7.2;
DevelopmentTeam = 76333YNXLE;
LastSwiftMigration = 0930;
LastSwiftMigration = "";
ProvisioningStyle = Automatic;
};
};
Expand Down Expand Up @@ -461,8 +461,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "io.Satyam.iOS-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -480,8 +479,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "io.Satyam.iOS-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
2 changes: 1 addition & 1 deletion ForecastIO.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Pod::Spec.new do |s|
s.name = "ForecastIO"
s.version = "5.1.0"
s.version = "6.0.0"
s.summary = "ForecastIO is a Swift library for interfacing with the Dark Sky forecast API."
s.homepage = "https://github.com/sxg/ForecastIO"
s.license = 'MIT'
Expand Down
46 changes: 40 additions & 6 deletions ForecastIO.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@
4A8B235C1D44807E00ACBAA8 /* forecast_bare.json in Resources */ = {isa = PBXBuildFile; fileRef = 4A14A6EE1CDAA80300D4C108 /* forecast_bare.json */; };
4A8B235D1D44807E00ACBAA8 /* forecast.json in Resources */ = {isa = PBXBuildFile; fileRef = D4D9F2B41C54061600A4A02F /* forecast.json */; };
4A8B235E1D44807E00ACBAA8 /* forecast_no_optionals.json in Resources */ = {isa = PBXBuildFile; fileRef = 4A3364661CD9712000775650 /* forecast_no_optionals.json */; };
4A92DEA422398FD300C12799 /* alerts.json in Resources */ = {isa = PBXBuildFile; fileRef = 4A92DEA322398FD300C12799 /* alerts.json */; };
4A92DEA5223991B000C12799 /* alerts.json in Resources */ = {isa = PBXBuildFile; fileRef = 4A92DEA322398FD300C12799 /* alerts.json */; };
4A92DEA7223997F900C12799 /* alerts_no_optionals.json in Resources */ = {isa = PBXBuildFile; fileRef = 4A92DEA6223997F900C12799 /* alerts_no_optionals.json */; };
4A92DEA82239997C00C12799 /* alerts_no_optionals.json in Resources */ = {isa = PBXBuildFile; fileRef = 4A92DEA6223997F900C12799 /* alerts_no_optionals.json */; };
4A92DEAA22399B9000C12799 /* flag.json in Resources */ = {isa = PBXBuildFile; fileRef = 4A92DEA922399B9000C12799 /* flag.json */; };
4A92DEAB22399CF100C12799 /* flag.json in Resources */ = {isa = PBXBuildFile; fileRef = 4A92DEA922399B9000C12799 /* flag.json */; };
4A92DEAD2239A31100C12799 /* datapoint.json in Resources */ = {isa = PBXBuildFile; fileRef = 4A92DEAC2239A31100C12799 /* datapoint.json */; };
4A92DEAE2239A32C00C12799 /* datapoint.json in Resources */ = {isa = PBXBuildFile; fileRef = 4A92DEAC2239A31100C12799 /* datapoint.json */; };
4A92DEB02239A62A00C12799 /* datablock.json in Resources */ = {isa = PBXBuildFile; fileRef = 4A92DEAF2239A62A00C12799 /* datablock.json */; };
4A92DEB22239A65300C12799 /* datablock_no_optionals.json in Resources */ = {isa = PBXBuildFile; fileRef = 4A92DEB12239A65300C12799 /* datablock_no_optionals.json */; };
4A92DEB32239A81A00C12799 /* datablock.json in Resources */ = {isa = PBXBuildFile; fileRef = 4A92DEAF2239A62A00C12799 /* datablock.json */; };
4A92DEB42239A81E00C12799 /* datablock_no_optionals.json in Resources */ = {isa = PBXBuildFile; fileRef = 4A92DEB12239A65300C12799 /* datablock_no_optionals.json */; };
4AA3256E1D615F03003CFFA9 /* DataBlockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4D9F2CF1C5442C400A4A02F /* DataBlockTests.swift */; };
4AA3256F1D615F03003CFFA9 /* DataPointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4D9F2CB1C54410300A4A02F /* DataPointTests.swift */; };
4AA325701D615F03003CFFA9 /* FlagTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4D9F2C71C54400700A4A02F /* FlagTests.swift */; };
Expand Down Expand Up @@ -153,6 +165,12 @@
4A7AFEA31D98B9BA00568802 /* Result.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Result.swift; path = Source/Result.swift; sourceTree = "<group>"; };
4A7C1CD2206FFBBD0021A961 /* CONTRIBUTING.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CONTRIBUTING.md; sourceTree = "<group>"; };
4A8B23511D447FB300ACBAA8 /* ForecastIO iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ForecastIO iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
4A92DEA322398FD300C12799 /* alerts.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = alerts.json; path = Tests/Resources/alerts.json; sourceTree = SOURCE_ROOT; };
4A92DEA6223997F900C12799 /* alerts_no_optionals.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = alerts_no_optionals.json; path = Tests/Resources/alerts_no_optionals.json; sourceTree = SOURCE_ROOT; };
4A92DEA922399B9000C12799 /* flag.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = flag.json; path = Tests/Resources/flag.json; sourceTree = SOURCE_ROOT; };
4A92DEAC2239A31100C12799 /* datapoint.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = datapoint.json; path = Tests/Resources/datapoint.json; sourceTree = SOURCE_ROOT; };
4A92DEAF2239A62A00C12799 /* datablock.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = datablock.json; path = Tests/Resources/datablock.json; sourceTree = SOURCE_ROOT; };
4A92DEB12239A65300C12799 /* datablock_no_optionals.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = datablock_no_optionals.json; path = Tests/Resources/datablock_no_optionals.json; sourceTree = SOURCE_ROOT; };
4AB7086C1D45230F005D1E8E /* LanguageTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LanguageTests.swift; path = Tests/LanguageTests.swift; sourceTree = SOURCE_ROOT; };
4AB708701D45246C005D1E8E /* IconTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = IconTests.swift; path = Tests/IconTests.swift; sourceTree = SOURCE_ROOT; };
4AB708741D452539005D1E8E /* PrecipitationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PrecipitationTests.swift; path = Tests/PrecipitationTests.swift; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -358,9 +376,15 @@
D4D9F2B31C54060800A4A02F /* Resources */ = {
isa = PBXGroup;
children = (
4A14A6EE1CDAA80300D4C108 /* forecast_bare.json */,
D4D9F2B41C54061600A4A02F /* forecast.json */,
4A14A6EE1CDAA80300D4C108 /* forecast_bare.json */,
4A3364661CD9712000775650 /* forecast_no_optionals.json */,
4A92DEAF2239A62A00C12799 /* datablock.json */,
4A92DEB12239A65300C12799 /* datablock_no_optionals.json */,
4A92DEAC2239A31100C12799 /* datapoint.json */,
4A92DEA922399B9000C12799 /* flag.json */,
4A92DEA322398FD300C12799 /* alerts.json */,
4A92DEA6223997F900C12799 /* alerts_no_optionals.json */,
);
name = Resources;
sourceTree = "<group>";
Expand Down Expand Up @@ -594,7 +618,7 @@
ProvisioningStyle = Manual;
};
D4A480641C507CE70053EB05 = {
LastSwiftMigration = 0930;
LastSwiftMigration = "";
};
D4A4807D1C507D730053EB05 = {
LastSwiftMigration = 1000;
Expand Down Expand Up @@ -644,6 +668,12 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4A92DEB22239A65300C12799 /* datablock_no_optionals.json in Resources */,
4A92DEB02239A62A00C12799 /* datablock.json in Resources */,
4A92DEAA22399B9000C12799 /* flag.json in Resources */,
4A92DEA422398FD300C12799 /* alerts.json in Resources */,
4A92DEAD2239A31100C12799 /* datapoint.json in Resources */,
4A92DEA7223997F900C12799 /* alerts_no_optionals.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -658,6 +688,12 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4A92DEA5223991B000C12799 /* alerts.json in Resources */,
4A92DEA82239997C00C12799 /* alerts_no_optionals.json in Resources */,
4A92DEB32239A81A00C12799 /* datablock.json in Resources */,
4A92DEB42239A81E00C12799 /* datablock_no_optionals.json in Resources */,
4A92DEAE2239A32C00C12799 /* datapoint.json in Resources */,
4A92DEAB22399CF100C12799 /* flag.json in Resources */,
D4D9F2B71C54061600A4A02F /* forecast.json in Resources */,
4A3364691CD9712000775650 /* forecast_no_optionals.json in Resources */,
4A14A6F51CDAA80F00D4C108 /* forecast_bare.json in Resources */,
Expand Down Expand Up @@ -1533,8 +1569,7 @@
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "watchsimulator watchos";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = 4;
TVOS_DEPLOYMENT_TARGET = 9.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -1570,8 +1605,7 @@
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "watchsimulator watchos";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = 4;
TVOS_DEPLOYMENT_TARGET = 9.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ With the `DarkSkyClient`, you can make two kinds of requests. The first will get
client.getForecast(latitude: myLat, longitude: myLon) { result in
switch result {
case .success(let currentForecast, let requestMetadata):
// We got the current forecast!
// We got the current forecast!
case .failure(let error):
// Uh-oh. We have an error!
// Uh-oh. We have an error!
}
}
```
Expand All @@ -99,9 +99,9 @@ The second kind of request is called a time machine request, and it will get a `
client.getForecast(latitude: myLat, longitude: myLon, time: myTime) { result in
switch result {
case .success(let forecast, let requestMetadata):
// We got the forecast!
// We got the forecast!
case .failure(let error):
// Uh-oh. We have an error!
// Uh-oh. We have an error!
}
}
```
Expand Down
22 changes: 2 additions & 20 deletions Source/Alert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

/// A severe weather warning issued for a location by a governmental authority (consult the Dark Sky API documentation for a full list).
public struct Alert {
public struct Alert: Decodable {

/// A short text summary of the `Alert`.
public let title: String
Expand All @@ -33,7 +33,7 @@ public struct Alert {
public let severity: Severity

/// Severity categories of `Alert`s.
public enum Severity: String {
public enum Severity: String, Decodable {

/// `advisory` `Alert`s tell an individual to be aware of potentially severe weather.
case advisory = "advisory"
Expand All @@ -45,22 +45,4 @@ public struct Alert {
case warning = "warning"
}

/// Creates a new `Alert` from a JSON object.
///
/// - parameter json: A JSON object with keys corresponding to the `Alert`'s properties.
///
/// - returns: A new `Alert` filled with data from the given JSON object.
public init(fromJSON json: NSDictionary) {
title = json["title"] as! String
if let jsonExpires = json["expires"] as? Double {
expires = Date(timeIntervalSince1970: jsonExpires)
} else {
expires = nil
}
time = Date(timeIntervalSince1970: json["time"] as! Double)
uri = URL(string: json["uri"] as! String)!
description = json["description"] as! String
regions = json["regions"] as! [String]
severity = Severity(rawValue: json["severity"] as! String)!
}
}
33 changes: 21 additions & 12 deletions Source/DarkSkyClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,44 @@ open class DarkSkyClient : NSObject {
private func getForecast(url: URL, completionHandler: @escaping (Result<Forecast>) -> Void) {
var urlRequest = URLRequest(url: url)
urlRequest.addValue("gzip", forHTTPHeaderField: "Accept-Encoding")
let task = self.session.dataTask(with: urlRequest, completionHandler: { (data: Data?, response, err: Error?) -> Void in
if let err = err {
let task = self.session.dataTask(with: urlRequest, completionHandler: { (optData: Data?, optResponse, optErr: Error?) -> Void in
if let err = optErr {
completionHandler(Result.failure(err))
} else {
do {
let jsonObject = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers)
if let json = jsonObject as? NSDictionary, let httpURLResponse = response as? HTTPURLResponse {
let forecast = Forecast(fromJSON: json)
let requestMetadata = RequestMetadata(fromHTTPHeaderFields: httpURLResponse.allHeaderFields)
completionHandler(Result.success(forecast, requestMetadata))
guard let data = optData else {
completionHandler(Result.failure(ForecastIOError.missingData))
return
}
} catch _ {
let invalidJSONError = ForecastIOError.invalidJSON(data!)
completionHandler(Result.failure(invalidJSONError))
guard let response = optResponse as? HTTPURLResponse else {
completionHandler(Result.failure(ForecastIOError.missingHeaders))
return
}

let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .secondsSince1970
let forecast = try decoder.decode(Forecast.self, from: data)
let requestMetadata = RequestMetadata(fromHTTPHeaderFields: response.allHeaderFields)
completionHandler(Result.success(forecast, requestMetadata))
} catch DecodingError.dataCorrupted(let context) {
completionHandler(Result.failure(DecodingError.dataCorrupted(context)))
} catch {
completionHandler(Result.failure(ForecastIOError.unexpectedError))
}
}
})
task.resume()
}

private func buildForecastURL(latitude lat: Double, longitude lon: Double, time: Date?, extendHourly: Bool, excludeFields: [Forecast.Field]) -> URL {
// Build URL path
// Build URL path
var urlString = DarkSkyClient.darkSkyURL + apiKey + "/\(lat),\(lon)"
if let time = time {
let timeString = String(format: "%.0f", time.timeIntervalSince1970)
urlString.append(",\(timeString)")
}

// Build URL query parameters
// Build URL query parameters
var urlBuilder = URLComponents(string: urlString)!
var queryItems: [URLQueryItem] = []
if let units = self.units {
Expand Down
22 changes: 1 addition & 21 deletions Source/DataBlock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

/// Weather data for a specific location over a period of time.
public struct DataBlock {
public struct DataBlock: Decodable {

/// A human-readable text summary.
public let summary: String?
Expand All @@ -20,24 +20,4 @@ public struct DataBlock {
/// `DataPoint`s ordered by time, which describe the weather conditions at the requested location over time.
public let data: [DataPoint]

/// Creates a new `DataBlock` from a JSON object.
///
/// - parameter json: A JSON object with keys corresponding to the `DataBlock`'s properties.
///
/// - returns: A new `DataBlock` filled with data from the given JSON object.
public init(fromJSON json: NSDictionary) {
summary = json["summary"] as? String
if let jsonIcon = json["icon"] as? String {
icon = Icon(rawValue: jsonIcon)
} else {
icon = nil
}

let jsonData = json["data"] as! [NSDictionary]
var tempData = [DataPoint]()
for jsonDataPoint in jsonData {
tempData.append(DataPoint(fromJSON: jsonDataPoint))
}
data = tempData
}
}
Loading

0 comments on commit 919b3ea

Please sign in to comment.