Skip to content

Instantly share code, notes, and snippets.

@aheze
Created April 28, 2020 18:41
Show Gist options
  • Save aheze/4586fb8f01e9623c97cab069b1835ef9 to your computer and use it in GitHub Desktop.
Save aheze/4586fb8f01e9623c97cab069b1835ef9 to your computer and use it in GitHub Desktop.
//import Foundation
//import Alamofire
let heroku_token = "4d6e1611-9b1a-4bdd-948c-1ea25dfb4178"
func load_all_apps(completion: @escaping ([Any]) -> ()) {
var json_apps_list: [Any] = []
print("APP")
let headers: HTTPHeaders = [
"Authorization": "Bearer \(heroku_token)",
"Accept": "application/vnd.heroku+json; version=3"
]
AF.request("https://api.heroku.com/apps", method: .get, encoding: JSONEncoding.default, headers: headers)
.responseJSON { response in
print(response)
print("he")
if let status = response.response?.statusCode {
switch (status) {
case 200:
print("[H.API] Success")
case 403:
print("[H.API] Not Authorized")
default:
print("error with response status: \(status)")
}
}
switch response.result {
case .success(let value):
// print("SUCC")
let JSON = value as! [Any]
json_apps_list = JSON
print(JSON)
completion(json_apps_list)
case .failure(let error):
print("[H.API] AF Error: \(error)")
}
}
// return json_apps_list
}
load_all_apps(completion: { jSonStuff in
print(jSonStuff)
print(jSonStuff[0])
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment