Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
3lvis committed Nov 17, 2015
1 parent f9536a1 commit 52907c6
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions Source/Networking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public class Networking {
private var stubs: [RequestType : [String : AnyObject]]
private var token: String?
private var imageCache = NSCache()

/**
Internal flag used to disable synchronous request when running automatic tests
*/
internal var disableTestingMode = false

private lazy var session: NSURLSession = {
Expand Down Expand Up @@ -64,13 +68,26 @@ public class Networking {
}

/**
Generates a NSURL by appending the provided path to the Networking's base URL.
Returns a NSURL by appending the provided path to the Networking's base URL.
- parameter path: The path to be appended to the base URL.
- returns: A NSURL generated after appending the path to the base URL.
*/
public func urlForPath(path: String) -> NSURL {
return NSURL(string: self.baseURL + path)!
}

/**
Returns the NSURL used to store a resource for a certain path. Useful to find where a download image is located.
- parameter path: The path used to download the resource.
- returns: A NSURL where a resource has been stored.
*/
public func destinationURL(path: String) -> NSURL {
guard let url = NSURL(string: (self.urlForPath(path).absoluteString as NSString).stringByReplacingOccurrencesOfString("/", withString: "-")),
cachesURL = NSFileManager.defaultManager().URLsForDirectory(.CachesDirectory, inDomains: .UserDomainMask).first else { fatalError("Couldn't normalize url") }
let destinationURL = cachesURL.URLByAppendingPathComponent(url.absoluteString)

return destinationURL
}
}

// MARK: HTTP requests
Expand Down Expand Up @@ -259,14 +276,6 @@ extension Networking {
public func stubImageDownload(path: String, image: UIImage) {
self.stub(.GET, path: path, response: image)
}

public func destinationURL(path: String) -> NSURL {
guard let url = NSURL(string: (self.urlForPath(path).absoluteString as NSString).stringByReplacingOccurrencesOfString("/", withString: "-")),
cachesURL = NSFileManager.defaultManager().URLsForDirectory(.CachesDirectory, inDomains: .UserDomainMask).first else { fatalError("Couldn't normalize url") }
let destinationURL = cachesURL.URLByAppendingPathComponent(url.absoluteString)

return destinationURL
}
#endif
}

Expand Down

0 comments on commit 52907c6

Please sign in to comment.