11/**
22* @author Jason Dobry <jason.dobry@gmail.com>
33* @file js-data-http.js
4- * @version 0.3 .0 - Homepage <http://www.js-data.iojs-data-http/>
4+ * @version 0.4 .0 - Homepage <http://www.js-data.iojs-data-http/>
55* @copyright (c) 2014 Jason Dobry
66* @license MIT <https://github.com/js-data/js-data-http/blob/master/LICENSE>
77*
@@ -1310,6 +1310,8 @@ defaultsPrototype.queryTransform = function (resourceName, params) {
13101310 return params ;
13111311} ;
13121312
1313+ defaultsPrototype . basePath = '' ;
1314+
13131315defaultsPrototype . httpConfig = { } ;
13141316
13151317defaultsPrototype . log = console ? console . log : function ( ) {
@@ -1330,6 +1332,14 @@ function DSHttpAdapter(options) {
13301332
13311333var dsHttpAdapterPrototype = DSHttpAdapter . prototype ;
13321334
1335+ dsHttpAdapterPrototype . getIdPath = function ( resourceConfig , options , id ) {
1336+ return makePath ( options . basePath || this . defaults . basePath || resourceConfig . basePath , resourceConfig . getEndpoint ( id , options ) , id ) ;
1337+ } ;
1338+
1339+ dsHttpAdapterPrototype . getAllPath = function ( resourceConfig , options ) {
1340+ return makePath ( options . basePath || this . defaults . basePath || resourceConfig . basePath , resourceConfig . getEndpoint ( null , options ) ) ;
1341+ } ;
1342+
13331343dsHttpAdapterPrototype . HTTP = function ( config ) {
13341344 var _this = this ;
13351345 var start = new Date ( ) . getTime ( ) ;
@@ -1390,7 +1400,7 @@ dsHttpAdapterPrototype.find = function (resourceConfig, id, options) {
13901400 var _this = this ;
13911401 options = options || { } ;
13921402 return _this . GET (
1393- makePath ( options . baseUrl || resourceConfig . baseUrl , resourceConfig . getEndpoint ( id , options ) , id ) ,
1403+ _this . getIdPath ( resourceConfig , options , id ) ,
13941404 options
13951405 ) . then ( function ( data ) {
13961406 return ( options . deserialize ? options . deserialize : _this . defaults . deserialize ) ( resourceConfig . name , data ) ;
@@ -1406,7 +1416,7 @@ dsHttpAdapterPrototype.findAll = function (resourceConfig, params, options) {
14061416 deepMixIn ( options . params , params ) ;
14071417 }
14081418 return _this . GET (
1409- makePath ( options . baseUrl || resourceConfig . baseUrl , resourceConfig . getEndpoint ( null , options ) ) ,
1419+ _this . getAllPath ( resourceConfig , options ) ,
14101420 options
14111421 ) . then ( function ( data ) {
14121422 return ( options . deserialize ? options . deserialize : _this . defaults . deserialize ) ( resourceConfig . name , data ) ;
@@ -1417,7 +1427,7 @@ dsHttpAdapterPrototype.create = function (resourceConfig, attrs, options) {
14171427 var _this = this ;
14181428 options = options || { } ;
14191429 return _this . POST (
1420- makePath ( options . baseUrl || resourceConfig . baseUrl , resourceConfig . getEndpoint ( attrs , options ) ) ,
1430+ makePath ( options . basePath || this . defaults . basePath || resourceConfig . basePath , resourceConfig . getEndpoint ( attrs , options ) ) ,
14211431 options . serialize ? options . serialize ( resourceConfig . name , attrs ) : _this . defaults . serialize ( resourceConfig . name , attrs ) ,
14221432 options
14231433 ) . then ( function ( data ) {
@@ -1429,7 +1439,7 @@ dsHttpAdapterPrototype.update = function (resourceConfig, id, attrs, options) {
14291439 var _this = this ;
14301440 options = options || { } ;
14311441 return _this . PUT (
1432- makePath ( options . baseUrl || resourceConfig . baseUrl , resourceConfig . getEndpoint ( id , options ) , id ) ,
1442+ _this . getIdPath ( resourceConfig , options , id ) ,
14331443 options . serialize ? options . serialize ( resourceConfig . name , attrs ) : _this . defaults . serialize ( resourceConfig . name , attrs ) ,
14341444 options
14351445 ) . then ( function ( data ) {
@@ -1446,7 +1456,7 @@ dsHttpAdapterPrototype.updateAll = function (resourceConfig, attrs, params, opti
14461456 deepMixIn ( options . params , params ) ;
14471457 }
14481458 return this . PUT (
1449- makePath ( options . baseUrl || resourceConfig . baseUrl , resourceConfig . getEndpoint ( null , options ) ) ,
1459+ _this . getAllPath ( resourceConfig , options ) ,
14501460 options . serialize ? options . serialize ( resourceConfig . name , attrs ) : _this . defaults . serialize ( resourceConfig . name , attrs ) ,
14511461 options
14521462 ) . then ( function ( data ) {
@@ -1458,7 +1468,7 @@ dsHttpAdapterPrototype.destroy = function (resourceConfig, id, options) {
14581468 var _this = this ;
14591469 options = options || { } ;
14601470 return _this . DEL (
1461- makePath ( options . baseUrl || resourceConfig . baseUrl , resourceConfig . getEndpoint ( id , options ) , id ) ,
1471+ _this . getIdPath ( resourceConfig , options , id ) ,
14621472 options
14631473 ) . then ( function ( data ) {
14641474 return ( options . deserialize ? options . deserialize : _this . defaults . deserialize ) ( resourceConfig . name , data ) ;
@@ -1474,7 +1484,7 @@ dsHttpAdapterPrototype.destroyAll = function (resourceConfig, params, options) {
14741484 deepMixIn ( options . params , params ) ;
14751485 }
14761486 return this . DEL (
1477- makePath ( options . baseUrl || resourceConfig . baseUrl , resourceConfig . getEndpoint ( null , options ) ) ,
1487+ _this . getAllPath ( resourceConfig , options ) ,
14781488 options
14791489 ) . then ( function ( data ) {
14801490 return ( options . deserialize ? options . deserialize : _this . defaults . deserialize ) ( resourceConfig . name , data ) ;
0 commit comments