Advertisement
flocsy

web request

May 11th, 2025
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. class UV {
  2. function fetch(lat as Double, lon as Double) as Void {
  3. var params = {"latitude"=>lat, "longitude"=>lon} as Dictionary<String, String or Double or Float or Number>;
  4. var url = "https://currentuvindex.com/api/v1/uvi";
  5. var options = {
  6. :method => Communications.HTTP_REQUEST_METHOD_GET,
  7. :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
  8. };
  9. log("fetch: " + url + " => " + params);
  10. var stats = System.getSystemStats();
  11. log("fetch: memory: free:" + stats.freeMemory + ", used:" + stats.usedMemory + ", total:" + stats.totalMemory);
  12. Communications.makeWebRequest(url, params as Dictionary<Object, Object>, options, method(:callback));
  13. }
  14.  
  15. 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*/;
  16.  
  17. function callback(responseCode as Number, data as DataValue) as Void {
  18. var stats = System.getSystemStats();
  19. log("callback: memory: free:" + stats.freeMemory + ", used:" + stats.usedMemory + ", total:" + stats.totalMemory);
  20. log("callback: " + responseCode + ", data: " + (data != null ? "size: " + data.size() + ", keys: " + data.keys() : null) + ", ok: " + (data != null ? data["ok"] : ""));
  21. }
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement