Loads the resource and stores the properties.
Loads the resource and stores the properties.
Name | Type | Description |
---|---|---|
properties | Object | The properties for this resource. |
_load: function(properties) {
this._properties = properties || {};
this._state = properties || {};
},
Refreshes the resource by fetching the object from the server and loading it.
Name | Type | Description |
---|---|---|
callback | Function | A function to call when the object is retrieved: |
fetch: function(callback) {
throw new Error("MUST BE OVERRIDDEN");
},
Constructor for splunkjs.Service.Resource
.
Name | Type | Description |
---|---|---|
service | splunkjs.Service | A |
path | String | A relative endpoint path (for example, "search/jobs"). |
namespace | Object | Namespace information: |
A new splunkjs.Service.Resource
instance.
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);
},
Retrieves the REST endpoint path for this resource (with no namespace).
path: function() {
throw new Error("MUST BE OVERRIDDEN");
},
Retrieves the current properties for this resource.
The properties.
properties: function() {
return this._properties;
},
Retrieves the current full state (properties and metadata) of this resource.
The current full state of this resource.
state: function() {
return this._state;
}
});
Performs a relative DELETE request on an endpoint's path, combined with the parameters and a relative path if specified.
Name | Type | Description |
---|---|---|
relpath | String | A relative path to append to the endpoint path. |
params | Object | A dictionary of entity-specific parameters to add to the query string. |
callback | Function | A function to call 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
);
}
});
Performs a relative GET request on an endpoint's path, combined with the parameters and a relative path if specified.
Name | Type | Description |
---|---|---|
relpath | String | A relative path to append to the endpoint path. |
params | Object | A dictionary of entity-specific parameters to add to the query string. |
callback | Function | A function to call 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, isAsync) {
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,
isAsync
);
},
Performs a relative POST request on an endpoint's path, combined with the parameters and a relative path if specified.
Name | Type | Description |
---|---|---|
relpath | String | A relative path to append to the endpoint path. |
params | Object | A dictionary of entity-specific parameters to add to the body. |
callback | Function | A function to call 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
);
},