Skip to content
This repository has been archived by the owner on May 6, 2021. It is now read-only.

Commit

Permalink
Add API endpoint for service advisories
Browse files Browse the repository at this point in the history
  • Loading branch information
asmallteapot committed May 3, 2019
1 parent c707acc commit 49ee1bf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Resources/SampleData/serviceAdvisory.json
@@ -0,0 +1,26 @@
{
"?xml":{
"@version":"1.0",
"@encoding":"utf-8"
},
"root":{
"@id":"1",
"uri":{
"#cdata-section":"http://api.bart.gov/api/bsa.aspx?cmd=bsa&json=y"
},
"date":"06/26/2017",
"time":"11:08:00 AM PDT",
"bsa":[
{
"station":"",
"description":{
"#cdata-section":"No delays reported."
},
"sms_text":{
"#cdata-section":"No delays reported."
}
}
],
"message":""
}
}
16 changes: 16 additions & 0 deletions Sources/BART/APIService.swift
Expand Up @@ -6,6 +6,11 @@ public enum APIService {
/// The public BART API key.
public static let apiKey = "MW9S-E7SL-26DU-VV8V"

/// Fetch service advisories
/// - SeeAlso:
/// [BART API documentation](http://api.bart.gov/docs/bsa/bsa.aspx)
case serviceAdvisories

/// Fetch estimated departures for every station
/// - SeeAlso:
/// [BART API documentation](http://api.bart.gov/docs/etd/etd.aspx)
Expand All @@ -30,6 +35,8 @@ public enum APIService {
extension APIService {
fileprivate var sampleDataName: String {
switch self {
case .serviceAdvisories:
return "serviceAdvisories"
case .estimatedDepartures:
return "estimatedDepartures"
case .routes:
Expand All @@ -53,6 +60,8 @@ extension APIService: TargetType {

public var path: String {
switch self {
case .serviceAdvisories:
return "bsa.aspx"
case .estimatedDepartures:
return "etd.aspx"
case .routes:
Expand All @@ -78,6 +87,13 @@ extension APIService: TargetType {

public var task: Task {
switch self {
case .serviceAdvisories:
return .requestParameters(parameters: [
"cmd": "bsa",
"orig": "all",
"key": APIService.apiKey,
"json": "y"
], encoding: Moya.URLEncoding.queryString)
case .estimatedDepartures:
return .requestParameters(parameters: [
"cmd": "etd",
Expand Down

0 comments on commit 49ee1bf

Please sign in to comment.