MCPcopy
hub / github.com/mgonto/restangular / fetchFunction

Function fetchFunction

src/restangular.js:1118–1207  ·  view source on GitHub ↗
(what, reqParams, headers)

Source from the content-addressed store, hash-verified

1116
1117
1118 function fetchFunction(what, reqParams, headers) {
1119 var __this = this;
1120 var deferred = $q.defer();
1121 var operation = 'getList';
1122 var url = urlHandler.fetchUrl(this, what);
1123 var whatFetched = what || __this[config.restangularFields.route];
1124
1125 var request = config.fullRequestInterceptor(null, operation,
1126 whatFetched, url, headers || {}, reqParams || {}, this[config.restangularFields.httpConfig] || {});
1127
1128 var filledArray = [];
1129 filledArray = config.transformElem(filledArray, true, whatFetched, service);
1130
1131 var method = 'getList';
1132
1133 if (config.jsonp) {
1134 method = 'jsonp';
1135 }
1136
1137 var okCallback = function(response) {
1138 var resData = response.data;
1139 var fullParams = response.config.params;
1140 var data = parseResponse(resData, operation, whatFetched, url, response, deferred);
1141
1142 // support empty response for getList() calls (some APIs respond with 204 and empty body)
1143 if (_.isUndefined(data) || '' === data) {
1144 data = [];
1145 }
1146 if (!_.isArray(data)) {
1147 throw new Error('Response for getList SHOULD be an array and not an object or something else');
1148 }
1149
1150 if (true === config.plainByDefault) {
1151 return resolvePromise(deferred, response, data, filledArray);
1152 }
1153
1154 var processedData = _.map(data, function(elem) {
1155 if (!__this[config.restangularFields.restangularCollection]) {
1156 return restangularizeElem(__this, elem, what, true, data);
1157 } else {
1158 return restangularizeElem(__this[config.restangularFields.parentResource],
1159 elem, __this[config.restangularFields.route], true, data);
1160 }
1161 });
1162
1163 processedData = _.extend(data, processedData);
1164
1165 if (!__this[config.restangularFields.restangularCollection]) {
1166 resolvePromise(
1167 deferred,
1168 response,
1169 restangularizeCollection(
1170 __this,
1171 processedData,
1172 what,
1173 true,
1174 fullParams
1175 ),

Callers

nothing calls this directly

Calls 2

resolvePromiseFunction · 0.85
restangularizePromiseFunction · 0.85

Tested by

no test coverage detected