angular-gem 1.2.21 → 1.2.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,621 @@
1
+ /**
2
+ * @license AngularJS v1.2.22
3
+ * (c) 2010-2014 Google, Inc. http://angularjs.org
4
+ * License: MIT
5
+ */
6
+ (function(window, angular, undefined) {'use strict';
7
+
8
+ var $resourceMinErr = angular.$$minErr('$resource');
9
+
10
+ // Helper functions and regex to lookup a dotted path on an object
11
+ // stopping at undefined/null. The path must be composed of ASCII
12
+ // identifiers (just like $parse)
13
+ var MEMBER_NAME_REGEX = /^(\.[a-zA-Z_$][0-9a-zA-Z_$]*)+$/;
14
+
15
+ function isValidDottedPath(path) {
16
+ return (path != null && path !== '' && path !== 'hasOwnProperty' &&
17
+ MEMBER_NAME_REGEX.test('.' + path));
18
+ }
19
+
20
+ function lookupDottedPath(obj, path) {
21
+ if (!isValidDottedPath(path)) {
22
+ throw $resourceMinErr('badmember', 'Dotted member path "@{0}" is invalid.', path);
23
+ }
24
+ var keys = path.split('.');
25
+ for (var i = 0, ii = keys.length; i < ii && obj !== undefined; i++) {
26
+ var key = keys[i];
27
+ obj = (obj !== null) ? obj[key] : undefined;
28
+ }
29
+ return obj;
30
+ }
31
+
32
+ /**
33
+ * Create a shallow copy of an object and clear other fields from the destination
34
+ */
35
+ function shallowClearAndCopy(src, dst) {
36
+ dst = dst || {};
37
+
38
+ angular.forEach(dst, function(value, key){
39
+ delete dst[key];
40
+ });
41
+
42
+ for (var key in src) {
43
+ if (src.hasOwnProperty(key) && !(key.charAt(0) === '$' && key.charAt(1) === '$')) {
44
+ dst[key] = src[key];
45
+ }
46
+ }
47
+
48
+ return dst;
49
+ }
50
+
51
+ /**
52
+ * @ngdoc module
53
+ * @name ngResource
54
+ * @description
55
+ *
56
+ * # ngResource
57
+ *
58
+ * The `ngResource` module provides interaction support with RESTful services
59
+ * via the $resource service.
60
+ *
61
+ *
62
+ * <div doc-module-components="ngResource"></div>
63
+ *
64
+ * See {@link ngResource.$resource `$resource`} for usage.
65
+ */
66
+
67
+ /**
68
+ * @ngdoc service
69
+ * @name $resource
70
+ * @requires $http
71
+ *
72
+ * @description
73
+ * A factory which creates a resource object that lets you interact with
74
+ * [RESTful](http://en.wikipedia.org/wiki/Representational_State_Transfer) server-side data sources.
75
+ *
76
+ * The returned resource object has action methods which provide high-level behaviors without
77
+ * the need to interact with the low level {@link ng.$http $http} service.
78
+ *
79
+ * Requires the {@link ngResource `ngResource`} module to be installed.
80
+ *
81
+ * @param {string} url A parametrized URL template with parameters prefixed by `:` as in
82
+ * `/user/:username`. If you are using a URL with a port number (e.g.
83
+ * `http://example.com:8080/api`), it will be respected.
84
+ *
85
+ * If you are using a url with a suffix, just add the suffix, like this:
86
+ * `$resource('http://example.com/resource.json')` or `$resource('http://example.com/:id.json')`
87
+ * or even `$resource('http://example.com/resource/:resource_id.:format')`
88
+ * If the parameter before the suffix is empty, :resource_id in this case, then the `/.` will be
89
+ * collapsed down to a single `.`. If you need this sequence to appear and not collapse then you
90
+ * can escape it with `/\.`.
91
+ *
92
+ * @param {Object=} paramDefaults Default values for `url` parameters. These can be overridden in
93
+ * `actions` methods. If any of the parameter value is a function, it will be executed every time
94
+ * when a param value needs to be obtained for a request (unless the param was overridden).
95
+ *
96
+ * Each key value in the parameter object is first bound to url template if present and then any
97
+ * excess keys are appended to the url search query after the `?`.
98
+ *
99
+ * Given a template `/path/:verb` and parameter `{verb:'greet', salutation:'Hello'}` results in
100
+ * URL `/path/greet?salutation=Hello`.
101
+ *
102
+ * If the parameter value is prefixed with `@` then the value for that parameter will be extracted
103
+ * from the corresponding property on the `data` object (provided when calling an action method). For
104
+ * example, if the `defaultParam` object is `{someParam: '@someProp'}` then the value of `someParam`
105
+ * will be `data.someProp`.
106
+ *
107
+ * @param {Object.<Object>=} actions Hash with declaration of custom action that should extend
108
+ * the default set of resource actions. The declaration should be created in the format of {@link
109
+ * ng.$http#usage_parameters $http.config}:
110
+ *
111
+ * {action1: {method:?, params:?, isArray:?, headers:?, ...},
112
+ * action2: {method:?, params:?, isArray:?, headers:?, ...},
113
+ * ...}
114
+ *
115
+ * Where:
116
+ *
117
+ * - **`action`** – {string} – The name of action. This name becomes the name of the method on
118
+ * your resource object.
119
+ * - **`method`** – {string} – Case insensitive HTTP method (e.g. `GET`, `POST`, `PUT`,
120
+ * `DELETE`, `JSONP`, etc).
121
+ * - **`params`** – {Object=} – Optional set of pre-bound parameters for this action. If any of
122
+ * the parameter value is a function, it will be executed every time when a param value needs to
123
+ * be obtained for a request (unless the param was overridden).
124
+ * - **`url`** – {string} – action specific `url` override. The url templating is supported just
125
+ * like for the resource-level urls.
126
+ * - **`isArray`** – {boolean=} – If true then the returned object for this action is an array,
127
+ * see `returns` section.
128
+ * - **`transformRequest`** –
129
+ * `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
130
+ * transform function or an array of such functions. The transform function takes the http
131
+ * request body and headers and returns its transformed (typically serialized) version.
132
+ * - **`transformResponse`** –
133
+ * `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
134
+ * transform function or an array of such functions. The transform function takes the http
135
+ * response body and headers and returns its transformed (typically deserialized) version.
136
+ * - **`cache`** – `{boolean|Cache}` – If true, a default $http cache will be used to cache the
137
+ * GET request, otherwise if a cache instance built with
138
+ * {@link ng.$cacheFactory $cacheFactory}, this cache will be used for
139
+ * caching.
140
+ * - **`timeout`** – `{number|Promise}` – timeout in milliseconds, or {@link ng.$q promise} that
141
+ * should abort the request when resolved.
142
+ * - **`withCredentials`** - `{boolean}` - whether to set the `withCredentials` flag on the
143
+ * XHR object. See
144
+ * [requests with credentials](https://developer.mozilla.org/en/http_access_control#section_5)
145
+ * for more information.
146
+ * - **`responseType`** - `{string}` - see
147
+ * [requestType](https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType).
148
+ * - **`interceptor`** - `{Object=}` - The interceptor object has two optional methods -
149
+ * `response` and `responseError`. Both `response` and `responseError` interceptors get called
150
+ * with `http response` object. See {@link ng.$http $http interceptors}.
151
+ *
152
+ * @returns {Object} A resource "class" object with methods for the default set of resource actions
153
+ * optionally extended with custom `actions`. The default set contains these actions:
154
+ * ```js
155
+ * { 'get': {method:'GET'},
156
+ * 'save': {method:'POST'},
157
+ * 'query': {method:'GET', isArray:true},
158
+ * 'remove': {method:'DELETE'},
159
+ * 'delete': {method:'DELETE'} };
160
+ * ```
161
+ *
162
+ * Calling these methods invoke an {@link ng.$http} with the specified http method,
163
+ * destination and parameters. When the data is returned from the server then the object is an
164
+ * instance of the resource class. The actions `save`, `remove` and `delete` are available on it
165
+ * as methods with the `$` prefix. This allows you to easily perform CRUD operations (create,
166
+ * read, update, delete) on server-side data like this:
167
+ * ```js
168
+ * var User = $resource('/user/:userId', {userId:'@id'});
169
+ * var user = User.get({userId:123}, function() {
170
+ * user.abc = true;
171
+ * user.$save();
172
+ * });
173
+ * ```
174
+ *
175
+ * It is important to realize that invoking a $resource object method immediately returns an
176
+ * empty reference (object or array depending on `isArray`). Once the data is returned from the
177
+ * server the existing reference is populated with the actual data. This is a useful trick since
178
+ * usually the resource is assigned to a model which is then rendered by the view. Having an empty
179
+ * object results in no rendering, once the data arrives from the server then the object is
180
+ * populated with the data and the view automatically re-renders itself showing the new data. This
181
+ * means that in most cases one never has to write a callback function for the action methods.
182
+ *
183
+ * The action methods on the class object or instance object can be invoked with the following
184
+ * parameters:
185
+ *
186
+ * - HTTP GET "class" actions: `Resource.action([parameters], [success], [error])`
187
+ * - non-GET "class" actions: `Resource.action([parameters], postData, [success], [error])`
188
+ * - non-GET instance actions: `instance.$action([parameters], [success], [error])`
189
+ *
190
+ * Success callback is called with (value, responseHeaders) arguments. Error callback is called
191
+ * with (httpResponse) argument.
192
+ *
193
+ * Class actions return empty instance (with additional properties below).
194
+ * Instance actions return promise of the action.
195
+ *
196
+ * The Resource instances and collection have these additional properties:
197
+ *
198
+ * - `$promise`: the {@link ng.$q promise} of the original server interaction that created this
199
+ * instance or collection.
200
+ *
201
+ * On success, the promise is resolved with the same resource instance or collection object,
202
+ * updated with data from server. This makes it easy to use in
203
+ * {@link ngRoute.$routeProvider resolve section of $routeProvider.when()} to defer view
204
+ * rendering until the resource(s) are loaded.
205
+ *
206
+ * On failure, the promise is resolved with the {@link ng.$http http response} object, without
207
+ * the `resource` property.
208
+ *
209
+ * If an interceptor object was provided, the promise will instead be resolved with the value
210
+ * returned by the interceptor.
211
+ *
212
+ * - `$resolved`: `true` after first server interaction is completed (either with success or
213
+ * rejection), `false` before that. Knowing if the Resource has been resolved is useful in
214
+ * data-binding.
215
+ *
216
+ * @example
217
+ *
218
+ * # Credit card resource
219
+ *
220
+ * ```js
221
+ // Define CreditCard class
222
+ var CreditCard = $resource('/user/:userId/card/:cardId',
223
+ {userId:123, cardId:'@id'}, {
224
+ charge: {method:'POST', params:{charge:true}}
225
+ });
226
+
227
+ // We can retrieve a collection from the server
228
+ var cards = CreditCard.query(function() {
229
+ // GET: /user/123/card
230
+ // server returns: [ {id:456, number:'1234', name:'Smith'} ];
231
+
232
+ var card = cards[0];
233
+ // each item is an instance of CreditCard
234
+ expect(card instanceof CreditCard).toEqual(true);
235
+ card.name = "J. Smith";
236
+ // non GET methods are mapped onto the instances
237
+ card.$save();
238
+ // POST: /user/123/card/456 {id:456, number:'1234', name:'J. Smith'}
239
+ // server returns: {id:456, number:'1234', name: 'J. Smith'};
240
+
241
+ // our custom method is mapped as well.
242
+ card.$charge({amount:9.99});
243
+ // POST: /user/123/card/456?amount=9.99&charge=true {id:456, number:'1234', name:'J. Smith'}
244
+ });
245
+
246
+ // we can create an instance as well
247
+ var newCard = new CreditCard({number:'0123'});
248
+ newCard.name = "Mike Smith";
249
+ newCard.$save();
250
+ // POST: /user/123/card {number:'0123', name:'Mike Smith'}
251
+ // server returns: {id:789, number:'0123', name: 'Mike Smith'};
252
+ expect(newCard.id).toEqual(789);
253
+ * ```
254
+ *
255
+ * The object returned from this function execution is a resource "class" which has "static" method
256
+ * for each action in the definition.
257
+ *
258
+ * Calling these methods invoke `$http` on the `url` template with the given `method`, `params` and
259
+ * `headers`.
260
+ * When the data is returned from the server then the object is an instance of the resource type and
261
+ * all of the non-GET methods are available with `$` prefix. This allows you to easily support CRUD
262
+ * operations (create, read, update, delete) on server-side data.
263
+
264
+ ```js
265
+ var User = $resource('/user/:userId', {userId:'@id'});
266
+ User.get({userId:123}, function(user) {
267
+ user.abc = true;
268
+ user.$save();
269
+ });
270
+ ```
271
+ *
272
+ * It's worth noting that the success callback for `get`, `query` and other methods gets passed
273
+ * in the response that came from the server as well as $http header getter function, so one
274
+ * could rewrite the above example and get access to http headers as:
275
+ *
276
+ ```js
277
+ var User = $resource('/user/:userId', {userId:'@id'});
278
+ User.get({userId:123}, function(u, getResponseHeaders){
279
+ u.abc = true;
280
+ u.$save(function(u, putResponseHeaders) {
281
+ //u => saved user object
282
+ //putResponseHeaders => $http header getter
283
+ });
284
+ });
285
+ ```
286
+ *
287
+ * You can also access the raw `$http` promise via the `$promise` property on the object returned
288
+ *
289
+ ```
290
+ var User = $resource('/user/:userId', {userId:'@id'});
291
+ User.get({userId:123})
292
+ .$promise.then(function(user) {
293
+ $scope.user = user;
294
+ });
295
+ ```
296
+
297
+ * # Creating a custom 'PUT' request
298
+ * In this example we create a custom method on our resource to make a PUT request
299
+ * ```js
300
+ * var app = angular.module('app', ['ngResource', 'ngRoute']);
301
+ *
302
+ * // Some APIs expect a PUT request in the format URL/object/ID
303
+ * // Here we are creating an 'update' method
304
+ * app.factory('Notes', ['$resource', function($resource) {
305
+ * return $resource('/notes/:id', null,
306
+ * {
307
+ * 'update': { method:'PUT' }
308
+ * });
309
+ * }]);
310
+ *
311
+ * // In our controller we get the ID from the URL using ngRoute and $routeParams
312
+ * // We pass in $routeParams and our Notes factory along with $scope
313
+ * app.controller('NotesCtrl', ['$scope', '$routeParams', 'Notes',
314
+ function($scope, $routeParams, Notes) {
315
+ * // First get a note object from the factory
316
+ * var note = Notes.get({ id:$routeParams.id });
317
+ * $id = note.id;
318
+ *
319
+ * // Now call update passing in the ID first then the object you are updating
320
+ * Notes.update({ id:$id }, note);
321
+ *
322
+ * // This will PUT /notes/ID with the note object in the request payload
323
+ * }]);
324
+ * ```
325
+ */
326
+ angular.module('ngResource', ['ng']).
327
+ factory('$resource', ['$http', '$q', function($http, $q) {
328
+
329
+ var DEFAULT_ACTIONS = {
330
+ 'get': {method:'GET'},
331
+ 'save': {method:'POST'},
332
+ 'query': {method:'GET', isArray:true},
333
+ 'remove': {method:'DELETE'},
334
+ 'delete': {method:'DELETE'}
335
+ };
336
+ var noop = angular.noop,
337
+ forEach = angular.forEach,
338
+ extend = angular.extend,
339
+ copy = angular.copy,
340
+ isFunction = angular.isFunction;
341
+
342
+ /**
343
+ * We need our custom method because encodeURIComponent is too aggressive and doesn't follow
344
+ * http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
345
+ * segments:
346
+ * segment = *pchar
347
+ * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
348
+ * pct-encoded = "%" HEXDIG HEXDIG
349
+ * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
350
+ * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
351
+ * / "*" / "+" / "," / ";" / "="
352
+ */
353
+ function encodeUriSegment(val) {
354
+ return encodeUriQuery(val, true).
355
+ replace(/%26/gi, '&').
356
+ replace(/%3D/gi, '=').
357
+ replace(/%2B/gi, '+');
358
+ }
359
+
360
+
361
+ /**
362
+ * This method is intended for encoding *key* or *value* parts of query component. We need a
363
+ * custom method because encodeURIComponent is too aggressive and encodes stuff that doesn't
364
+ * have to be encoded per http://tools.ietf.org/html/rfc3986:
365
+ * query = *( pchar / "/" / "?" )
366
+ * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
367
+ * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
368
+ * pct-encoded = "%" HEXDIG HEXDIG
369
+ * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
370
+ * / "*" / "+" / "," / ";" / "="
371
+ */
372
+ function encodeUriQuery(val, pctEncodeSpaces) {
373
+ return encodeURIComponent(val).
374
+ replace(/%40/gi, '@').
375
+ replace(/%3A/gi, ':').
376
+ replace(/%24/g, '$').
377
+ replace(/%2C/gi, ',').
378
+ replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
379
+ }
380
+
381
+ function Route(template, defaults) {
382
+ this.template = template;
383
+ this.defaults = defaults || {};
384
+ this.urlParams = {};
385
+ }
386
+
387
+ Route.prototype = {
388
+ setUrlParams: function(config, params, actionUrl) {
389
+ var self = this,
390
+ url = actionUrl || self.template,
391
+ val,
392
+ encodedVal;
393
+
394
+ var urlParams = self.urlParams = {};
395
+ forEach(url.split(/\W/), function(param){
396
+ if (param === 'hasOwnProperty') {
397
+ throw $resourceMinErr('badname', "hasOwnProperty is not a valid parameter name.");
398
+ }
399
+ if (!(new RegExp("^\\d+$").test(param)) && param &&
400
+ (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) {
401
+ urlParams[param] = true;
402
+ }
403
+ });
404
+ url = url.replace(/\\:/g, ':');
405
+
406
+ params = params || {};
407
+ forEach(self.urlParams, function(_, urlParam){
408
+ val = params.hasOwnProperty(urlParam) ? params[urlParam] : self.defaults[urlParam];
409
+ if (angular.isDefined(val) && val !== null) {
410
+ encodedVal = encodeUriSegment(val);
411
+ url = url.replace(new RegExp(":" + urlParam + "(\\W|$)", "g"), function(match, p1) {
412
+ return encodedVal + p1;
413
+ });
414
+ } else {
415
+ url = url.replace(new RegExp("(\/?):" + urlParam + "(\\W|$)", "g"), function(match,
416
+ leadingSlashes, tail) {
417
+ if (tail.charAt(0) == '/') {
418
+ return tail;
419
+ } else {
420
+ return leadingSlashes + tail;
421
+ }
422
+ });
423
+ }
424
+ });
425
+
426
+ // strip trailing slashes and set the url
427
+ url = url.replace(/\/+$/, '') || '/';
428
+ // then replace collapse `/.` if found in the last URL path segment before the query
429
+ // E.g. `http://url.com/id./format?q=x` becomes `http://url.com/id.format?q=x`
430
+ url = url.replace(/\/\.(?=\w+($|\?))/, '.');
431
+ // replace escaped `/\.` with `/.`
432
+ config.url = url.replace(/\/\\\./, '/.');
433
+
434
+
435
+ // set params - delegate param encoding to $http
436
+ forEach(params, function(value, key){
437
+ if (!self.urlParams[key]) {
438
+ config.params = config.params || {};
439
+ config.params[key] = value;
440
+ }
441
+ });
442
+ }
443
+ };
444
+
445
+
446
+ function resourceFactory(url, paramDefaults, actions) {
447
+ var route = new Route(url);
448
+
449
+ actions = extend({}, DEFAULT_ACTIONS, actions);
450
+
451
+ function extractParams(data, actionParams){
452
+ var ids = {};
453
+ actionParams = extend({}, paramDefaults, actionParams);
454
+ forEach(actionParams, function(value, key){
455
+ if (isFunction(value)) { value = value(); }
456
+ ids[key] = value && value.charAt && value.charAt(0) == '@' ?
457
+ lookupDottedPath(data, value.substr(1)) : value;
458
+ });
459
+ return ids;
460
+ }
461
+
462
+ function defaultResponseInterceptor(response) {
463
+ return response.resource;
464
+ }
465
+
466
+ function Resource(value){
467
+ shallowClearAndCopy(value || {}, this);
468
+ }
469
+
470
+ forEach(actions, function(action, name) {
471
+ var hasBody = /^(POST|PUT|PATCH)$/i.test(action.method);
472
+
473
+ Resource[name] = function(a1, a2, a3, a4) {
474
+ var params = {}, data, success, error;
475
+
476
+ /* jshint -W086 */ /* (purposefully fall through case statements) */
477
+ switch(arguments.length) {
478
+ case 4:
479
+ error = a4;
480
+ success = a3;
481
+ //fallthrough
482
+ case 3:
483
+ case 2:
484
+ if (isFunction(a2)) {
485
+ if (isFunction(a1)) {
486
+ success = a1;
487
+ error = a2;
488
+ break;
489
+ }
490
+
491
+ success = a2;
492
+ error = a3;
493
+ //fallthrough
494
+ } else {
495
+ params = a1;
496
+ data = a2;
497
+ success = a3;
498
+ break;
499
+ }
500
+ case 1:
501
+ if (isFunction(a1)) success = a1;
502
+ else if (hasBody) data = a1;
503
+ else params = a1;
504
+ break;
505
+ case 0: break;
506
+ default:
507
+ throw $resourceMinErr('badargs',
508
+ "Expected up to 4 arguments [params, data, success, error], got {0} arguments",
509
+ arguments.length);
510
+ }
511
+ /* jshint +W086 */ /* (purposefully fall through case statements) */
512
+
513
+ var isInstanceCall = this instanceof Resource;
514
+ var value = isInstanceCall ? data : (action.isArray ? [] : new Resource(data));
515
+ var httpConfig = {};
516
+ var responseInterceptor = action.interceptor && action.interceptor.response ||
517
+ defaultResponseInterceptor;
518
+ var responseErrorInterceptor = action.interceptor && action.interceptor.responseError ||
519
+ undefined;
520
+
521
+ forEach(action, function(value, key) {
522
+ if (key != 'params' && key != 'isArray' && key != 'interceptor') {
523
+ httpConfig[key] = copy(value);
524
+ }
525
+ });
526
+
527
+ if (hasBody) httpConfig.data = data;
528
+ route.setUrlParams(httpConfig,
529
+ extend({}, extractParams(data, action.params || {}), params),
530
+ action.url);
531
+
532
+ var promise = $http(httpConfig).then(function (response) {
533
+ var data = response.data,
534
+ promise = value.$promise;
535
+
536
+ if (data) {
537
+ // Need to convert action.isArray to boolean in case it is undefined
538
+ // jshint -W018
539
+ if (angular.isArray(data) !== (!!action.isArray)) {
540
+ throw $resourceMinErr('badcfg',
541
+ 'Error in resource configuration. Expected ' +
542
+ 'response to contain an {0} but got an {1}',
543
+ action.isArray ? 'array' : 'object',
544
+ angular.isArray(data) ? 'array' : 'object');
545
+ }
546
+ // jshint +W018
547
+ if (action.isArray) {
548
+ value.length = 0;
549
+ forEach(data, function (item) {
550
+ if (typeof item === "object") {
551
+ value.push(new Resource(item));
552
+ } else {
553
+ // Valid JSON values may be string literals, and these should not be converted
554
+ // into objects. These items will not have access to the Resource prototype
555
+ // methods, but unfortunately there
556
+ value.push(item);
557
+ }
558
+ });
559
+ } else {
560
+ shallowClearAndCopy(data, value);
561
+ value.$promise = promise;
562
+ }
563
+ }
564
+
565
+ value.$resolved = true;
566
+
567
+ response.resource = value;
568
+
569
+ return response;
570
+ }, function(response) {
571
+ value.$resolved = true;
572
+
573
+ (error||noop)(response);
574
+
575
+ return $q.reject(response);
576
+ });
577
+
578
+ promise = promise.then(
579
+ function(response) {
580
+ var value = responseInterceptor(response);
581
+ (success||noop)(value, response.headers);
582
+ return value;
583
+ },
584
+ responseErrorInterceptor);
585
+
586
+ if (!isInstanceCall) {
587
+ // we are creating instance / collection
588
+ // - set the initial promise
589
+ // - return the instance / collection
590
+ value.$promise = promise;
591
+ value.$resolved = false;
592
+
593
+ return value;
594
+ }
595
+
596
+ // instance call
597
+ return promise;
598
+ };
599
+
600
+
601
+ Resource.prototype['$' + name] = function(params, success, error) {
602
+ if (isFunction(params)) {
603
+ error = success; success = params; params = {};
604
+ }
605
+ var result = Resource[name].call(this, params, this, success, error);
606
+ return result.$promise || result;
607
+ };
608
+ });
609
+
610
+ Resource.bind = function(additionalParamDefaults){
611
+ return resourceFactory(url, extend({}, paramDefaults, additionalParamDefaults), actions);
612
+ };
613
+
614
+ return Resource;
615
+ }
616
+
617
+ return resourceFactory;
618
+ }]);
619
+
620
+
621
+ })(window, window.angular);