Swiftpack.co - Package - WXKDarkSky/WXKDarkSky

WXKDarkSky

This Swift package is a Codable layer over the Dark Sky API for quick and easy access to API response objects. It’s super straightforward and directly modeled after the Dark Sky API docs.

This package is written in pure Swift, and it has no dependencies, so you don’t need to worry about conflicts or anything like that.

Compatibility

WXKDarkSky should work great with Swift 5.1.

Installation

Install WXKDarkSky via Swift Package Manager, or if you really don't want to, you can also import the source files manually. CocoaPods and Carthage are not officially supported. Use them at your own risk.

Swift Package Manager (recommended)

Of course, you'll need to add this package as a dependency in Swift Package Manager:

.package(url: "https://github.com/loopwxservices/WXKDarkSky.git", from: "4.0.0")

Then, just be sure to add "WXKDarkSky" as a dependency in the targets section.

Manual

Just get the source files out of the Sources folder and drag them into your Xcode project, and add them to any relevant targets. Just make sure to keep updated should changes be made to the Dark Sky API.

Usage

The DarkSkyResponse object structure should perfectly match that of the documented response format for ease of reference. In keeping with the documentation, nearly everything is an optional value, even if it is frequently included. Absolutely no assumption is made about the availability of weather data!

Build URLs for networking

WXKDarkSky does not include its own networking code, but you can build a URL for a request like so:

// Set up the request with your API key.
let request = DarkSkyRequest(key: "YOUR_API_KEY_HERE")
// Specify the point to use in the request
let point = DarkSkyRequest.Point(43.02, -108.38)

// Build a URL to use for a request using the default options
if let url = request.buildURL(point: point) {
    // ...
}

Your API key should never be hard-coded into a public product like an app; this puts it at risk of being compromised and, should it become compromised, will leave you with no way to replace the API key in code that already shipped.

Request configuration

The buildURL method supports two additional parameters for configuring your request. It takes an optional time parameter which defaults to nil, to which you may pass a Date object for a Time Machine request.

You can also create a DarkSkyRequest.Options object to specify the following options for the Dark Sky API:

  • exclude: Data blocks to exclude from the request.
  • extendHourly: Whether to extend the hourly forecast to 168 hours instead of 48 hours.
  • language: Language to be used in the response.
  • units: Units to be used in the response.

A DarkSkyRequest.Options object can be initialized with any combination of the above four. If you do not include one, it will use the default setting. You can also use Options.defaults to access the default options (for example, Options.defaults.extendHourly).

Accessing data from a response

After you obtain data from the Dark Sky API, using WXKDarkSky is very simple:

let data = // the data you retrieved
if let response = DarkSkyResponse(data: data) {
    // Sample to get the current temperature from the decoded JSON
    if let temperature = response.currently.temperature {
        print("Current temperature: " + String(describing: temperature))
    }
} else {
    // Gracefully handle a decoding error...
}

Contributing

WXKDarkSky is no longer being actively maintained.

Licensing/legal

