This class provides a thin layer around commonly used Assets Server REST API methods. It streamlines the authentication process and underlying AJAX calls so you can focus on coding your added functionality.
Authentication functions
useAutoLogin( username, password [, clientType] )
Call this method once in your page.
Now when other methods like 'search' fail because the session is not authorized, the ElvisAPI class will attempt login with the specified username and password. If login succeeds, the original API call will be repeated automatically.
If the session is already authenticated, no auto-login will be performed.
An optional clientType can be specified to track which interface was used to perform operations logged in the asset usage history. The clientType must be prefixed with "api_", for example: "api_MySearchPortal".
useLoginPage( url )
Call this method once in your page.
When other methods like 'search' fail because the session is not authorized, the login page at the specified URL will be loaded.
If the session is already authenticated, no login page will be shown.
login( username, password, callbackHandler( <response> ) )
Use this method to explicitly handle login for a session. Useful if you need information from the loginResponse or if you want to specify additional parameters for the REST login. For most cases it is easier to use the auto-login or login-page functions described above.
logout( nextUrl )
Simple method to logout the session on the Assets Server. Provide the URL to navigate to after logging out.
Searching
search( { params }, callbackHandler( <response> ) )
A thin wrapper to call the Assets Server search service.
All parameters are passed in one params object. The property names for the object are identical to the parameter names of the Assets Server search service.
The callback handler is executed when results are returned and will receive an already-parsed object with the results as returned by the search service.
elvisApi.search({
q: "assetDomain:image",
sort: "name",
metadataToReturn: "all"
},
function(data) {
alert("Found " + data.totalHits + " images");
}
);
As a convenience, the HitRenderer.render and FacetRenderer.render functions can be used directly as callback handler for the search function:
elvisApi.search({ q: "beach" }, hitRenderer.render);
Browsing
browse( { params }, callbackHandler( <response> ) )
A thin wrapper to call the Elvis browse service.
All parameters are passed in one params object. The property names for the object are identical to the parameter names of the Assets Server browse service.
The callback handler is executed when results are returned and will receive an already-parsed object with the results as returned by the browse service.
elvisApi.browse({ path: "/Demo Zone/Images" },
function(data) {
alert("Folder contains " + data.length + " subfolders");
}
);
Update metadata
update( id, { metadata } )
A thin wrapper to call the Assets Server update service.
Updates metadata of the asset with the specified id in Assets Server. The metadata must be specified as an object with properties matching Assets Server field names.
elvisApi.update("8eh5eIcz4938uGsU3CZKnq",
{
rating: 4,
status: "New"
}
);
Comment
Do you have corrections or additional information about this article? Leave a comment! Do you have a question about what is described in this article? Please contact Support.
0 comments
Please sign in to leave a comment.