Created
April 25, 2015 00:05
-
-
Save seveibar/ef89a61c851bb094ce9d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Copyright (c) 2015, <your name>. All rights reserved. Use of this source code | |
// is governed by a BSD-style license that can be found in the LICENSE file. | |
/// The SiaIExx library. | |
library SiaIExx; | |
import 'dart:async'; | |
import 'dart:convert'; | |
import 'package:http/http.dart' as http; | |
// Classes | |
class HostStatus{ | |
int TotalStorage; | |
int MinFilesize; | |
int Price; | |
// rest of props | |
HostStatus(_totalStorage, _minFileSize, _price): | |
TotalStorage = _totalStorage, MinFilesize = _minFileSize, Price = _price; | |
HostStatus copy(){ | |
return new HostStatus(TotalStorage, MinFilesize, Price); | |
} | |
} | |
// Variables | |
HostStatus latestHostStatus; | |
// "Getters" | |
HostStatus getHostStatus(){ | |
return latestHostStatus.copy(); | |
} | |
// Timer approach | |
void updateGlobalVariables(Timer t){ | |
http.get("localhost:9980/host/status").then((response){ | |
var json = JSON.decode(response.body); | |
latestHostStatus.TotalStorage = json["TotalStorage"]; | |
// rest of props | |
}); | |
} | |
main(){ | |
Duration duration = new Duration(milliseconds:500); | |
new Timer.periodic(duration, updateGlobalVariables); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment