Skip to content

Commit

Permalink
Adding headers to LKAPI Routable Protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Sargent committed Feb 24, 2016
1 parent 5c5f342 commit 9844df9
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion Pod/Classes/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ public protocol Routable: URLRequestConvertible {
///Path to the endpoint
var path: NSURL { get }

///Optional parameters to send up with each request
///Optional parameters to send up in the body of each request
var parameters: [String: AnyObject]? { get }

///Optional http headers to send up with each request
var headers: [(String, String)]? { get }

///Mock data to return for tests
var mockData: AnyObject? { get }
}
Expand Down Expand Up @@ -153,3 +156,25 @@ public class API {
}.description
}
}


public extension API {
///Load in and parse the stored JSON file
public class func mockedDataObject(path: String) -> AnyObject? {
do {
if let dataPath = NSBundle.mainBundle().pathForResource(path, ofType: "json"),
data = NSData(contentsOfFile: dataPath) {

return try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments)
}
else {
print("❌ Unable to load file: \(path)")
return nil
}
}
catch let exception {
print("❌ Error occured while parsing JSON", exception)
return nil
}
}
}

0 comments on commit 9844df9

Please sign in to comment.