Last active
January 18, 2016 13:03
-
-
Save robertmassaioli/0830eab1a556ff05703f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Utils = {}; | |
Utils.getUrlParam = function (param, escape) { | |
try { | |
var regex = new RegExp(param + '=([^&]+)'), | |
data = regex.exec(window.location.search)[1]; | |
// decode URI with plus sign fix. | |
return (escape) ? window.decodeURIComponent(data.replace(/\+/g, '%20')) : data; | |
} catch (e) { | |
return undefined; | |
} | |
}; | |
// This is required to get the base url of JIRA | |
Utils.getBaseUrl = function () { | |
var cp = this.getUrlParam('cp', true); | |
return this.getUrlParam('xdm_e', true) + ( cp ? cp : '') + '/atlassian-connect'; | |
}; | |
$(document).ready(function () { | |
var allJS = Utils.getBaseUrl() + '/all.js'; | |
$.getScript(allJS, function () { | |
//Call a REST endpoint using the Atlassian Connect Javascript library | |
AP.request({ | |
url: "/rest/api/latest/myself", | |
headers: {"accept": "application/json"}, | |
success: function (responseText) { | |
console.log(responseText); | |
var userJson = $.parseJSON(responseText); | |
$("#userName").text(userJson.displayName); | |
}, | |
error: function (responseText) { | |
$("#missing-read-scope").removeClass("hidden"); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment