Constructor for splunkjs.Service.Resource
Constructor for splunkjs.Service.Resource
Name | Type | Description |
---|---|---|
service | splunkjs.Service | A service instance |
path | String | A relative endpoint path (e.g. 'search/jobs') |
namespace | Object | Namespace information for this resource (owner, app, sharing) |
init: function(service, path, namespace) {
var fullpath = service.fullpath(path, namespace);
this._super(service, fullpath);
this.namespace = namespace;
this._properties = {};
this._state = {};
// We perform the bindings so that every function works
// properly when it is passed as a callback.
this._load = utils.bind(this, this._load);
this.fetch = utils.bind(this, this.fetch);
this.properties = utils.bind(this, this.properties);
this.state = utils.bind(this, this.state);
this.path = utils.bind(this, this.path);
},
Retrieve the state for this resource
This will retrieve the current full state for this resource.
state: function() {
return this._state;
}
});
Retrieve the properties for this resource
This will retrieve the current properties for this resource.
properties: function() {
return this._properties;
},
Refresh the resource
This will fetch the object from the server and load it up.
Name | Type | Description |
---|---|---|
callback | Function | A callback when the object is retrieved: |
fetch: function(callback) {
throw new Error("MUST BE OVERRIDDEN");
},
Load the resource, also storing the properties.
Name | Type | Description |
---|---|---|
properties | Object | The properties for this resource |
_load: function(properties) {
this._properties = properties || {};
this._state = properties || {};
},
REST path for this resource (with no namespace)
path: function() {
throw new Error("MUST BE OVERRIDDEN");
},
Perform a relative DELETE request
Perform a relative DELETE request on this endpoint's path, combined with the parameters and a relative path if specified.
Name | Type | Description |
---|---|---|
relpath | String | A relative path to append at the end of the path |
params | Object | A dictionary of parameters to add to the query string |
callback | Function | A callback to be invoked when the request is complete: |
// Will make a request to {service.prefix}/search/jobs/123456
var endpoint = new splunkjs.Service.Endpoint(service, "search/jobs/12345");
endpoint.delete("", {}, function() { console.log("DELETED"))});
del: function(relpath, params, callback) {
var url = this.qualifiedPath;
// If we have a relative path, we will append it with a preceding
// slash.
if (relpath) {
url = url + "/" + relpath;
}
return this.service.del(
url,
params,
callback
);
}
});
Perform a relative POST request
Perform a relative POST request on this endpoint's path, combined with the parameters and a relative path if specified.
Name | Type | Description |
---|---|---|
relpath | String | A relative path to append at the end of the path |
params | Object | A dictionary of parameters to add to the body |
callback | Function | A callback to be invoked when the request is complete: |
// Will make a request to {service.prefix}/search/jobs/123456/control
var endpoint = new splunkjs.Service.Endpoint(service, "search/jobs/12345");
endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});
post: function(relpath, params, callback) {
var url = this.qualifiedPath;
// If we have a relative path, we will append it with a preceding
// slash.
if (relpath) {
url = url + "/" + relpath;
}
return this.service.post(
url,
params,
callback
);
},
Perform a relative GET request
Perform a relative GET request on this endpoint's path, combined with the parameters and a relative path if specified.
Name | Type | Description |
---|---|---|
relpath | String | A relative path to append at the end of the path |
params | Object | A dictionary of parameters to add to the query string |
callback | Function | A callback to be invoked when the request is complete: |
// Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
var endpoint = new splunkjs.Service.Endpoint(service, "search/jobs/12345");
endpoint.get("results", {offset: 1}, function() { console.log("DONE"))});
get: function(relpath, params, callback) {
var url = this.qualifiedPath;
// If we have a relative path, we will append it with a preceding
// slash.
if (relpath) {
url = url + "/" + relpath;
}
return this.service.get(
url,
params,
callback
);
},