UNPKG

synergia-jira-connector

Version:

Easy to use NodeJS wrapper for the Jira REST API.

204 lines (181 loc) 7.83 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: api/avatar.js</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: api/avatar.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>"use strict"; var fs = require('fs'); var path = require('path'); var errorStrings = require('./../lib/error'); module.exports = AvatarClient; /** * Used to access Jira REST endpoints in '/rest/api/2/avatar' * @param {JiraClient} jiraClient * @constructor AvatarClient */ function AvatarClient(jiraClient) { this.jiraClient = jiraClient; /** * Returns all system avatars of the given type. * * @method getAvatars * @memberOf AvatarClient# * @param opts The options to be used in the API request. * @param opts.avatarType The avatar type. May be 'project' or 'user'. * @param callback Called when the avatars are retrieved. */ this.getAvatars = function (opts, callback) { if (!opts.avatarType) { throw new Error(errorStrings.NO_AVATAR_TYPE_ERROR); } var options = { method: 'GET', json: true, followAllRedirects: true, uri: this.jiraClient.buildURL('/avatar/' + opts.avatarType + '/system') }; this.jiraClient.makeRequest(options, callback); }; /** * Creates a temporary avatar. This function doesn't seem to work the way the Jira API describes, so for now * just don't use it. * * @method createTemporaryAvatar * @memberOf AvatarClient# * @param opts The options to be used in the API request. * @param opts.avatarType The avatar type. May be 'project' or 'user'. * @param opts.avatarFilename The name of the file being uploaded * @param opts.avatarFileSize The size of the file * @param opts.avatarFilePath The path to the avatar file. * @param callback Called when the avatar is created. */ this.createTemporaryAvatar = function (opts, callback) { if (!opts.avatarType) { throw new Error(errorStrings.NO_AVATAR_TYPE_ERROR); } var size = fs.statSync(opts.avatarFilePath).size; var name = path.basename(opts.avatarFilePath); var options = { method: 'POST', json: true, followAllRedirects: true, uri: this.jiraClient.buildURL('/avatar/' + opts.avatarType + '/temporary'), headers: { "X-Atlassian-Token": "no-check" }, qs: { filename: name, size: size }, formData: { file: fs.createReadStream(opts.avatarFilePath) } }; delete options.body; this.jiraClient.makeRequest(options, callback); }; /** * Updates the cropping instructions of the temporary avatar. This function doesn't seem to work the way the Jira * API describes, so for now just don't use it. * * @method cropTemporaryAvatar * @memberOf AvatarClient# * @param {Object} opts The options to be used in the API request. * @param {string} opts.avatarType The avatar type. May be 'project' or 'user'. * @param {Object} opts.crop See {@link https://docs.atlassian.com/jira/REST/latest/#d2e3316} * @param callback Called when the avatar has been cropped. */ this.cropTemporaryAvatar = function (opts, callback) { if (!opts.avatarType) { throw new Error(errorStrings.NO_AVATAR_TYPE_ERROR); } var options = { method: 'POST', json: true, followAllRedirects: true, uri: this.jiraClient.buildURL('/avatar/' + opts.avatarType + '/temporaryCrop'), headers: { "X-Atlassian-Token": "no-check" }, body: opts.crop }; this.jiraClient.makeRequest(options, callback); }; }</code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2> <h3>Classes</h3> <ul> <li><a href="ApplicationPropertiesClient.html">ApplicationPropertiesClient</a></li> <li><a href="AttachmentClient.html">AttachmentClient</a></li> <li><a href="AuditingClient.html">AuditingClient</a></li> <li><a href="AvatarClient.html">AvatarClient</a></li> <li><a href="CommentClient.html">CommentClient</a></li> <li><a href="ComponentClient.html">ComponentClient</a></li> <li><a href="CustomFieldOptionClient.html">CustomFieldOptionClient</a></li> <li><a href="DashboardClient.html">DashboardClient</a></li> <li><a href="FieldClient.html">FieldClient</a></li> <li><a href="FilterClient.html">FilterClient</a></li> <li><a href="GroupClient.html">GroupClient</a></li> <li><a href="GroupsClient.html">GroupsClient</a></li> <li><a href="GroupUserPickerClient.html">GroupUserPickerClient</a></li> <li><a href="IssueClient.html">IssueClient</a></li> <li><a href="IssueLinkClient.html">IssueLinkClient</a></li> <li><a href="IssueLinkTypeClient.html">IssueLinkTypeClient</a></li> <li><a href="IssueTypeClient.html">IssueTypeClient</a></li> <li><a href="JiraClient.html">JiraClient</a></li> <li><a href="JqlClient.html">JqlClient</a></li> <li><a href="LicenseRoleClient.html">LicenseRoleClient</a></li> <li><a href="LicenseValidatorClient.html">LicenseValidatorClient</a></li> <li><a href="MyPermissionsClient.html">MyPermissionsClient</a></li> <li><a href="MyPreferencesClient.html">MyPreferencesClient</a></li> <li><a href="MyselfClient.html">MyselfClient</a></li> <li><a href="PasswordClient.html">PasswordClient</a></li> <li><a href="PriorityClient.html">PriorityClient</a></li> <li><a href="ProjectCategoryClient.html">ProjectCategoryClient</a></li> <li><a href="ProjectClient.html">ProjectClient</a></li> <li><a href="ProjectValidateClient.html">ProjectValidateClient</a></li> <li><a href="ReindexClient.html">ReindexClient</a></li> <li><a href="ResolutionClient.html">ResolutionClient</a></li> <li><a href="ScreensClient.html">ScreensClient</a></li> <li><a href="SearchClient.html">SearchClient</a></li> <li><a href="SecurityLevelClient.html">SecurityLevelClient</a></li> <li><a href="ServerInfoClient.html">ServerInfoClient</a></li> <li><a href="SettingsClient.html">SettingsClient</a></li> <li><a href="StatusCategoryClient.html">StatusCategoryClient</a></li> <li><a href="StatusClient.html">StatusClient</a></li> <li><a href="UserClient.html">UserClient</a></li> <li><a href="VersionClient.html">VersionClient</a></li> <li><a href="WorkflowClient.html">WorkflowClient</a></li> <li><a href="WorkflowSchemeClient.html">WorkflowSchemeClient</a></li> </ul> <h3>Namespaces</h3> <ul> <li><a href="OauthUtil.html">OauthUtil</a></li> </ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha13</a> on Fri Oct 16 2015 13:33:15 GMT-0500 (CDT) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"></script> </body> </html>