[ad_1]
Background I am building a desktop app that will enable me to aggregate some analytics for Confluence pages.
To do this you call the Atlassian Confluence API and get all pages for a space. The way we have the space set up we use labels and we have a “no-analytics” label which allows us to filter out landing pages or other pages we’ve no interest in getting analytics from.
To get the labels you need to get the page id then make a separate API call using the id and label endpoint. This is where I am getting stuck, I get all the page ids, dump them into an array, loop through the array and make the API call. Check the results and see if any of the labels contain “no-analytics”, if not I filter those ids into a new array that I can then use to make the analytic calls.
So the problem is I can’t tell when the API calls are complete and the new array has all the ids. Here’s my code. Open to any suggestions to make this more efficient and, well, work. : D
@objc func getKTCLabels(notification:NSNotification) {
var arrPagesToAnalyze:Array<String> = []
if let dictData = notification.userInfo as? Dictionary<String, Any>, let arrIds = dictData["ids"] as? Array<String> {
for thisId in arrIds {
//get the labels for this page
let strURL = myAppManager.formatURL(["id":thisId], 2)
myAppManager.callAPI(strURL, .confluence, completed: {(dictResults:Dictionary<String, Any>) in
if let arrData = dictResults["data"] as? Array<Dictionary<String, Any>> {
if arrData.count > 0 {
var bNoAnalytics = false
for dictLabel in arrData {
if let strLabel = dictLabel["label"] as? String {
if strLabel == "no-analytics" {
bNoAnalytics = true
break
}
}
}
if !bNoAnalytics {
arrPagesToAnalyze.append(thisId)
}
} else {
print(strURL) //page url without labels
}
}
})
}//end loop
}
}
[ad_2]