endroid/openweathermap-bundle

This package is abandoned and no longer maintained. The author suggests using the endroid/openweathermap package instead.

Endroid OpenWeatherMap Bundle for Symfony

1.0.4 2016-04-01 20:46 UTC

This package is not auto-updated.

Last update: 2017-01-01 00:37:35 UTC


README

THIS BUNDLE HAS MOVED TO endroid/openweathermap
THIS REPOSITORY IS ABANDONED AND WILL BE REMOVED ON 01-07-2017

By endroid

Latest Stable Version Build Status Total Downloads Monthly Downloads License

This bundle enables you to use Endroid OpenWeatherMap as a service in your Symfony project. It also provides an API controller that takes a local API request, adds the API key (APPID) to it and returns the corresponding OpenWeatherMap API response. This enables you to expose the OpenWeatherMap API on your own domain without having to bother about passing your API key on every request and creating a new instance each time you make a request.

For more information see the endroid/OpenWeatherMap repository and the OpenWeatherMap API.

knpbundles.com

Requirements

Installation

Add in your composer.json

{
    "require": {
        "endroid/openweathermap-bundle": "dev-master"
    }
}

Install the bundle

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update endroid/openweathermap-bundle

Composer will install the bundle to your project's vendor/endroid directory.

Enable the bundle via the kernel

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...
        new Endroid\Bundle\OpenWeatherMapBundle\EndroidOpenWeatherMapBundle(),
    ];
}

Configuration

config.yml

endroid_open_weather_map:
    api_key: my_api_key
    api_url:
    units: ... // optional

Routing

If you don't want to expose the OpenWeatherMap API via your application, you can skip this section.

EndroidOpenWeatherMapBundle:
    resource:   "@EndroidOpenWeatherMapBundle/Controller/"
    type:       annotation
    prefix:     /openweathermap/api

This exposes the OpenWeatherMap API via /openweathermap/api. This means that instead of sending a request to http://api.openweathermap.org/ you can now send an unsigned request to /openweathermap/api/*. Make sure you secure this area if you don't want others to be able to post on your behalf.

Usage

After installation and configuration, the service can be directly referenced from within your controllers.

<?php

use Endroid\OpenWeatherMap\Client;

/** @var Client $client */
$client = $this->get('endroid.openweathermap.client');

// Retrieve the current weather for Breda
$weather = $client->getWeather('Breda,nl');

// Or retrieve the weather using the generic query method
$response = $client->query('weather', ['q' => 'Breda,nl']);
$weather = json_decode($response->getContent());

Versioning

Version numbers follow the MAJOR.MINOR.PATCH scheme. Backwards compatibility breaking changes will be kept to a minimum but be aware that these can occur. Lock your dependencies for production and test your code when upgrading.

License

This bundle is under the MIT license. For the full copyright and license information please view the LICENSE file that was distributed with this source code.