Created
March 2, 2019 14:50
-
-
Save Kmohamed/6e0057ef369723b0748755263b83545d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open func executeGETRequest(api:String, completionBlock:@escaping (Data?) -> Void) { | |
let environment = ProcessInfo.processInfo.environment | |
var baseUrl:String = "" | |
if let _ = environment["isUITest"] { | |
// Running in a UI test | |
baseUrl = ProcessInfo.processInfo.environment["BASEURL"]! | |
} else { | |
baseUrl = "https://api.example.com" | |
} | |
guard let gitUrl = URL(string: baseUrl + api) else { return } | |
let session = URLSession(configuration: URLSessionConfiguration.default) | |
let dataTask = session.dataTask(with: gitUrl) { (data, response, error) in | |
guard let data = data else { return } | |
do { | |
if let returnData = String(data: data, encoding: .utf8) { | |
print(returnData) | |
} else { | |
print("empty") | |
} | |
} | |
if let err = error { | |
print("Err", err) | |
} | |
completionBlock(data) | |
} | |
dataTask.resume() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment