Sha256: b49912d33dd5e118a1097fd73aacc539bb6d96efc1040ee04e13ea7a59b337a6
Contents?: true
Size: 1.29 KB
Versions: 3
Compression:
Stored size: 1.29 KB
Contents
(function () { "use strict"; window.Suricate = window.Suricate || {}; /* * Public */ Suricate.API = function(baseURL) { this.baseURL = baseURL; }; // Get widget configurations Suricate.API.prototype.getWidgets = function(callback) { this.sendRequest("GET", "/widgets", {}, function(data) { callback(data.widgets); }); }; // Get updated data for widget Suricate.API.prototype.getWidgetData = function(widgetID, callback) { var path = "/widgets/" + widgetID; this.sendRequest("GET", path, {}, callback); }; /* * Private */ // Send request to API Suricate.API.prototype.sendRequest = function(method, path, params, callback) { var self = this; var url = this.baseURL + path; $.ajax({ url: url, method: method, data: params, success: function(data) { self.handleResponse(url, data, callback); } }); }; Suricate.API.prototype.handleResponse = function(url, json, callback) { if(json.status == 200) { callback(json.data); } else { console.error("Failed to load request", "url", url, "response", json); } }; }());
Version data entries
3 entries across 3 versions & 1 rubygems