User:Harthur/BugzillaRPC
- Bugzilla XML-RPC Javascript API
download: bugzillaRPC.js
About
This is a Javascript API that wraps several of the methods exposed via the Bugzilla XML-RPC interface. In particular, it wraps the functionality of the Bug.create, Bug.get_bugs, Bug.legal_values, User.login, User.logout, and User.offer_account_by_email methods from the API. In addition, it adds a method for advanced searching by term.
The API is a js object, bugzillaRPC, that is contained in a single js file. Unfortunately, it's only for use by code with chrome privileges right now as it uses cross-site XHR which is not currently allowed by the bugzilla.mozilla.org server.
To call a method of the API, simply call bugzillaRPC.methodName. If a method returned a struct in the XML-RPC interface, then it will return a js hash in this library. Similarly for arrays and values. All methods require a callback and an error callback. If there is an error (from the connection or from an illegal argument, etc.) then the error callback will be called with the error message (the faultString from the XML-RPC call if it's a logical error). Otherwise, the callback will be called with the return value.
API
getBug
Retrieves an object with a bug's information given an id
parameters:
- id - the id of the bug
- callback - the callback function to populate with the returned bug info
- errback - callback that is called upon error (connection or logical)
success parameter:
- bug - object defined by Bugzilla XML-RPC's getBugs return value. with properties id, summary, creation_time, last_change_time, and the internals object which has various other properties.
example:
bugzillaRPC.getBug(48875,
function(bug) {alert(bug.summary);},
function(errMsg) {alert(errMsg)});
getBugs
Retrieves an array of bug objects
parameters:
- ids - an array of bug ids
- callback
- errback
success parameter:
- bugs - An array of objects defined by Bugzilla XML-RPC's getBugs return value. with properties id, summary, creation_time, last_change_time, and the internals object which has various other properties.
example:
bugzillaRPC.getBugs([8117, 2344],
function(bugs) {alert(bugs[0].summary);},
function(errMsg) {alert(errMsg)});
advancedSearch
Retrieves an array of bug objects based on advanced search parameters.
parameters:
- params - a hash of parameters for the buglist query - same parameters as are passed as GET parameters to buglist.cgi.
- callback
- errback
success parameter:
- bugs - An array of objects defined by Bugzilla XML-RPC's getBugs return value. with properties id, summary, creation_time, last_change_time, and the internals object which has various other properties.
example:
bugzillaRPC.advancedSearch({ short_desc_type: 'allwordssubstr',
short_desc: 'window+should+close',
component: 'general'},
function(bugs) {alert(bugs[0].summary);
function(errMsg) {alert(errMsg)});
login
Authenticates a Bugzilla user for future API calls.
parameters:
- login - the user's login name
- password - the user's password
- callback
- errback
success parameter:
- id - the id of the logged in user
example:
bugzillaRPC.getBug(test@company.com, mypassword
function(id) {alert('user ' + id + 'logged in');
function(errMsg) {alert(errMsg)});
logout
Logs out the currently logged in user.
parameters:
- callback
- errback
success parameter: -
example:
bugzillaRPC.getBug( function() {alert('logged out');
function(errMsg) {alert(errMsg)});