Skip to content
This repository has been archived by the owner on Apr 30, 2019. It is now read-only.

Commit

Permalink
Fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron McTavish committed Jan 4, 2017
1 parent 03fc1ef commit 19d0077
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Brunel.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0820;
ORGANIZATIONNAME = ustwo;
TargetAttributes = {
008280F21C4CFE6500186513 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
22 changes: 15 additions & 7 deletions Sources/API/TFLLineAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,24 @@ extension TFLLineAPI: TargetType {
var method: Moya.Method {
switch self {
case .modeStatus, .search, .status:
return .GET
return .get
}
}

var parameters: [String: AnyObject]? {
var multipartBody: [MultipartFormData]? {
return nil
}

var parameterEncoding: ParameterEncoding {
return URLEncoding.default
}

var parameters: [String: Any]? {
switch self {
case let .modeStatus(_, detail):
return ["detail" : encodeBool(detail) as AnyObject]
return ["detail" : encodeBool(detail)]
case let .status(_, detail):
return ["detail" : encodeBool(detail) as AnyObject]

return ["detail" : encodeBool(detail)]
case .search:
return nil
}
Expand All @@ -66,10 +73,11 @@ extension TFLLineAPI: TargetType {
return emptyStringData
}

var multipartBody: [MultipartFormData]? {
return nil
var task: Task {
return .request
}


// MARK: - Convenience

fileprivate func csvFromArray(_ value: [String]) -> String {
Expand Down
22 changes: 11 additions & 11 deletions Sources/API/TFLRestAPI-Line-GET.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ import Foundation
extension TFLRestAPI {

func getLineStatus(_ modes: [TFLModes], completion: @escaping ([TFLLine]?, RestAPIError?) -> Void) {
tfl(lineProvider, target: .ModeStatus(modes: modes, detail: true), completion: { resultJSON, error in
tfl(lineProvider, target: .modeStatus(modes: modes, detail: true), completion: { resultJSON, error in
if let resultJSON = resultJSON {

var lines = [TFLLine]()
guard let jsonArray = resultJSON.array else {
completion(nil, .InvalidJSON(localizedDescription: "Expected array."))
completion(nil, .invalidJSON(localizedDescription: "Expected array."))
return
}


for jsonItem in jsonArray {
guard let line = TFLLine(jsonObject: jsonItem) else {
completion(nil, .InvalidJSON(localizedDescription: "Bad JSON to initialize `TFLLine`."))
completion(nil, .invalidJSON(localizedDescription: "Bad JSON to initialize `TFLLine`."))
return
}

Expand All @@ -36,19 +36,19 @@ extension TFLRestAPI {
completion(nil, error)
return
} else {
completion(nil, .UnknownError)
completion(nil, .unknownError)
return
}
})
}

func getLineSearch(_ query: String, completion: @escaping ([TFLLineSearch]?, RestAPIError?) -> Void) {
tfl(lineProvider, target: .Search(query: query), completion: { resultJSON, error in
tfl(lineProvider, target: .search(query: query), completion: { resultJSON, error in
if let resultJSON = resultJSON {

var lines = [TFLLineSearch]()
guard let jsonArray = resultJSON["searchMatches"].array else {
completion(nil, .InvalidJSON(localizedDescription: "Expected array."))
completion(nil, .invalidJSON(localizedDescription: "Expected array."))
return
}

Expand All @@ -64,26 +64,26 @@ extension TFLRestAPI {
completion(nil, error)
return
} else {
completion(nil, .UnknownError)
completion(nil, .unknownError)
return
}
})
}

func getLineStatus(_ lines: [String], completion: @escaping ([TFLLine]?, RestAPIError?) -> Void) {
tfl(lineProvider, target: .Status(lines: lines, detail: true), completion: { resultJSON, error in
tfl(lineProvider, target: .status(lines: lines, detail: true), completion: { resultJSON, error in
if let resultJSON = resultJSON {

var lines = [TFLLine]()
guard let jsonArray = resultJSON.array else {
completion(nil, .InvalidJSON(localizedDescription: "Expected array."))
completion(nil, .invalidJSON(localizedDescription: "Expected array."))
return
}


for jsonItem in jsonArray {
guard let line = TFLLine(jsonObject: jsonItem) else {
completion(nil, .InvalidJSON(localizedDescription: "Bad JSON to initialize `TFLLine`."))
completion(nil, .invalidJSON(localizedDescription: "Bad JSON to initialize `TFLLine`."))
return
}

Expand All @@ -95,7 +95,7 @@ extension TFLRestAPI {
completion(nil, error)
return
} else {
completion(nil, .UnknownError)
completion(nil, .unknownError)
return
}
})
Expand Down
8 changes: 4 additions & 4 deletions Sources/API/TFLRestAPI-StopPoint-GET.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import Foundation
extension TFLRestAPI {

func getStopPointList(_ modes: [TFLModes], completion: @escaping ([TFLLine]?, RestAPIError?) -> Void) {
tfl(stopPointProvider, target: .StopPointList(modes: modes), completion: { resultJSON, error in
tfl(stopPointProvider, target: .stopPointList(modes: modes), completion: { resultJSON, error in
if let resultJSON = resultJSON {

print(resultJSON.rawString()!)

var lines = [TFLLine]()
guard let jsonArray = resultJSON.array else {
completion(nil, .InvalidJSON(localizedDescription: "Expected array."))
completion(nil, .invalidJSON(localizedDescription: "Expected array."))
return
}


for jsonItem in jsonArray {
guard let line = TFLLine(jsonObject: jsonItem) else {
completion(nil, .InvalidJSON(localizedDescription: "Bad JSON to initialize `TFLLine`."))
completion(nil, .invalidJSON(localizedDescription: "Bad JSON to initialize `TFLLine`."))
return
}

Expand All @@ -38,7 +38,7 @@ extension TFLRestAPI {
completion(nil, error)
return
} else {
completion(nil, .UnknownError)
completion(nil, .unknownError)
return
}
})
Expand Down
18 changes: 9 additions & 9 deletions Sources/API/TFLRestAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Moya
import SwiftyJSON


enum RestAPIError: Error {
enum RestAPIError: Swift.Error {
case genericError(localizedDescription: String)
case invalidJSON(localizedDescription: String)
case unknownError
Expand Down Expand Up @@ -57,7 +57,7 @@ struct TFLRestAPI {
*/
static func TFLEndpointClosure<T: TargetType>(_ appID: String, appKey: String) -> ((T) -> Endpoint<T>) {
return { (target: T) -> Endpoint<T> in
var newParameters = [String : AnyObject]()
var newParameters = [String : Any]()

newParameters["app_id"] = appID
newParameters["app_key"] = appKey
Expand All @@ -68,7 +68,7 @@ struct TFLRestAPI {
}
}

let endpoint: Endpoint<T> = Endpoint<T>(URL: url(target), sampleResponseClosure: {.NetworkResponse(200, target.sampleData)}, method: target.method, parameters: newParameters, parameterEncoding: .URL, httpHeaderFields: nil)
let endpoint: Endpoint<T> = Endpoint<T>(url: url(target), sampleResponseClosure: {.networkResponse(200, target.sampleData)}, method: target.method, parameters: newParameters, parameterEncoding: URLEncoding.default, httpHeaderFields: nil)

return endpoint
}
Expand All @@ -81,21 +81,21 @@ struct TFLRestAPI {
- parameter target: Endpoint from which to request data.
- parameter completion: Completion handler that returns either a valid JSON object or an error based on the response.
*/
internal func tfl<T: TargetType>(_ provider: MoyaProvider<T>, target: T, completion: (JSON?, RestAPIError?) -> Void) {
internal func tfl<T: TargetType>(_ provider: MoyaProvider<T>, target: T, completion: @escaping (JSON?, RestAPIError?) -> Void) {
provider.request(target, completion: { result in
switch result {
case let .Success(response):
case let .success(response):
do {
let jsonObj = try response.mapJSON()
let resultJSON = JSON(jsonObj)

completion(resultJSON, nil)
} catch let error as NSError {
completion(nil, .GenericError(localizedDescription: error.localizedDescription))
completion(nil, .genericError(localizedDescription: error.localizedDescription))
return
}
case let .Failure(error):
completion(nil, .GenericError(localizedDescription: error.description))
case let .failure(error):
completion(nil, .genericError(localizedDescription: error.description))
return
}
})
Expand All @@ -112,5 +112,5 @@ struct TFLRestAPI {
- returns: URL string for endpoint.
*/
func url(_ route: TargetType) -> String {
return route.baseURL.URLByAppendingPathComponent(route.path)!.absoluteString!
return route.baseURL.appendingPathComponent(route.path).absoluteString
}
18 changes: 14 additions & 4 deletions Sources/API/TFLStopPointAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum TFLStopPointAPI {


extension TFLStopPointAPI: TargetType {


var baseURL: URL { return URL(string: "https://api.tfl.gov.uk")! }

Expand All @@ -36,11 +37,19 @@ extension TFLStopPointAPI: TargetType {
var method: Moya.Method {
switch self {
case .stopPointList:
return .GET
return .get
}
}

var parameters: [String: AnyObject]? {
var multipartBody: [MultipartFormData]? {
return nil
}

var parameterEncoding: ParameterEncoding {
return URLEncoding.default
}

var parameters: [String: Any]? {
switch self {
case .stopPointList:
return nil
Expand All @@ -52,10 +61,11 @@ extension TFLStopPointAPI: TargetType {
return emptyStringData
}

var multipartBody: [MultipartFormData]? {
return nil
var task: Task {
return .request
}


// MARK: - Convenience

fileprivate func csvFromArray(_ value: [String]) -> String {
Expand Down
26 changes: 17 additions & 9 deletions Sources/API/WikipediaAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,26 @@ extension WikipediaAPI: TargetType {
var method: Moya.Method {
switch self {
case .queryTitle:
return .GET
return .get
}
}

var parameters: [String: AnyObject]? {
var multipartBody: [MultipartFormData]? {
return nil
}

var parameterEncoding: ParameterEncoding {
return URLEncoding.default
}

var parameters: [String: Any]? {
switch self {
case let .queryTitle(title):
return ["action" : "query" as AnyObject,
"prop" : "extracts" as AnyObject,
"exintro" : "" as AnyObject,
"explaintext" : "" as AnyObject,
"titles" : title as AnyObject]
return ["action" : "query",
"prop" : "extracts",
"exintro" : "",
"explaintext" : "",
"titles" : title]
}
}

Expand All @@ -50,8 +58,8 @@ extension WikipediaAPI: TargetType {
return emptyStringData
}

var multipartBody: [MultipartFormData]? {
return nil
var task: Task {
return .request
}

}
8 changes: 4 additions & 4 deletions Sources/API/WikipediaRestAPI-GET.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import Foundation
extension WikipediaRestAPI {

func getQueryTitle(_ title: String, completion: @escaping (String?, RestAPIError?) -> Void) {
wikipedia(provider, target: .QueryTitle(title: title), completion: { resultJSON, error in
wikipedia(provider, target: .queryTitle(title: title), completion: { resultJSON, error in
if let resultJSON = resultJSON {
guard let pagesDictionary = resultJSON["query"]["pages"].dictionary else {
completion(nil, .InvalidJSON(localizedDescription: "Expected `pages` dictionary."))
completion(nil, .invalidJSON(localizedDescription: "Expected `pages` dictionary."))
return
}

let firstKey = Array(pagesDictionary.keys)[0]

guard let extract = pagesDictionary[firstKey]?["extract"].string else {
completion(nil, .InvalidJSON(localizedDescription: "Expected `extract`."))
completion(nil, .invalidJSON(localizedDescription: "Expected `extract`."))
return
}

Expand All @@ -31,7 +31,7 @@ extension WikipediaRestAPI {
completion(nil, error)
return
} else {
completion(nil, .UnknownError)
completion(nil, .unknownError)
return
}
})
Expand Down
Loading

0 comments on commit 19d0077

Please sign in to comment.