GithubHelp home page GithubHelp logo

wxkdarksky / wxkdarksky Goto Github PK

View Code? Open in Web Editor NEW
20.0 5.0 4.0 255 KB

A pure-Swift Codable layer over the Dark Sky API.

License: MIT License

Swift 100.00%
codable json dark-sky dark-sky-api weather swift-package-manager swift swift-package swift-5

wxkdarksky's Introduction

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.

wxkdarksky's People

Contributors

jonblatho avatar lwsllc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

wxkdarksky's Issues

Remove DarkSkyRequest networking functionality and prohibit client-side use

It appears that some have chosen to use WXKDarkSky to make client-side requests in spite of warnings from both Dark Sky and us (both here and inline documentation), which poses a risk of the API key becoming compromised and makes matters worse should the API key ever become compromised. Therefore, we intend to remove the DarkSkyRequest networking functionality in WXKDarkSky 4.0.

Starting with WXKDarkSky 3.2, coming soon, the DarkSkyRequest.loadData(...) method will be marked deprecated with a warning suggesting that users migrate to their own networking solution going forward. In WXKDarkSky 4.0, our first SPM-only release coming early next year, the method will be marked unavailable and its functionality removed. In a later release, the method will be removed entirely.

The other DarkSkyRequest functionality (i.e., the URL builder) will remain available but will be restricted to macOS and Linux only to limit it to server-side use. Users who wish to continue this unsupported use may continue to use WXKDarkSky 3.1 and earlier, though we very strongly advise against doing so.

As a reminder, the safest way to handle Dark Sky requests client-side is as follows:

  1. Your app authenticates with your server to request weather data from the Dark Sky API.
  2. Your app sends a request for weather data to your server.
  3. Your server passes the request along to the Dark Sky API.
  4. Your server returns the Dark Sky API’s response to your app.

This procedure keeps the Dark Sky API key in your hands and makes it possible to swap out API keys should your key ever be compromised.

We believe that this will have minimal impact on supported use cases because better solutions exist for server-side Swift projects (the intended use case) anyway, and client-side use is unsupported and we will never intend to support it.

We regret any inconvenience this may cause, but we prefer to err on the side of caution here due to the significant risks associated with exposing one’s API key.

[BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C3.1:2][0x101f1c190] get output frames failed

Hi,
I'm new to whole iOS development and sometimes I'm getting this "error?". And when I'm getting this it looks like data are synchronised a little bit slower.

2018-10-17 14:35:09.231199+1100 WeatherOutside[424:57727] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C3.1:2][0x101f1c190] get output frames failed, state 8196
2018-10-17 14:35:09.231471+1100 WeatherOutside[424:57727] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C3.1:2][0x101f1c190] get output frames failed, state 8196
2018-10-17 14:35:09.232281+1100 WeatherOutside[424:57727] TIC Read Status [3:0x0]: 1:57
2018-10-17 14:35:09.232341+1100 WeatherOutside[424:57727] TIC Read Status [3:0x0]: 1:57

Decode UNIX times as Date objects

When decoding data into WXKDarkSkyResponse objects, convert UNIX times to Date objects in Swift Foundation for easier manipulation rather than using automatic encoding into Int.

Make WXKDarkSkyRequest unavailable for client-side use

While we added CocoaPods support in version 2.2, the WXKDarkSkyRequest class is available for use in client-side scenarios. Requests to the Dark Sky API should never be made client-side. The best way of handling this, of course, is to make the class unavailable altogether for client-side scenarios.

Swift makes this a bit difficult. The closest approximation I can find for making WXKDarkSkyRequest unavailable client-side is to use @available(..., unavailable) for the following platforms:

  • iOS
  • iOSApplicationExtension
  • macOSApplicationExtension
  • watchOS
  • watchOSApplicationExtension
  • tvOS
  • tvOSApplicationExtension

That excludes all platforms where it’s either impossible or unreasonable to try to run a server…but it leaves the macOS platform. Making the class unavailable on macOS would prevent client-side usage, but it’d also prevent possible server-side usage on macOS. I’d be inclined to allow availability on macOS.

