BaseResource
d7-services.commons
An abstract resource providing retrieve, create, update, delete and index functions. This service is used to handle the resources basic get put pust delete operations.
Generic function for drupals create request. The request will use the POST operator
Param | Type | Details |
---|---|---|
data | Object |
|
createPath | String |
|
[pubSuccess] | Function |
|
[pubError] | Function |
|
Promise | Promise of the create request |
Fire a request with the create function.
angular .module('myModule', ['d7-services.commons']) .controller('myController',function ($scope,BaseResource) { var data = {...}, path = 'path/to/resource', pubSuccess = function(success){...}, pubError = function(error){...}; BaseResource.create(data, path, pubSuccess, pubError).then(function(success){...}, function(error){...}); }
Generic function for drupals delete request. The request will use the DELETE operator.
Param | Type | Details |
---|---|---|
deletePath | String |
|
[pubSuccess] | Function |
|
[pubError] | Function |
|
Promise | Promise of the delete request |
Fire a request with the delete function.
angular .module('myModule', ['d7-services.commons']) .controller('myController',function ($scope,BaseResource) { var path = 'path/to/resource', pubSuccess = function(success){...}, pubError = function(error){...}; BaseResource.delete(path, pubSuccess, pubError).then(function(success){...}, function(error){...}); }
Generic function for drupals delete request. The request will use the GET operator. It also formats all params for drupals index function
Param | Type | Details |
---|---|---|
data | Object |
|
indexPath | String |
|
[pubSuccess] | Function |
|
[pubError] | Function |
|
Promise | Promise of the delete request |
Fire a request with the index function.
angular .module('myModule', ['d7-services.commons']) .controller('myController',function ($scope,BaseResource) { var data = {...}, path = 'path/to/resource', pubSuccess = function(success){...}, pubError = function(error){...}; BaseResource.index(data, path, pubSuccess, pubError).then(function(success){...}, function(error){...}); }
Formats the JSON depending on format and key param
Param | Type | Details |
---|---|---|
values | Object | The value to format |
key | String | The name of key to use in formatted output |
format | String | The new format of the value param |
String | formatted data |
Prepares data for request.
angular .module('myModule', ['d7-services.commons']) .controller('myController',function ($scope,BaseResource) { var data = {...}, format : 'array_of_keys': var prepData = BaseResource.prepareGetParams(data, 'keyName',format); BaseResource.retrieve(prepData, 'path/to/api/resource'); }
Prepares the options for an index request
Param | Type | Details |
---|---|---|
options | Object |
|
options.page | integer |
|
options.pagesize | integer |
|
options.fields | object |
|
options.parameters | object |
|
String | formated params as string or empty string |
Prepare an object for drupals index request. This request is uses the GET operator
angular .module('myModule', ['d7-services.commons']) .controller('myController',function ($scope,BaseResource) { var data = prepareIndexGetParams({...}); path = 'path/to/resource'; BaseResource.index(data, path); }
Formats the JSON depending on format param
Param | Type | Details |
---|---|---|
values | Object | The value to format |
format | String | The new format of the value param |
Array | formatted data |
Prepares data for request.
angular .module('myModule', ['d7-services.commons']) .controller('myController',function ($scope,BaseResource) { var data = {...}, format : 'array_of_keys': var prepData = BaseResource.preparePostData(data, format); Baseresource.create(prepData, 'path/to/api/resource') }
Generic function for http requests that emits events on success and on error
Param | Type | Details |
---|---|---|
requestConfig | Object |
|
[pubSuccess] | Function |
|
[pubError] | Function |
|
Promise | Promise of the retrieve request |
Fire a request with the request function
angular .module('myModule', ['d7-services.commons']) .controller('myController',function ($scope,BaseResource) { var requestConfig = { url : 'path/to/resource?param=test', method :'GET' }; var pubSuccess = function(success){...}; var pubError = function(error){...}; BaseResource.request().then(function(success){...}, function(error){...}); }
Generic function for drupals retrieve request. The request will use the GET operator
Param | Type | Details |
---|---|---|
retrievePath | String |
|
[pubSuccess] | Function |
|
[pubError] | Function |
|
Promise | Promise of the retrieve request |
Fire a request with the retrieve function.
angular .module('myModule', ['d7-services.commons']) .controller('myController',function ($scope,BaseResource) { var requestConfig = { url : 'path/to/resource?param=test', method :'GET' }; var pubSuccess = function(success){...}; var pubError = function(error){...}; BaseResource.retrieve().then(function(success){...}, function(error){...}); }
Generic function for drupals update request. The request will use the PUT operator.
Param | Type | Details |
---|---|---|
data | Object |
|
updatePath | String |
|
[pubSuccess] | Function |
|
[pubError] | Function |
|
Promise | Promise of the update request |
Fire a request with the update function.
angular .module('myModule', ['d7-services.commons']) .controller('myController',function ($scope,BaseResource) { var data = {...}, path = 'path/to/resource', pubSuccess = function(success){...}, pubError = function(error){...}; BaseResource.update(data, path, pubSuccess, pubError).then(function(success){...}, function(error){...}); }