Skip to content

Commit

Permalink
Version 4.0 (#11)
Browse files Browse the repository at this point in the history
- Renamed HPOpenWeather to OpenWeather
- Updated some method signatures
- greatly simplified decoding of responses which improves readability
- added more documentation comments
- added alerts
  • Loading branch information
henrik-dmg authored Dec 15, 2020
1 parent 6087a1e commit 7a81c06
Show file tree
Hide file tree
Showing 33 changed files with 617 additions and 604 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
runs-on: macos-latest

steps:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- uses: actions/checkout@v2
- name: Build
run: swift build -v
Expand Down
2 changes: 1 addition & 1 deletion HPOpenWeather.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "HPOpenWeather"
s.version = "3.6.0"
s.version = "4.0.0"
s.summary = "Cross-platform framework to communicate with the OpenWeatherMap JSON API"

s.license = { :type => "MIT", :file => "LICENSE.md" }
Expand Down
11 changes: 7 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@ let package = Package(
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "HPOpenWeather",
targets: ["HPOpenWeather"])
targets: ["HPOpenWeather"]
)
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/henrik-dmg/HPNetwork", from: "0.1.0")
.package(url: "https://github.com/henrik-dmg/HPNetwork", from: "0.8.0")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "HPOpenWeather",
dependencies: ["HPNetwork"]),
dependencies: ["HPNetwork"]
),
.testTarget(
name: "HPOpenWeatherTests",
dependencies: ["HPOpenWeather"])
dependencies: ["HPOpenWeather"]
)
]
)
30 changes: 13 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,33 @@
<a href="https://github.com/henrik-dmg/HPOpenWeather/blob/master/.github/workflows/swift.yml"><img src="https://github.com/henrik-dmg/HPOpenWeather/workflows/Swift/badge.svg" alt="Github Actions"/></a>
[![GitHub license](https://img.shields.io/github/license/henrik-dmg/HPOpenWeather)](https://github.com/henrik-dmg/HPOpenWeather/blob/master/LICENSE.md)

HPOpenWeather is a cross-platform Swift framework to communicate with the OpenWeatherMap JSON API. See their [documentation](https://openweathermap.org/api) for further details.
HPOpenWeather is a cross-platform Swift framework to communicate with the OpenWeather One-Call API. See their [documentation](https://openweathermap.org/api/one-call-api) for further details.
## Installation

HPOpenWeather supports iOS 9.0+, watchOS 2.0+, tvOS 9.0+ and macOS 10.10+.
HPOpenWeather supports iOS 9.0+, watchOS 3.0+, tvOS 9.0+ and macOS 10.10+.

#### SPM

Add `.package(url: "https://github.com/henrik-dmg/HPOpenWeather", from: "3.0.0")` to your `Package.swift` file
Add `.package(url: "https://github.com/henrik-dmg/HPOpenWeather", from: "4.0.0")` to your `Package.swift` file

#### CocoaPods

Add `pod 'HPOpenWeather'` to your `Podfile` and run `pod install`

## Usage

To get started, you need an API key from [OpenWeatherMap](https://openweathermap.org). Put this API key in the initialiser, additionally you can also specify a custom temperature format and/or language used in the responses (see list for available languages and units below).
To get started, you need an API key from [OpenWeather](https://openweathermap.org). Put this API key in the initialiser, additionally you can also specify a custom temperature format and/or language used in the responses (see list for available languages and units below).
```swift
import HPOpenWeather

// Assign API key
HPOpenWeather.shared.apiKey = "--- YOUR API KEY ---"
OpenWeather.shared.apiKey = "--- YOUR API KEY ---"
OpenWeather.shared.language = .german
OpenWeather.shared.units = .metric

// Or use options
let settings = OpenWeather.Settings(apiKey: "yourAPIKey", language: .german, units: .metric)
OpenWeather.shared.apply(settings)
```
You can also customise the response data units and language by accessing the `language` and `units` propertis.

Expand All @@ -47,10 +53,10 @@ let timemachineRequest = TimeMachineRequest(coordinate: .init(latitude: 40, long

**Note:** the date has to be at least 6 hours in the past

To post a request, call the `requestWeather` on `HPOpenWeather`:
To post a request, call `sendWeatherRequest` on `OpenWeather`:

```swift
HPOpenWeather.shared.requestWeather(request) { result in
OpenWeather.shared.sendWeatherRequest(request) { result in
switch result {
case .success(let response):
// do something with weather data here
Expand Down Expand Up @@ -87,13 +93,3 @@ HPOpenWeather.shared.requestWeather(request) { result in
- Celsius (default)
- Kelvin
- Fahrenheit

## TODO List
- [x] Current weather data
- [x] Daily and hourly forecast
- [x] More Unit Tests
- [x] Historical Data
- [ ] UV Index Data
- [ ] watchOS and tvOS demo apps

#### This documentation is far from complete, however the code itself is pretty well documented so feel free to just play around and just contact me if you have any suggestions :)
25 changes: 25 additions & 0 deletions Sources/HPOpenWeather/DataTypes/Alert.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Foundation

/// Type that holds information about weather alerts
public struct Alert: Codable, Hashable, Equatable {

/// Name of the alert source. Please read here the full list of alert sources
public let senderName: String
/// Alert event name
public let eventName: String
//// Date and time of the start of the alert
public let startDate: Date
//// Date and time of the end of the alert
public let endDate: Date
/// Description of the alert
public let description: String

enum CodingKeys: String, CodingKey {
case senderName = "sender_name"
case eventName = "event"
case startDate = "start"
case endDate = "end"
case description
}

}
94 changes: 0 additions & 94 deletions Sources/HPOpenWeather/DataTypes/CurrentWeather.swift

This file was deleted.

97 changes: 0 additions & 97 deletions Sources/HPOpenWeather/DataTypes/DailyForecast.swift

This file was deleted.

7 changes: 7 additions & 0 deletions Sources/HPOpenWeather/DataTypes/DailyTemperature.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import Foundation

/// Type that holds information about daily temperature changes
public struct DailyTemperature: Codable, Equatable, Hashable {

/// Day temperature.
public let day: Double
/// Night temperature.
public let night: Double
/// Minimum daily temperature.
public let min: Double?
/// Max daily temperature.
public let max: Double?
/// Evening temperature.
public let evening: Double
/// Morning temperature.
public let morning: Double

enum CodingKeys: String, CodingKey {
Expand Down
Loading

0 comments on commit 7a81c06

Please sign in to comment.