This issue doesn’t need to be fixed immediately. Hopefully, the multiple warnings both here on GitHub and in the inline documentation are enough for now. Rather, it’s sticking a pin in this matter to see if later Swift versions open up a proper solution.

Remove old max/min temperature convention in favor of high/low temperatures

Dark Sky has deprecated the following items on daily data points:

  • temperatureMax
  • temperatureMaxTime
  • temperatureMin
  • temperatureMinTime
  • apparentTemperatureMax
  • apparentTemperatureMaxTime
  • apparentTemperatureMin
  • apparentTemperatureMinTime

These calculate the maximum/minimum temperature from midnight to midnight, but that’s not how high/low temperatures are typically calculated. Usually, one uses the daytime high and overnight low temperature, which may not match the given items.

Therefore, the listed items have been deprecated and replaced by Dark Sky with temperatureHigh, temperatureHighTime, temperatureLow, etc. This is currently the only deprecated code supported by WXKDarkSky.

Deprecation warnings for the listed items were added in WXKDarkSky 1.0.4, and they will be removed for release 2.0, which should help to avoid breaking code already using the deprecated items.

RFC: Discontinuation of CocoaPods support in favor of Swift Package Manager

Rationale

The recommended method of installation for WXKDarkSky has always been to install via Swift Package Manager (SPM) where possible because WXKDarkSky started as, and still is, a Swift package. But last year, we began offering CocoaPods support because it was somewhat difficult at the time to integrate WXKDarkSky—or any Swift package—into Xcode projects used to build apps for Apple platforms.

This year at WWDC, however, Apple announced that Swift packages will be supported in Xcode 11 projects and workspaces, providing official support for integrating WXKDarkSky into all Xcode projects where there previously wasn’t technically any. We strongly favor the decentralized approach of SPM, and releasing new versions for SPM requires zero additional manual effort on our part as we don’t have to update a file and upload it to a central repo like we do for CocoaPods.

We have tested this in our own projects and found that Swift packages should can be easily mixed into Xcode workspaces generated by CocoaPods, and so we feel as if we have little cause to continue supporting the WXKDarkSky pod.

Instructions for migration

Migrating from the WXKDarkSky pod to the Swift package, for most if not all projects, should be as simple as performing the following steps:

  1. Remove pod 'WXKDarkSky' from your Podfile.
  2. In Xcode 11, go to File > Swift Packages > Add Package Dependency…
  3. Select the project(s) to which you wish to add the dependency. Click Next.
  4. Enter the GitHub repository URL (https://github.com/loopwxservices/WXKDarkSky.git) in the search bar. Select WXKDarkSky and click Next.
  5. If desired, select the version dependency rule appropriate for your project. Click Next.
  6. Select a target to which to add the WXKDarkSky library. (You can add it to other targets later, if needed, by adding it in the Frameworks and Libraries section for each target.)
  7. Run $ pod update. This should remove WXKDarkSky from the Pods project.
  8. Compile to make sure everything works.

Proposal

We propose the following to be effective beginning on December 31, 2019:

  • We will no longer provide new feature releases for CocoaPods.
  • The WXKDarkSky pod will be deprecated but may still be used.
  • We will (generally) no longer officially support the use of the WXKDarkSky pod.
  • Should any major bugs arise with WXKDarkSky releases already available on CocoaPods, we may choose to release an update which resolves those bugs, at our discretion, on an “as-is” basis.

We feel that December 31 provides enough time for folks to migrate, but we’re certainly open to suggestions on this, whether that means pushing the date back or even cancelling this altogether. Please let us know if you have any comments, questions, or concerns.

Add support for new max/min temperature

At the end of August, Dark Sky added support for two new temperature fields, temperatureHigh and temperatureLow, to daily data points in order to better match standards for reporting daily temperature maxima and minima.

WXKDarkSky does not yet have support for this, but it should be able to be done by adding these fields as properties in WXKDarkSkyDataPoint.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.