Looking up Client data

Example on how to use Breinify's temporal-data endpoint to get current information about the client. See https://github.com/Breinify/brein-api-library-javascript-browser

by Breinify

HTML

<script src="https://cdn.rawgit.com/Breinify/brein-api-library-javascript-browser/90bb431e/dist/breinify-api.min.js"></script>
<div id="result"></div>

CSS

#result, #result kbd {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  text-align: justify;
}

#result kbd {
  color: #42A2DE;
}

JavaScript

// set the configuration and fire the query to get the required information
Breinify.setConfig({ 'apiKey': '938D-3120-64DD-413F-BB55-6573-90CE-473A' });
Breinify.temporalData(function(data) {
	document.getElementById('result').innerHTML = createText(data);
});

/*
 * Just a simple helper method to write the wonderful text based on the provided data.
 */
function createText(data) {
	var text = '';

  text += 'The endpoint provides several temporal information. <br/><br/>';
  text += 'Today is <kbd>' + data.time.localDayName + '</kbd>, which is a ';
  text += '<kbd>' + (data.time.localDayName.startsWith('s') ? 'week-end' : 'week-day') + '</kbd>. ';
  if (data.holidays.length == 0) {
       text += 'There aren\'t any holidays/special day(s) today, ';
       text += 'but if there would be they would be shown. ';
  } else {
       var rnd = Math.floor((Math.random() * data.holidays.length));
       text += 'Today is/are ' + data.holidays.length + ' holiday(s)/special days ';
       text += '(e.g., <kbd>' + data.holidays[rnd].holiday + '</kbd>). ';
  }
  text += 'The local timezone is <kbd>' + data.time.timezone + '</kbd>. ';
  text += 'There are <kbd>' + data.events.length + '</kbd> different events in ';
  text += '<kbd>' + data.location.city + '</kbd> today ';
  if (data.events.length == 0) {
       text += '(which would be available, if there are any). ';
  } else {
       var rnd = Math.floor((Math.random() * data.events.length));
       text += '(e.g., <kbd>' + data.events[rnd].displayName + '</kbd>). ';
  }
  if (typeof data.weather == 'object') {
  	text += 'The data contains up to 12 weather changes ';
  	text += '(currently: <kbd>' + data.weather.description + '</kbd> ';
  	text += 'with a temperature of ';
    text += '<kbd>' + Math.round(data.weather.temperatureC) + '&nbsp;°C</kbd>, ';
    text += 'and <kbd>' + Math.round(data.weather.temperatureF) + '&nbsp;°F</kbd>).';
  }
  return text;
}

/*
 * The following is not part of the example and just used to...