Skip to content

Instantly share code, notes, and snippets.

@sclark39
Last active February 28, 2017 14:29
Show Gist options
  • Save sclark39/4da054d0519612dcb55408a2f8b1f9ba to your computer and use it in GitHub Desktop.
Save sclark39/4da054d0519612dcb55408a2f8b1f9ba to your computer and use it in GitHub Desktop.
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