This package is licensed under the MIT License, which allows you to do just about anything with this project (within Dark Sky's rules, of course) except sue for any malfunctions, as long as you give credit.

While we're at it with the legal stuff: This project is not affiliated in any way with The Dark Sky Company, LLC.

Github

link
Stars: 19

Dependencies

Used By

Total: 0

Releases

WXKDarkSky 4.0.0 - 2020-02-07 20:21:17

Added

  • Added Scottish Gaelic, Vietnamese, and Welsh languages.

Removed

  • DarkSkyRequest networking functionality has been removed. Use your own networking code to retrieve Dark Sky data and then pass that into the failable DarkSkyReponse(data:) init.

Renamed

  • The DarkSkyDataPoint struct is now DarkSkyResponse.DataPoint.
  • The DarkSkyDataBlock struct is now DarkSkyResponse.DataBlock.
  • The DarkSkyAlerts struct is now DarkSkyResponse.Alerts.
  • The DarkSkyFlags struct is now DarkSkyResponse.Flags.

Other notes

  • WXKDarkSky now uses SPM tools version 5.1.
  • This is the final release of WXKDarkSky; the project will no longer be maintained or supported. If you wish to continue development on this project, please fork it and let me know; I will link it here.

WXKDarkSky 3.1.0 - 2019-07-24 20:40:01

  • Removes the deprecated DarkSkyResponse.converted(from:) method. Use the failable init DarkSkyResponse(data:) instead.

WXKDarkSky 2.4.2 - 2019-07-24 20:30:27

Note: This is not the latest release of WXKDarkSky and fixes an issue with an older release. Please use WXKDarkSky 3.0.0 or later.

  • Adds typealiases for renamed types which were not typealiased in 2.4.0 or 2.4.1.

WXKDarkSky 3.0.0 - 2019-07-09 16:26:00

  • Deprecated classes WXKDarkSkyReponse and WXKDarkSkyRequest, along with the deprecated method DarkSkyRequest.buildDarkSkyURL(point:time:options:) have been removed.
    • WXKDarkSkyResponse was renamed to DarkSkyResponse.
    • WXKDarkSkyRequest was renamed to DarkSkyRequest.
    • buildDarkSkyURL was renamed to buildURL.
  • Inline documentation and access control improvements.

WXKDarkSky 2.4.1 - 2019-07-09 05:26:23

Rerelease of 2.4.0 for CocoaPods. See the release notes for 2.4.0.

WXKDarkSky 2.4.0 - 2019-07-09 05:12:24

  • Renames WXKDarkSkyResponse to DarkSkyResponse and WXKDarkSkyRequest to DarkSkyRequest. The old prefixed names are available as typealiases but deprecated and will be removed in a future release.
  • Renames DarkSkyRequest.buildDarkSkyURL(...) to DarkSkyRequest.buildURL(...). The old method is available but deprecated and will be removed in a future release.
  • Deprecates DarkSkyResponse.converted(from:) in favor of a failable init DarkSkyResponse(data:).
  • Adds support for several new languages.

WXKDarkSky 2.3.0 - 2019-07-09 03:34:32

  • Updated to Swift 5.0.

WXKDarkSky 2.2.1 - 2019-06-27 02:27:18

  • Fixes an issue where decoding using WXKDarkSkyResponse did not use the correct date decoding strategy.

WXKDarkSky 2.2 - 2018-06-22 02:52:59

WXKDarkSky 2.2 includes the following changes:

  • We now support CocoaPods installation! Let us know if you run into any issues.
  • You can now directly create WXKDarkSkyResponse objects from Data objects that contain Dark Sky API JSON responses.
  • Inline documentation improvements.

WXKDarkSky 2.1 - 2018-06-18 17:04:41

This release simply makes the method which constructs a URL for a Dark Sky request public (instead of internal) so that the method may be used with custom networking code.

WXKDarkSky 2.0.3 - 2018-06-18 02:21:56

  • Adds language support for summaries in Hebrew and Korean (#3).

WXKDarkSky 2.0.2 - 2018-01-09 01:43:12

This update fixes some issues with non-public initializers which should, in fact, be public. It also makes the version number palindromic, so there’s that.


What’s new in WXKDarkSky 2.0.x:

  • Removed the deprecated max/min temperatures in favor of daytime highs and overnight lows (#2).
  • Added basic networking functionality for retrieving data from the Dark Sky API (#3).
  • Now decodes times from JSON as Date objects rather than Ints (#4).

These changes may break your code. Please ensure compatibility with the above tweaks (particularly the new temperature and date coding conventions) before updating to the new version.

WXKDarkSky 1.0.4 - 2018-01-02 23:29:03

This release adds support for apparentTemperatureHigh, apparentTemperatureHighTime, apparentTemperatureLow, and apparentTemperatureLowTime on daily data points

It also adds deprecation warnings for the old maximum/minimum temperature (and apparent temperature) items. They will be removed in the next release, version 2.0.0. If you are still using them, you should see buildtime warnings suggesting that you move away from them.

Please move to the new high/low convention as soon as possible—adopting them should require nearly no effort on your part beyond some renaming.

WXKDarkSky 1.0.3 - 2017-11-26 17:44:52

  • Made the structs Codable instead of just Decodable, since…well, why not?

WXKDarkSky 1.0.2 - 2017-10-05 18:43:05

In this release:

  • Support for temperatureHigh and temperatureLow and associated keys, which were added to daily data points [#1]

WXKDarkSky 1.0.1 - 2017-08-19 21:30:27

Initial release.