API Usage

The WeatherBlox JavaScript integration may be the simplest, for some use cases you need additional control, which the WeatherBlox API (Server Side) provides. You may need to request one or more WeatherBlox views and insert them into your HTML before the page is rendered by the browser, or you may not want to rely on JavaScript for rendering large blox of content on your page for indexing, searching or SEO purposes. In these cases, you can use our server-side method where you request weather blox from our servers as HTML and then insert them into your pages before serving those pages to the browser in the response.

The benefit of using the server-side (API) method is that you can control caching of rendered WeatherBlox content on your backend, reducing the total number of accesses against your API account. However, the server-side method for using WeatherBlox is not as quick and easy as the client-side method as it requires additional development.

There are two different approaches to using the server-side method. You can use our PHP package for quicker integration without worrying about performing the necessary requests to our servers or configuring the view. Or, you can request the WeatherBlox HTML directly from our servers.

Using the PHP Package

Using our PHP package for integrating WeatherBlox into your own pages offers the quickest and easiest server-side solution. Not only does it eliminate the need for you to perform the requests to our servers directly, but it also handles a lot of the necessary view configuration and rendering based on your global configuration before returning the final HTML to your script, such as replacing and formatting links.

Use the following steps to get started using the PHP package:

Step 1: Include the package in your application either as a dependency via Composer or by downloading the files directly from our Github repo.

Step 2: Import the library's View.php file into your script where you need to request WeatherBlox content:

require_once('./lib/Aeris/WxBlox/View.php');

Step 3: Include the client-side CSS and script files for WeatherBlox from our CDN: 

<link href="https://cdn.aerisapi.com/wxblox/aeris-wxblox.css" rel="stylesheet" />
<script src="https://cdn.aerisapi.com/wxblox/aeris-wxblox.min.js"></script>
<script src="https://cdn.aerisapi.com/wxblox/aeris-wxblox-ui.min.js"></script>

Step 4: Configure the library in your script with your API access keys and any other configuration options you wish to override, such as link formats:

Aeris\WxBlox\Config::getInstance()->setAccess(‘{{API_KEY}}’, '{{SECRET_KEY}}');

Step 5: Instantiate an instance of View, passing the desired view or layout type and any additional API request parameters or configuration options:

$opts = array('limit' => 5);
$view = new Aeris\WxBlox\View('forecasts/detailed', '98109', $opts);

Step 6: Request and return the view's HTML via the View's html() method:

$content = $view->html();

Step 7: Output the returned HTML where you want the view's content to appear within your own HTML:

<div class="local-forecast"><?php echo $content; ?></div>

Directly Requesting HTML

An alternative to using our PHP package for requesting WeatherBlox content is to request them directly from our servers. While this reduces the dependency on our scripts and PHP, the downside is that view options and links will not be automatically applied and formatted from the server's response. You will need to perform any output customization, especially link formatting, on your own as needed before outputting the final WeatherBlox content to your page.

To use the direct-request method via a URL:

Step 1: Include the client-side CSS and script files for WeatherBlox from our CDN: 

<link href="https://cdn.aerisapi.com/wxblox/aeris-wxblox.css" rel="stylesheet" />
<script src="https://cdn.aerisapi.com/wxblox/aeris-wxblox.min.js"></script>
<script src="https://cdn.aerisapi.com/wxblox/aeris-wxblox-ui.min.js"></script>

Step 2: Determine the type of WeatherBlox view or layout you want to return and its associated server-side key. Refer to the view and layout reference for the server-side keys to use for each type of view.

Step 3: Setup the full URL for the desired content using your API access keys and additional API request parameters or view configuration options. Note that some views or layouts have additional URL requirements, so refer to the view and layout reference for more information per WeatherBlox type:

$url = 'https://wxblox.aerisapi.com/{{API_KEY}}/{{SECRET_KEY}}/views/{{type}}';

Step 4: Make the HTTP request for the resulting URL using your method of choice:

$content = file_get_contents($url);

Step 5: Perform any customization or formatting to the returned HTML before outputting.

Step 6: Output the final view contents where you want the view's content to appear within your own HTML:

<div class="local-forecast"><?php echo $content; ?></div>

Customization

WeatherBlox views are customizable to get the content and look you need. Refer to the customization documentation for the various methods available.