jeffbdn/tools-bundle

Symfony JeffBdnToolsBundle

Installs: 14

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

0.0.1 2017-07-26 14:01 UTC

This package is not auto-updated.

Last update: 2024-05-26 02:24:46 UTC


README

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require jeffbdn/tools-bundle "~1"

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new JeffBdn\ToolsBundle\JeffBdnToolsBundle(),
        );

        // ...
    }

    // ...
}

This bundle comes with several services. In order to make them available for your project, register the bundle's services.yml file in your config.yml:

# app/config/config.yml
imports:
    ...
    - { resource: "@JeffBdnToolsBundle/Resources/config/services.yml" }

Then, add and customise those parameters in your config.yml:

# app/config/config.yml
parameters:
      jeffbdn_tools.weather.apikey: 'PASTE HERE YOUR openweathermaps API KEY'
      jeffbdn_tools.weather.refresh: '3 minutes' # or 1 day or 2 days or 1 hour or 2 hours or 1 minute or 2 minutes

jeffbdn_tools.weather.apikey: In order to use the Weather Service, you will need an OpenWeatherMaps API Key. You can get one for free by creating a new account on https://home.openweathermap.org/users/sign_up .

jeffbdn_tools.weather.refresh: You can choose the refresh rate for the broadcast for all locations. The cache will be renewed on next call if the data get older than the amount of time your precised.

Step 3: Use the Tools

The current version of JeffBdnToolsBundle provides 2 services:

  • A random number provider
$randomNumber = $this->get('jeffbdn_tools.math')->random();
  • A weather broadcast provider
$weatherBroadcast = $this->get('jeffbdn_tools.weather')->broadcast('Paris,fr');

The data you may be interested to use are:

  • Temperatures in Kelvin, Celsius, Fahrenheit
$weatherBroadcast['temp_k']
$weatherBroadcast['temp_k_min']
$weatherBroadcast['temp_k_max']
$weatherBroadcast['temp_c']
$weatherBroadcast['temp_c']
$weatherBroadcast['temp_c_max']
$weatherBroadcast['temp_f']
$weatherBroadcast['temp_f_min']
$weatherBroadcast['temp_f_max']
  • Sky and Atmosphere details:
$weatherBroadcast['humidity']
$weatherBroadcast['sky_description_short']
$weatherBroadcast['sky_description_long']
$weatherBroadcast['pressure_hpa']
$weatherBroadcast['wind_speed_metersec']
$weatherBroadcast['cloud_percent']
  • Date of last update, sunrise and sunset:
$weatherBroadcast['date']
$weatherBroadcast['sunrise']
$weatherBroadcast['sunset']
  • Error Management:
// true if API call went well, else false
$weatherBroadcast['ok']
// this is the HTTP response code, default is 200
$weatherBroadcast['error_code']
// this is the API response message, default is an empty string
$weatherBroadcast['error_string']

Step 4: Testing the ToolsBundle

$ phpunit vendor/jeffbdn/tools-bundle/JeffBdn/ToolsBundle/Tests/Weather.php

If you encounter any bug, please report on http://www.github.com/jeffbdn/tools-bundle/issues