Skip to content

Commit 3cb5fc7

Browse files
committed
Added time, regions, and severity properties and Severity enum to the Alert struct
1 parent b20f414 commit 3cb5fc7

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

Source/Alert.swift

+25
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public struct Alert {
1414
/// A short text summary of the `Alert`.
1515
public let title: String
1616

17+
/// The time at which this alert was issued.
18+
public let time: Date
19+
1720
/// The time at which the `Alert` will cease to be valid.
1821
public let expires: Date?
1922

@@ -23,6 +26,25 @@ public struct Alert {
2326
/// An HTTP(S) URI that contains detailed information about the `Alert`.
2427
public let uri: URL
2528

29+
/// Regions covered by the `Alert`.
30+
public let regions: [String]
31+
32+
/// The severity of the `Alert`.
33+
public let severity: Severity
34+
35+
/// Severity categories of `Alert`s.
36+
public enum Severity: String {
37+
38+
/// `advisory` `Alert`s tell an individual to be aware of potentially severe weather.
39+
case advisory = "advisory"
40+
41+
/// `watch` `Alert`s tell an individual to prepare for potentially severe weather.
42+
case watch = "watch"
43+
44+
/// `warning` `Alert`s tell an individual to take immediate action to protect themselves and others from potentially severe weather.
45+
case warning = "warning"
46+
}
47+
2648
/// Creates a new `Alert` from a JSON object.
2749
///
2850
/// - parameter json: A JSON object with keys corresponding to the `Alert`'s properties.
@@ -35,7 +57,10 @@ public struct Alert {
3557
} else {
3658
expires = nil
3759
}
60+
time = Date(timeIntervalSince1970: json["time"] as! Double)
3861
uri = URL(string: json["uri"] as! String)!
3962
description = json["description"] as! String
63+
regions = json["regions"] as! [String]
64+
severity = Severity(rawValue: json["severity"] as! String)!
4065
}
4166
}

Tests/Resources/forecast_no_optionals.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -1616,13 +1616,17 @@
16161616
"title":"High Wind Warning for Baltimore, MD",
16171617
"time":1453562580,
16181618
"description":"...HIGH WIND WARNING REMAINS IN EFFECT UNTIL 7 PM EST THIS\nEVENING...\n* TIMING...THROUGH TODAY.\n* WINDS...NORTH 25 TO 35 MPH WITH GUSTS UP TO 55 MPH.\n* IMPACTS...DOWNED TREES...POWERLINES...AND MINOR STRUCTURAL\nDAMAGE. DRIVING HIGH PROFILE VEHICLES IN THESE CONDITIONS IS\nDANGEROUS.\n",
1619-
"uri":"http://alerts.weather.gov/cap/wwacapget.php?x=MD1255E4FAA7AC.HighWindWarning.1255E5079700MD.LWXNPWLWX.b0aa96f59630770f05e80c219b873fd2"
1619+
"uri":"http://alerts.weather.gov/cap/wwacapget.php?x=MD1255E4FAA7AC.HighWindWarning.1255E5079700MD.LWXNPWLWX.b0aa96f59630770f05e80c219b873fd2",
1620+
"severity":"watch",
1621+
"regions": ["Eastern Bergen","Eastern Essex","Eastern Passaic","Eastern Union","Hudson","Western Bergen","Western Essex","Western Passaic","Western Union"]
16201622
},
16211623
{
16221624
"title":"Blizzard Warning for Baltimore, MD",
16231625
"time":1453559700,
16241626
"description":"VERY STRONG LOW PRESSURE WILL DRIFT EAST FROM THE MOUTH OF THE\nCHESAPEAKE BAY TODAY.\n...BLIZZARD WARNING REMAINS IN EFFECT UNTIL 6 AM EST SUNDAY...\n* HAZARD TYPES...HEAVY SNOW AND BLOWING SNOW.\n* SNOW ACCUMULATIONS...22 TO 30 INCHES...UP TO 36 INCHES ABOVE\n1200 FEET.\n* TIMING...HEAVY SNOW THROUGH THIS EVENING. BLOWING SNOW INTO\nSUNDAY.\n* IMPACTS...HEAVY SNOW AND BLOWING SNOW WILL CONTINUE TO CAUSE\nDANGEROUS CONDITIONS AND WILL BE A THREAT TO LIFE AND PROPERTY.\nTRAVEL IS IMPOSSIBLE. VISIBILITY WILL BE REDUCED TO NEAR ZERO\nAT TIMES IN WHITEOUT CONDITIONS THROUGH TONIGHT.\n* WINDS...NORTH 20 TO 30 MPH WITH GUSTS UP TO 50 MPH.\n* TEMPERATURES...IN THE LOWER 20S. WIND CHILLS SINGLE DIGITS.\n",
1625-
"uri":"http://alerts.weather.gov/cap/wwacapget.php?x=MD1255E4FA854C.BlizzardWarning.1255E50944B0MD.LWXWSWLWX.2725408b6d049dc67224e179c743dc2d"
1627+
"uri":"http://alerts.weather.gov/cap/wwacapget.php?x=MD1255E4FA854C.BlizzardWarning.1255E50944B0MD.LWXWSWLWX.2725408b6d049dc67224e179c743dc2d",
1628+
"severity":"watch",
1629+
"regions": ["Eastern Bergen","Eastern Essex","Eastern Passaic","Eastern Union","Hudson","Western Bergen","Western Essex","Western Passaic","Western Union"]
16261630
}
16271631
],
16281632
"flags":{

0 commit comments

Comments
 (0)