Last active
February 28, 2017 14:29
-
-
Save sclark39/4da054d0519612dcb55408a2f8b1f9ba 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
private func makeRequest( | |
method : String, url : String, | |
query : [String:Any]! = nil, | |
body : [String:Any]! = nil, | |
complete: @escaping DatabaseAsyncCallback | |
) | |
{ | |
let client = WOMAPIGatewayClient.default() | |
let headerParameters = | |
client.invokeHTTPRequest( | |
method, | |
urlString: url, | |
pathParameters: nil, | |
queryParameters: query ?? [:], | |
headerParameters: | |
[ | |
"Content-Type": "application/json; charset=utf-8", | |
"Accept": "application/json", | |
], | |
body:body | |
).continueWith(executor: AWSExecutor.default(), block: | |
{ (task) -> Any? in | |
if (task.error != nil) | |
{ | |
print("Error: " + task.error!.localizedDescription) | |
} | |
else | |
{ | |
let data = task.result! | |
print("Data Received: \(data)") | |
if let json = data as? [Any] | |
{ | |
complete(["body":json]) | |
} | |
else if let json = data as? [String:Any] | |
{ | |
complete(json) | |
} | |
else | |
{ | |
print("Error: Problem decoding JSON from API\n\tUnable to cast to Swift object") | |
} | |
} | |
return task; | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment