jam-cloud/app/assets/javascripts/jam_rest.js

84 lines
1.9 KiB
JavaScript

(function(context,$) {
/**
* Javascript wrappers for the REST API
*/
"use strict";
context.JK = context.JK || {};
context.JK.API = function(app) {
var self = this;
var logger = context.JK.logger;
function getUserDetail(options) {
var id = options && options["id"]
if(!id) {
id = context.JK.currentUserId;
}
var url = "/api/users/" + id;
return $.ajax({
type: "GET",
dataType: "json",
url: url,
async: true,
processData: false
});
}
function getCities (options) {
var country = options['country']
var region = options['region']
return $.ajax('/api/cities', {
data : { country: country, region: region },
dataType : 'json'
});
}
function getRegions(options) {
var country = options["country"]
return $.ajax('/api/regions', {
data : { country: country},
dataType : 'json'
});
}
function getIsps(options) {
var country = options["country"]
return $.ajax('/api/isps', {
data : { country: country},
dataType : 'json'
});
}
function getInstruments(options) {
return $.ajax('/api/instruments', {
data : { },
dataType : 'json'
});
}
function initialize() {
return self;
}
// Expose publics
this.initialize = initialize;
this.getUserDetail = getUserDetail;
this.getCities = getCities;
this.getRegions = getRegions;
this.getIsps = getIsps;
this.getInstruments = getInstruments
return this;
};
})(window,jQuery);