...
HTML |
---|
<script type="text/javascript" src="/download/attachments/133238405/ecmwf-api-display.js?api=v2">
var urlApiKey = 'https://api.ecmwf.int/v1/key/';
var API_FILENAME = '.ecmwfapirc';
var FILE_TYPE = 'application/octet-stream'; //'application/ecmwfapirc'; //'application/json'; //'.ecmwfapirc'; //'text/plain'; causes chrome to append .txt
$(function() {
getApiInfo(function(apiInfo){
AJS.$('#apiKey').append('<h3>Your API key credentials</h3>' + apiInfo.apiKey);
AJS.$('#envVars').append(typeof apiInfo.envVars=='undefined' ? '' : '<h3>Environment variables</h3>' + apiInfo.envVars);
AJS.$('#objServer').append(typeof apiInfo.objServer=='undefined' ? '' : '<h3>Information to include in your Python script when creating the ECMWFDataServer Object</h3>' + apiInfo.objServer);
});
});
function getApiInfo(obj) {
AJS.$.ajax({
url: urlApiKey,
data: {format: 'json'},
method: 'get',
xhrFields: {
withCredentials: true
}
}).done(function(json){
obj({
'apiKey':'<p>Copy / paste the text below into a blank text file and save it to your $HOME directory as ' + API_FILENAME + '</p><pre><code>' + JSON.stringify(json, null, ' ') + '</code></pre>',
'envVars':'<pre><code>export ECMWF_API_URL="' + json.url + '"\nexport ECMWF_API_KEY="' + json.key + '"\nexport ECMWF_API_EMAIL="' + json.email + '"</code></pre>',
'objServer':'<pre><code>server = ECMWFDataServer(url="' + json.url + '",key="' + json.key + '",email="' + json.email + '")</code></pre>'
});
}).fail(function(jqXHR, textStatus){
console.error('Request failed: ' + textStatus);
obj({
'apiKey':'<p>Your API key information is not available.</p><ul><li>If you are not logged in, please log in first.</li><li>If you are logged in, please <a href="https://www.ecmwf.int/en/about/contact-us">let our Service Desk know</a> that ' + window.location.href + ' is not working as expected. Please provide us with your username and screenshots or error messages if possible so that we can investigate and fix the problem.</li></ul><p>You can also try visiting <a href="' + urlApiKey + '">' + urlApiKey + '</a> to retrieve your credentials.</p><p>We apologise for any inconvenience.</p>'
}); //TODO: could send back empty string for envVars and objServer?
});
}
</script>
<style>
pre {
background-color: #eff0f1;
padding: 1em;
}
</style>
|
...