Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UV {
- function fetch(lat as Double, lon as Double) as Void {
- var params = {"latitude"=>lat, "longitude"=>lon} as Dictionary<String, String or Double or Float or Number>;
- var url = "https://currentuvindex.com/api/v1/uvi";
- var options = {
- :method => Communications.HTTP_REQUEST_METHOD_GET,
- :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
- };
- log("fetch: " + url + " => " + params);
- var stats = System.getSystemStats();
- log("fetch: memory: free:" + stats.freeMemory + ", used:" + stats.usedMemory + ", total:" + stats.totalMemory);
- Communications.makeWebRequest(url, params as Dictionary<Object, Object>, options, method(:callback));
- }
- typedef DataValue as Null or Dictionary<String, Boolean or Float or Array<Dictionary<String, String or Float>> or Dictionary<String, String or Float>> /*or String or PersistedContent.Iterator*/;
- function callback(responseCode as Number, data as DataValue) as Void {
- var stats = System.getSystemStats();
- log("callback: memory: free:" + stats.freeMemory + ", used:" + stats.usedMemory + ", total:" + stats.totalMemory);
- log("callback: " + responseCode + ", data: " + (data != null ? "size: " + data.size() + ", keys: " + data.keys() : null) + ", ok: " + (data != null ? data["ok"] : ""));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement