fetch ongoing matches and put them into the list
This commit is contained in:
@@ -7,38 +7,27 @@
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
import SwiftyJSON
|
||||
|
||||
class StatusBarController: NSObject {
|
||||
|
||||
let baseURL = "https://liquipedia.net/"
|
||||
let game = "dota2"
|
||||
let query = "/api.php?action=parse&page=Liquipedia:Upcoming_and_ongoing_matches&format=json&prop=text"
|
||||
|
||||
var html = ""
|
||||
|
||||
func constructURL(baseURL: String, game: String, query: String) -> String {
|
||||
return baseURL + game + query
|
||||
@IBOutlet weak var statusBar: NSMenu!
|
||||
let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
|
||||
let matchesAPI = MatchesAPI()
|
||||
var matches = [Match]()
|
||||
|
||||
override func awakeFromNib() {
|
||||
let icon = NSImage(named: "statusBarIcon")
|
||||
icon?.isTemplate = true
|
||||
statusItem.image = icon
|
||||
statusItem.menu = statusBar
|
||||
}
|
||||
|
||||
func fetch(url: String) {
|
||||
|
||||
DispatchQueue.global().async {
|
||||
|
||||
[unowned self] in
|
||||
if let url = URL(string: url) {
|
||||
if let data = try? String(contentsOf: url) {
|
||||
let json = JSON(parseJSON: data)
|
||||
self.html = self.extractHTML(json: json)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@IBAction func quitClicked(_ sender: NSMenuItem) {
|
||||
NSApplication.shared.terminate(self)
|
||||
}
|
||||
|
||||
func extractHTML(json: JSON) -> String {
|
||||
return json["parse"]["text"].stringValue
|
||||
@IBAction func request(_ sender: NSMenuItem) {
|
||||
matches = matchesAPI.fetch(for: "dota2")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user