Skip to content

Commit ffae052

Browse files
committed
Closes #111.
1 parent 717231d commit ffae052

File tree

6 files changed

+78
-7
lines changed

6 files changed

+78
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
##### 0.10.5 - 11 August 2014
22

33
###### Backwards compatible API changes
4+
- #111 - DSHttpAdapter default $http config
45
- #114 - Include resourceName in error messages
56

67
###### Backwards compatible bug fixes

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ __master:__ [0.10.5](http://angular-data-next.pseudobry.com/)
77

88
Angular-data is approaching 1.0.0 Beta. The API is stabilizing and angular-data is well tested.
99

10-
Angular-data is being used in production, though it's not 1.0.0. If you want to use Angular-data, keep an eye on the changelog. 1.0.0 will introduce strict semver (minor number is bumped for breaking changes right now).
10+
Angular-data is being used in production, though it's not 1.0.0. If you want to use Angular-data, keep an eye on the changelog. 1.0.0 will introduce strict semver (until then, minor number is bumped for breaking changes).
1111

1212
Roadmap:
1313
- Even more adapters

dist/angular-data.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,31 @@ function DSHttpAdapterProvider() {
14481448
*/
14491449
queryTransform: function (resourceName, params) {
14501450
return params;
1451-
}
1451+
},
1452+
1453+
/**
1454+
* @doc property
1455+
* @id DSHttpAdapterProvider.properties:defaults.$httpConfig
1456+
* @name defaults.$httpConfig
1457+
* @description
1458+
* Default `$http` configuration options used whenever `DSHttpAdapter` uses `$http`.
1459+
*
1460+
* ## Example:
1461+
* ```js
1462+
* angular.module('myApp', function (DSHttpAdapterProvider) {
1463+
* angular.extend(DSHttpAdapterProvider.defaults.httpConfig, {
1464+
* interceptor: [...],
1465+
* headers: {
1466+
* common: {
1467+
* Authorization: 'Basic YmVlcDpib29w'
1468+
* }
1469+
* },
1470+
* timeout: 20000
1471+
* });
1472+
* });
1473+
* ```
1474+
*/
1475+
$httpConfig: {}
14521476
};
14531477

14541478
this.$get = ['$http', '$log', 'DSUtils', function ($http, $log, DSUtils) {
@@ -1726,6 +1750,7 @@ function DSHttpAdapterProvider() {
17261750
function HTTP(config) {
17271751
var start = new Date().getTime();
17281752

1753+
config = DSUtils.deepMixIn(config, defaults.$httpConfig);
17291754
return $http(config).then(function (data) {
17301755
$log.debug(data.config.method + ' request:' + data.config.url + ' Time taken: ' + (new Date().getTime() - start) + 'ms', arguments);
17311756
return data;
@@ -4094,7 +4119,7 @@ function errorPrefix(resourceName) {
40944119
*
40954120
* @returns {function} Scope $watch deregistration function.
40964121
*/
4097-
function bindOne(scope, expr, resourceName, params, cb) {
4122+
function bindAll(scope, expr, resourceName, params, cb) {
40984123
var IA = this.errors.IA;
40994124

41004125
if (!this.utils.isObject(scope)) {
@@ -4128,7 +4153,7 @@ function bindOne(scope, expr, resourceName, params, cb) {
41284153
}
41294154
}
41304155

4131-
module.exports = bindOne;
4156+
module.exports = bindAll;
41324157

41334158
},{}],51:[function(require,module,exports){
41344159
function errorPrefix(resourceName) {

dist/angular-data.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/adapters/http.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,31 @@ function DSHttpAdapterProvider() {
3030
*/
3131
queryTransform: function (resourceName, params) {
3232
return params;
33-
}
33+
},
34+
35+
/**
36+
* @doc property
37+
* @id DSHttpAdapterProvider.properties:defaults.$httpConfig
38+
* @name defaults.$httpConfig
39+
* @description
40+
* Default `$http` configuration options used whenever `DSHttpAdapter` uses `$http`.
41+
*
42+
* ## Example:
43+
* ```js
44+
* angular.module('myApp', function (DSHttpAdapterProvider) {
45+
* angular.extend(DSHttpAdapterProvider.defaults.httpConfig, {
46+
* interceptor: [...],
47+
* headers: {
48+
* common: {
49+
* Authorization: 'Basic YmVlcDpib29w'
50+
* }
51+
* },
52+
* timeout: 20000
53+
* });
54+
* });
55+
* ```
56+
*/
57+
$httpConfig: {}
3458
};
3559

3660
this.$get = ['$http', '$log', 'DSUtils', function ($http, $log, DSUtils) {
@@ -308,6 +332,7 @@ function DSHttpAdapterProvider() {
308332
function HTTP(config) {
309333
var start = new Date().getTime();
310334

335+
config = DSUtils.deepMixIn(config, defaults.$httpConfig);
311336
return $http(config).then(function (data) {
312337
$log.debug(data.config.method + ' request:' + data.config.url + ' Time taken: ' + (new Date().getTime() - start) + 'ms', arguments);
313338
return data;

test/integration/adapters/http/find.test.js

+20
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,24 @@ describe('DSHttpAdapter.find(resourceConfig, id, options)', function () {
3333

3434
assert.equal(lifecycle.queryTransform.callCount, 0, 'queryTransform should not have been called');
3535
});
36+
37+
it('should use default configs', function () {
38+
$httpBackend.expectGET('api/posts/1?test=test').respond(200, p1);
39+
40+
DSHttpAdapter.defaults.$httpConfig.params = { test: 'test' };
41+
42+
DSHttpAdapter.find({
43+
baseUrl: 'api',
44+
endpoint: 'posts'
45+
}, 1).then(function (data) {
46+
assert.deepEqual(data.data, p1, 'post should have been found');
47+
}, function (err) {
48+
console.error(err.stack);
49+
fail('should not have rejected');
50+
});
51+
52+
$httpBackend.flush();
53+
54+
delete DSHttpAdapter.defaults.$httpConfig.params;
55+
});
3656
});

0 commit comments

Comments
 (0)