Commit 22040c7d by Rashid Khan

Upgrade elasticjs

parent 444bb406
/*! elastic.js - v1.0.0 - 2013-03-05 /*! elastic.js - v1.1.1 - 2013-05-24
* https://github.com/fullscale/elastic.js * https://github.com/fullscale/elastic.js
* Copyright (c) 2013 FullScale Labs, LLC; Licensed MIT */ * Copyright (c) 2013 FullScale Labs, LLC; Licensed MIT */
/*jshint browser:true */ /*jshint browser:true */
/*global angular:true */ /*global angular:true */
/*jshint es5:true */
'use strict'; 'use strict';
/* /*
Angular.js service wrapping the elastic.js API. This module can simply Angular.js service wrapping the elastic.js API. This module can simply
be injected into your angular controllers. be injected into your angular controllers.
*/ */
angular.module('elasticjs.service', []) angular.module('elasticjs.service', [])
.factory('ejsResource', ['$http', function ($http) { .factory('ejsResource', ['$http', function ($http) {
return function (url) { return function (config) {
var var
...@@ -32,40 +31,54 @@ angular.module('elasticjs.service', []) ...@@ -32,40 +31,54 @@ angular.module('elasticjs.service', [])
}); });
}; };
// check if we have a config object
// if not, we have the server url so
// we convert it to a config object
if (config !== Object(config)) {
config = {server: config};
}
// set url to empty string if it was not specified // set url to empty string if it was not specified
if (url == null) { if (config.server == null) {
url = ''; config.server = '';
} }
/* implement the elastic.js client interface for angular */ /* implement the elastic.js client interface for angular */
ejs.client = { ejs.client = {
server: function (s) { server: function (s) {
if (s == null) { if (s == null) {
return url; return config.server;
} }
url = s; config.server = s;
return this; return this;
}, },
post: function (path, data, successcb, errorcb) { post: function (path, data, successcb, errorcb) {
path = url + path; path = config.server + path;
return promiseThen($http.post(path, data), successcb, errorcb); var reqConfig = {url: path, data: data, method: 'POST'};
return promiseThen($http(angular.extend(reqConfig, config)), successcb, errorcb);
}, },
get: function (path, data, successcb, errorcb) { get: function (path, data, successcb, errorcb) {
path = url + path; path = config.server + path;
return promiseThen($http.get(path, data), successcb, errorcb); // no body on get request, data will be request params
var reqConfig = {url: path, params: data, method: 'GET'};
return promiseThen($http(angular.extend(reqConfig, config)), successcb, errorcb);
}, },
put: function (path, data, successcb, errorcb) { put: function (path, data, successcb, errorcb) {
path = url + path; path = config.server + path;
return promiseThen($http.put(path, data), successcb, errorcb); var reqConfig = {url: path, data: data, method: 'PUT'};
return promiseThen($http(angular.extend(reqConfig, config)), successcb, errorcb);
}, },
del: function (path, data, successcb, errorcb) { del: function (path, data, successcb, errorcb) {
path = url + path; path = config.server + path;
return promiseThen($http.delete(path, data), successcb, errorcb); var reqConfig = {url: path, data: data, method: 'DELETE'};
return promiseThen($http(angular.extend(reqConfig, config)), successcb, errorcb);
}, },
head: function (path, data, successcb, errorcb) { head: function (path, data, successcb, errorcb) {
path = url + path; path = config.server + path;
return $http.head(path, data) // no body on HEAD request, data will be request params
var reqConfig = {url: path, params: data, method: 'HEAD'};
return $http(angular.extend(reqConfig, config))
.then(function (response) { .then(function (response) {
(successcb || angular.noop)(response.headers()); (successcb || angular.noop)(response.headers());
return response.headers(); return response.headers();
...@@ -75,7 +88,7 @@ angular.module('elasticjs.service', []) ...@@ -75,7 +88,7 @@ angular.module('elasticjs.service', [])
}); });
} }
}; };
return ejs; return ejs;
}; };
}]); }]);
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment